/* ============================================
   Telnyx Billing Dashboard — Styles
   ============================================ */

:root {
    --sidebar-width: 240px;
    --sidebar-bg: #1a1e2e;
    --sidebar-text: #a0aec0;
    --sidebar-active: #4fd1c5;
    --primary: #4fd1c5;
    --primary-dark: #38b2ac;
    --danger: #fc8181;
    --warning: #f6e05e;
    --success: #68d391;
    --bg: #f7fafc;
    --card-bg: #ffffff;
    --text: #2d3748;
    --text-muted: #718096;
    --border: #e2e8f0;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ============================================
   LOGIN PAGE
   ============================================ */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a1e2e 0%, #2d3748 100%);
}

.login-card {
    background: var(--card-bg);
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: 0 4px 24px rgba(0,0,0,0.15);
    width: 100%;
    max-width: 400px;
}

.login-card h1 {
    text-align: center;
    color: var(--sidebar-bg);
    margin-bottom: 4px;
    font-size: 24px;
}

.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.error-message {
    background: #fff5f5;
    color: #c53030;
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
    border: 1px solid #feb2b2;
}

/* ============================================
   FORMS
   ============================================ */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 14px;
    color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    color: var(--text);
    background: #fff;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 209, 197, 0.15);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    text-decoration: none;
}

.btn:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #1a1e2e; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-success { background: var(--success); color: #1a1e2e; }
.btn-small { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
    color: #fff;
    font-size: 18px;
}

.nav-links {
    list-style: none;
    padding: 12px 0;
    flex: 1;
}

.nav-links li a {
    display: block;
    padding: 10px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.2s, color 0.2s;
}

.nav-links li a:hover {
    background: rgba(255,255,255,0.05);
    color: #fff;
}

.nav-links li.active a {
    color: var(--sidebar-active);
    background: rgba(79, 209, 197, 0.1);
    border-right: 3px solid var(--sidebar-active);
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-name {
    font-size: 13px;
    color: #fff;
}

.btn-logout {
    font-size: 12px;
    color: var(--sidebar-text);
    text-decoration: none;
    padding: 4px 10px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: var(--radius);
    transition: color 0.2s;
}

.btn-logout:hover { color: #fff; }

/* ============================================
   CONTENT AREA
   ============================================ */
.content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.content-header {
    padding: 20px 30px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
}

.content-header h1 {
    font-size: 22px;
    font-weight: 700;
}

.content-body {
    padding: 24px 30px;
}

/* ============================================
   CARDS
   ============================================ */
.cards-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.card-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.card-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
}

.card-value.positive { color: var(--success); }
.card-value.negative { color: var(--danger); }

/* ============================================
   FILTER BAR
   ============================================ */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
    background: var(--card-bg);
    padding: 16px 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 20px;
}

.filter-bar .form-group {
    margin-bottom: 0;
}

.filter-bar label {
    font-size: 12px;
    margin-bottom: 4px;
}

.filter-bar input,
.filter-bar select {
    padding: 8px 10px;
    font-size: 13px;
}

/* ============================================
   TABLES
   ============================================ */
.table-container {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 16px;
    overflow-x: auto;
}

table.dataTable {
    width: 100% !important;
    border-collapse: collapse;
}

table.dataTable thead th {
    background: var(--bg);
    color: var(--text);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 10px 14px;
    border-bottom: 2px solid var(--border);
}

table.dataTable tbody td {
    padding: 10px 14px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

table.dataTable tbody tr:hover {
    background: rgba(79, 209, 197, 0.04);
}

/* ============================================
   CHARTS
   ============================================ */
.chart-container {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 20px;
    margin-bottom: 20px;
}

.chart-container h3 {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* ============================================
   TABS
   ============================================ */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
}

.tab {
    padding: 10px 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--primary-dark); border-bottom-color: var(--primary); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ============================================
   MODAL
   ============================================ */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-overlay.show { display: flex; }

.modal {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal h3 {
    margin-bottom: 16px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transform: translateX(100%);
    transition: opacity 0.3s, transform 0.3s;
    max-width: 360px;
}

/* ============================================
   DETAIL TABLE (modal line-item breakdown)
   ============================================ */
.detail-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}

.detail-table th {
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 8px 12px;
    border-bottom: 2px solid var(--border);
    background: var(--bg);
}

.detail-table td {
    padding: 8px 12px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

.detail-table tr.detail-total td {
    font-weight: 700;
    border-top: 2px solid var(--text);
    border-bottom: none;
    font-size: 14px;
}

.detail-section {
    margin-bottom: 16px;
}

.detail-section h4 {
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 24px;
}

.detail-grid .detail-item {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    padding: 4px 0;
}

.detail-grid .detail-label {
    color: var(--text-muted);
}

.detail-grid .detail-value {
    font-weight: 600;
}

table.dataTable tbody tr {
    cursor: pointer;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast-success { background: #c6f6d5; color: #22543d; }
.toast-error { background: #fed7d7; color: #9b2c2c; }
.toast-info { background: #bee3f8; color: #2a4365; }

/* ============================================
   STATUS BADGES
   ============================================ */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-success { background: #c6f6d5; color: #22543d; }
.badge-warning { background: #fefcbf; color: #744210; }
.badge-danger { background: #fed7d7; color: #9b2c2c; }
.badge-info { background: #bee3f8; color: #2a4365; }

/* ============================================
   PROGRESS BAR
   ============================================ */
.sync-progress-item {
    margin-bottom: 16px;
}

.sync-progress-item:last-child {
    margin-bottom: 0;
}

.sync-progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.sync-progress-label {
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sync-progress-stats {
    font-size: 13px;
    color: var(--text-muted);
}

.progress-bar-track {
    width: 100%;
    height: 24px;
    background: var(--bg);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    position: relative;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 12px;
    transition: width 0.5s ease;
    background: linear-gradient(90deg, var(--primary) 0%, var(--primary-dark) 100%);
    position: relative;
}

.progress-bar-fill.completed {
    background: linear-gradient(90deg, var(--success) 0%, #38a169 100%);
}

.progress-bar-fill.failed {
    background: linear-gradient(90deg, var(--danger) 0%, #e53e3e 100%);
}

.progress-bar-fill.polling {
    background: linear-gradient(90deg, var(--primary) 0%, var(--primary-dark) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.progress-bar-text {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #1a1e2e;
    text-shadow: 0 0 3px rgba(255,255,255,0.5);
}

.sync-progress-time {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ============================================
   SPINNER
   ============================================ */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 900px) {
    .sidebar { width: 200px; }
    .content { margin-left: 200px; }
    :root { --sidebar-width: 200px; }
}
