:root {
    --bg-body:       #FFFFFF;
    --bg-section:    #F5F3EA;
    --bg-card:       #FFFFFF;
    --bg-sidebar:    #FFFFFF;
    --bg-input:      #F5F3EA;
    --bg-hover:      rgba(28,28,26,0.05);
    --bg-dark:       #1C1C1A;
    --text-white:    #FFFFFF;
    --text-heading:  #1A1A1A;
    --text-primary:  #1A1A1A;
    --text-secondary:#5A5A57;
    --text-muted:    #8A8A86;
    --border:        #E3E0D3;
    --border-light:  #EEECE0;
    --accent:        #C99A3B;
    --accent-hover:  #b0852e;
    --accent-text:   #1C1C1A;
    --green:         #1F9254;
    --green-border:  #1F9254;
    --red:           #E8392A;
    --red-border:    #E8392A;
    --yellow:        #C99A3B;
    --yellow-border: #C99A3B;
    --primary-red:   #E8392A;
    --gold:          #C99A3B;
    --gold-hover:    #b0852e;
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-body);
    color: var(--text-secondary);
    line-height: 1.6;
}

h1, h2, h3, h4, h5 {
    font-family: 'Manrope', sans-serif;
    font-weight: 700;
    color: var(--text-heading);
    letter-spacing: -0.01em;
}

/* ── Buttons ── */
.btn-gold {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    padding: 0.65rem 1.5rem;
    border-radius: 6px;
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-gold:hover { background: var(--accent-hover); }
.btn-gold .material-icons { font-size: 1rem; }

/* ── Login ── */
#login-overlay {
    position: fixed; inset: 0;
    background: var(--bg-section);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999;
}
#login-overlay.hidden { display: none; }

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 3rem 2.5rem 2.5rem;
    width: 100%; max-width: 420px;
    box-shadow: 0 8px 40px rgba(28,28,26,0.12);
}
.login-logo {
    font-family: 'Manrope', sans-serif;
    font-weight: 800;
    font-size: 2.5rem;
    color: var(--primary-red);
    line-height: 1;
    margin-bottom: 0.2rem;
}
.login-byline {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 2.5rem;
}
.login-card h3 {
    font-family: 'Manrope', sans-serif;
    font-weight: 700;
    font-size: 1.4rem;
    color: var(--text-heading);
    margin-bottom: 1.75rem;
}
.login-field { margin-bottom: 1.25rem; }
.login-field label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    margin-bottom: 0.45rem;
}
.login-field input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border) !important;
    border-radius: 6px;
    background: var(--bg-section);
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    color: var(--text-heading);
    outline: none;
    box-sizing: border-box;
    height: auto !important;
    margin: 0 !important;
    box-shadow: none !important;
    transition: border-color 0.2s, background 0.2s;
}
.login-field input:focus {
    border-color: var(--accent) !important;
    background: var(--bg-card);
}
.login-btn {
    width: 100%;
    padding: 0.85rem;
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    border-radius: 6px;
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    font-size: 0.9rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
    margin-top: 0.5rem;
    transition: background 0.2s;
}
.login-btn:hover { background: var(--accent-hover); }
.login-error {
    background: rgba(232,57,42,0.08);
    border-left: 3px solid var(--red);
    border-radius: 4px;
    color: var(--red);
    padding: 0.6rem 0.9rem;
    font-size: 0.85rem;
    margin-bottom: 1rem;
    display: none;
}
.login-error.show { display: block; }
.login-footer {
    margin-top: 2rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

.user-pill {
    display: none;
    align-items: center;
    gap: 0.4rem;
    background: rgba(201,154,59,0.12);
    border: 1px solid rgba(201,154,59,0.35);
    border-radius: 20px;
    padding: 0.25rem 0.7rem 0.25rem 0.45rem;
    font-size: 0.75rem;
    color: var(--accent-hover);
    font-weight: 600;
    margin-top: 0.6rem;
    width: fit-content;
}
.user-pill i { font-size: 0.9rem; }

.sign-out-link {
    display: none;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.4rem;
    cursor: pointer;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}
.sign-out-link:hover { color: var(--red); }

/* ── Layout ── */
.app-container { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    background: var(--bg-sidebar);
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    border-right: 1px solid var(--border);
}
.sidebar-header {
    padding: 1.5rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-header h1 {
    font-size: 1.8rem;
    color: var(--primary-red);
    margin-bottom: 0.5rem;
}
.sidebar-header p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.main-nav { flex: 1; padding: 0.5rem 0; }
.main-nav-item {
    display: flex;
    align-items: center;
    padding: 0.7rem 1.25rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.82rem;
    transition: all 0.2s ease;
    cursor: pointer;
    border-left: 3px solid transparent;
    gap: 0.6rem;
}
.main-nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-heading);
}
.main-nav-item.active {
    background: rgba(201,154,59,0.1);
    color: var(--text-heading);
    border-left-color: var(--accent);
    font-weight: 600;
}
.main-nav-item i { font-size: 1.15rem; }

.main-content {
    margin-left: 250px;
    flex: 1;
    padding: 0;
    width: calc(100% - 250px);
    min-height: 100vh;
    background: var(--bg-section);
}

.main-tab-content { display: none; }
.main-tab-content.active { display: block; animation: fadeIn 0.35s ease; }
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Page title ── */
.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-heading);
    margin-bottom: 0.25rem;
}
.page-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* ── KPI Cards ── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.kpi-card.border-green  { border-color: var(--green-border); }
.kpi-card.border-red    { border-color: var(--red-border); }
.kpi-card.border-yellow { border-color: var(--yellow-border); }

.kpi-card-title {
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.kpi-card-value {
    color: var(--text-heading);
    font-size: 1.5rem;
    font-weight: 600;
    font-family: 'Manrope', sans-serif;
}
.kpi-card-sub {
    color: var(--text-muted);
    font-size: 0.7rem;
}

/* ── Chart Cards ── */
.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
}
.chart-card-title {
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
}
.chart-card canvas {
    max-width: 100%;
}

/* ── Data Tables ── */
.data-table-wrap {
    overflow-x: auto;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}
.data-table thead tr {
    background: var(--bg-section);
    border-bottom: 1px solid var(--border);
}
.data-table th {
    padding: 0.5rem 0.75rem;
    text-align: left;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}
.data-table th.text-right { text-align: right; }
.data-table td {
    padding: 0.5rem 0.75rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
}
.data-table td.text-right {
    text-align: right;
    font-family: 'SF Mono', 'Fira Code', monospace;
}
.data-table tbody tr {
    transition: background 0.15s;
}
.data-table tbody tr:hover {
    background: var(--bg-hover);
}
.data-table-empty {
    padding: 1.5rem;
    text-align: center;
    color: var(--text-muted);
}

.table-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.25rem;
    margin-top: 0.5rem;
}
.table-pagination-info {
    color: var(--text-muted);
    font-size: 0.75rem;
}
.table-pagination-btns {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.table-pagination-btns button {
    padding: 0.25rem 0.625rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    background: transparent;
    transition: all 0.15s;
}
.table-pagination-btns button:hover:not(:disabled) {
    color: var(--text-heading);
    background: var(--bg-hover);
}
.table-pagination-btns button.active {
    background: var(--accent);
    color: var(--accent-text);
}
.table-pagination-btns button:disabled {
    opacity: 0.4;
    cursor: default;
}

/* ── Filter Bar ── */
.filter-bar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
    margin-bottom: 1.5rem;
}
.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.filter-label {
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.filter-select,
.filter-date {
    background: var(--bg-section);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 0.8125rem;
    border-radius: 0.375rem;
    padding: 0.375rem 0.75rem;
    outline: none;
    font-family: 'Inter', sans-serif;
    transition: border-color 0.15s;
}
.filter-select:focus,
.filter-date:focus {
    border-color: var(--accent);
}
.filter-clear {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline;
    padding-bottom: 0.375rem;
    font-family: 'Inter', sans-serif;
}
.filter-clear:hover { color: var(--text-heading); }

/* ── Tab Toggle ── */
.tab-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.25rem;
    flex-wrap: wrap;
}
.tab-toggle-btn {
    padding: 0.375rem 1rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    background: transparent;
    transition: all 0.15s;
    font-family: 'Inter', sans-serif;
    white-space: nowrap;
}
.tab-toggle-btn:hover {
    color: var(--text-heading);
}
.tab-toggle-btn.active {
    background: var(--accent);
    color: var(--accent-text);
}

/* ── Loading / Error ── */
.loading-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 12rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}
.error-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 12rem;
    color: var(--red);
    font-size: 0.9rem;
}

/* ── Spinner ── */
.qbo-spinner {
    width: 24px; height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
    display: inline-block;
    vertical-align: middle;
    margin-right: 0.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Section heading ── */
.section-heading {
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 1rem;
}

/* ── Grid helpers ── */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}
@media (min-width: 1024px) {
    .grid-2 { grid-template-columns: repeat(2, 1fr); }
}

/* ── Info card (Company page) ── */
.info-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.25rem;
}
.info-card-title {
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}
.info-row {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-light);
}
.info-row:last-child { border-bottom: none; }
.info-row-label {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.info-row-value {
    color: var(--text-primary);
    font-size: 0.875rem;
}

/* ── Status badges ── */
.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
}
.status-subscribed {
    background: rgba(31,146,84,0.12);
    border: 1px solid var(--green);
    color: #1a7a46;
}
.status-unsubscribed {
    background: rgba(232,57,42,0.1);
    border: 1px solid var(--red);
    color: var(--red);
}
.status-plan {
    background: var(--bg-section);
    border: 1px solid var(--border);
    color: var(--text-primary);
}

/* ── Period badge ── */
.period-badge {
    display: inline-block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-section);
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    padding: 0.125rem 0.5rem;
}

/* ── Balance indicator ── */
.balance-ok { color: #1a7a46; font-weight: 600; font-size: 0.875rem; }
.balance-bad { color: var(--red); font-weight: 600; font-size: 0.875rem; }

/* ── Tab page container ── */
.tab-page {
    padding: 1.5rem;
}
.tab-page > * + * {
    margin-top: 1.5rem;
}

/* ── Error banner ── */
.error-banner {
    padding: 1rem;
    background: rgba(232,57,42,0.08);
    border-left: 3px solid var(--red);
    border-radius: 4px;
    color: var(--red);
    font-size: 0.88rem;
    margin-bottom: 1rem;
}

/* ── Modal ── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(28,28,26,0.55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}
.modal-overlay.visible { display: flex; }

.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem 2.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 12px 48px rgba(28,28,26,0.2);
    animation: fadeIn 0.2s ease;
}
.modal-card h3 {
    font-family: 'Manrope', sans-serif;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-heading);
    margin-bottom: 0.5rem;
}
.modal-card p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
    line-height: 1.5;
}
.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

.btn-outline {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 0.6rem 1.4rem;
    border-radius: 6px;
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}
.btn-outline:hover {
    border-color: var(--text-secondary);
    color: var(--text-heading);
}

/* ── Connect tab ── */
.connect-card {
    max-width: 520px;
    margin: 2rem auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2.5rem;
    text-align: center;
}
.connect-icon { margin-bottom: 1rem; }
.connect-icon svg { width: 48px; height: 48px; }
.connect-title {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}
.connect-desc {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
    line-height: 1.6;
}
.connect-btn {
    display: block;
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: #2CA01C;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.connect-btn:hover { background: #228b15; }
.connect-btn-secondary {
    display: block;
    width: 100%;
    margin-top: 0.75rem;
    padding: 0.7rem 1.5rem;
    background: transparent;
    color: #2CA01C;
    border: 1.5px solid #2CA01C;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.connect-btn-secondary:hover { background: rgba(44,160,28,0.08); }
.connect-error {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: rgba(232,57,42,0.08);
    border: 1px solid var(--red);
    border-radius: 8px;
    font-size: 0.8125rem;
    color: var(--red);
    text-align: left;
}
.connect-notice {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    text-align: left;
    background: rgba(201,154,59,0.1);
    border: 1px solid rgba(201,154,59,0.35);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1.25rem;
    font-size: 0.875rem;
    color: var(--text-primary);
    line-height: 1.55;
}
.connect-notice p { margin-top: 0.25rem; color: var(--text-secondary); }
.connect-spinner { margin: 1.5rem 0; }
.connect-status {
    color: var(--text-secondary);
    font-size: 0.875rem;
}
.connect-success-icon { margin-bottom: 0.75rem; }

/* ── Footer ── */
.app-footer {
    background: var(--bg-dark);
    color: rgba(255,255,255,0.7);
    padding: 1.25rem 1.5rem;
    font-size: 0.8rem;
}
.app-footer a { color: var(--gold); }

/* ── Responsive ── */
@media (max-width: 992px) {
    .sidebar { width: 200px; }
    .main-content { margin-left: 200px; width: calc(100% - 200px); }
}
@media (max-width: 768px) {
    .app-container { flex-direction: column; }
    .sidebar { width: 100%; position: relative; height: auto; }
    .main-content { margin-left: 0; width: 100%; }
}
