/* ============================================================================
   TitleVision Scribe — Design System
   ----------------------------------------------------------------------------
   A single shared stylesheet for the customer billing portal. Loaded once by
   _Layout.cshtml. Per-page views should rely on these tokens and component
   classes; only genuinely page-specific rules belong in a view's @section
   Styles block.

   Aesthetic: refined dark dashboard. Dark slate-navy chrome (top bar, sidebar),
   light neutral content area, TitleVision blue (#667eea) as the single accent.
   ========================================================================= */

/* ----------------------------------------------------------------------------
   1. Design tokens
   ------------------------------------------------------------------------- */
:root {
    /* Brand accent — the TitleVision blue, used sparingly for primary actions,
       active nav, focus rings and links. */
    --accent:            #667eea;
    --accent-hover:      #5568d8;
    --accent-active:     #4f5fd3;
    --accent-soft:       rgba(102, 126, 234, 0.12);
    --accent-ring:       rgba(102, 126, 234, 0.35);

    /* Dark chrome — top bar + sidebar. Slate-navy, layered for depth. */
    --chrome-bg:         #0f172a;
    --chrome-bg-raised:  #1e293b;
    --chrome-border:     #1e293b;
    --chrome-text:       #e2e8f0;
    --chrome-text-dim:   #94a3b8;
    --chrome-text-faint: #64748b;
    --chrome-hover:      rgba(255, 255, 255, 0.06);

    /* Light content surfaces. */
    --bg:                #f8fafc;
    --surface:           #ffffff;
    --surface-sunken:    #f1f5f9;
    --border:            #e2e8f0;
    --border-strong:     #cbd5e1;

    /* Text on light surfaces. */
    --text:              #0f172a;
    --text-muted:        #475569;
    --text-faint:        #94a3b8;

    /* Semantic status colors. */
    --success:           #16a34a;
    --success-bg:        #dcfce7;
    --success-text:      #166534;
    --warning:           #d97706;
    --warning-bg:        #fef3c7;
    --warning-text:      #92400e;
    --danger:            #dc2626;
    --danger-bg:         #fee2e2;
    --danger-text:       #991b1b;
    --neutral-bg:        #e2e8f0;
    --neutral-text:      #475569;

    /* Typography. A refined, modern sans stack — distinctive without pulling a
       web font. 'Segoe UI' on Windows, system fallbacks elsewhere. */
    --font-sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;

    /* Shadows — soft, low-spread, layered. Crisp not heavy. */
    --shadow-sm:  0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow:     0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md:  0 4px 12px rgba(15, 23, 42, 0.08), 0 2px 4px rgba(15, 23, 42, 0.04);
    --shadow-lg:  0 12px 32px rgba(15, 23, 42, 0.12), 0 4px 8px rgba(15, 23, 42, 0.05);

    /* Radii — 12px for cards, smaller for controls. Crisper than the old 16px. */
    --radius-sm:  6px;
    --radius:     10px;
    --radius-lg:  12px;
    --radius-xl:  16px;
}

/* ----------------------------------------------------------------------------
   2. Reset & base
   ------------------------------------------------------------------------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.5;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ----------------------------------------------------------------------------
   3. App shell — the layout grid
   ------------------------------------------------------------------------- */
.app-shell {
    display: grid;
    grid-template-columns: 248px 1fr;
    grid-template-rows: 60px 1fr;
    grid-template-areas:
        "topbar topbar"
        "sidebar content";
    min-height: 100vh;
}

/* Logged-out state — no sidebar, single column. */
.app-shell.app-shell--no-sidebar {
    grid-template-columns: 1fr;
    grid-template-areas:
        "topbar"
        "content";
}

/* ----------------------------------------------------------------------------
   4. Top bar
   ------------------------------------------------------------------------- */
.topbar {
    grid-area: topbar;
    background: var(--chrome-bg);
    border-bottom: 1px solid var(--chrome-border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    position: relative;
    z-index: 20;
}

.topbar-logo {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.topbar-logo:hover {
    text-decoration: none;
}

.topbar-logo img {
    height: 38px;
    width: auto;
    display: block;
}

/* Divider between logo and wordmark. */
.topbar-title {
    color: var(--chrome-text);
    font-size: 15px;
    font-weight: 600;
    margin-left: 16px;
    padding-left: 16px;
    border-left: 1px solid var(--chrome-bg-raised);
    letter-spacing: 0.2px;
}

.topbar-spacer {
    flex: 1;
}

.topbar-meta {
    color: var(--chrome-text-dim);
    font-size: 13px;
}

/* Sign-out — quiet ghost button. */
.topbar-logout {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--chrome-text-dim);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    padding: 7px 13px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--chrome-bg-raised);
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.topbar-logout:hover {
    background: var(--chrome-hover);
    border-color: var(--chrome-text-faint);
    color: var(--chrome-text);
    text-decoration: none;
}

.topbar-logout svg {
    width: 14px;
    height: 14px;
}

/* ----------------------------------------------------------------------------
   5. Sidebar
   ------------------------------------------------------------------------- */
.sidebar {
    grid-area: sidebar;
    background: var(--chrome-bg);
    border-right: 1px solid var(--chrome-border);
    padding: 20px 0;
    overflow-y: auto;
}

.sidebar-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--chrome-text-faint);
    padding: 0 24px 10px;
}

.sidebar-nav {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 0 12px;
}

.nav-item a {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    color: var(--chrome-text-dim);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: background 0.13s ease, color 0.13s ease;
}

.nav-item a:hover {
    background: var(--chrome-hover);
    color: var(--chrome-text);
    text-decoration: none;
}

/* Active nav — accent fill. The one place the brand blue appears in the chrome. */
.nav-item.active a {
    background: var(--accent);
    color: #ffffff;
}

.nav-item.active a:hover {
    background: var(--accent-hover);
    color: #ffffff;
}

.nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* ----------------------------------------------------------------------------
   6. Content area & page scaffolding
   ------------------------------------------------------------------------- */
.content {
    grid-area: content;
    overflow-y: auto;
    background: var(--bg);
}

/* Standard page wrapper — replaces the old purple .page-gradient. Provides the
   consistent max-width column + padding every page sits in. */
.page {
    max-width: 1080px;
    margin: 0 auto;
    padding: 36px 32px 64px;
    animation: page-rise 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.page--narrow { max-width: 640px; }
.page--mid    { max-width: 860px; }

/* Centered variant — used by the login page to vertically center its card. */
.page--center {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

@keyframes page-rise {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Page header — title + subtitle block. Dashboard-scale, not hero-scale. */
.page-header {
    margin-bottom: 28px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}

.page-header p {
    margin-top: 4px;
    font-size: 14px;
    color: var(--text-muted);
}

/* Back link — quiet, replaces the old translucent pill button. */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 18px;
    transition: color 0.13s ease;
}

.back-link:hover {
    color: var(--accent);
    text-decoration: none;
}

/* ----------------------------------------------------------------------------
   7. Cards
   ------------------------------------------------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 18px;
}

.card:last-child {
    margin-bottom: 0;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

/* ----------------------------------------------------------------------------
   8. Buttons
   ------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.14s ease, border-color 0.14s ease,
                color 0.14s ease, box-shadow 0.14s ease, transform 0.05s ease;
    text-decoration: none;
}

.btn:hover { text-decoration: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Primary — solid accent. */
.btn-primary {
    background: var(--accent);
    color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    color: #ffffff;
}

/* Secondary — outline. */
.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--surface-sunken);
    border-color: var(--text-faint);
    color: var(--text);
}

/* Small modifier. */
.btn-sm {
    padding: 7px 12px;
    font-size: 13px;
}

/* Full-width modifier. */
.btn-block {
    width: 100%;
}

/* Inline spinner for buttons in a loading state. */
.btn .spinner {
    width: 15px;
    height: 15px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ----------------------------------------------------------------------------
   9. Forms
   ------------------------------------------------------------------------- */
.form-group {
    margin-bottom: 18px;
}

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

.form-input {
    width: 100%;
    padding: 10px 13px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    outline: none;
    transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.form-input::placeholder {
    color: var(--text-faint);
}

.form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

.form-input:disabled {
    background: var(--surface-sunken);
    color: var(--text-muted);
    cursor: not-allowed;
}

.form-hint {
    font-size: 12px;
    color: var(--text-faint);
    margin-top: 6px;
}

/* ----------------------------------------------------------------------------
   10. Alerts
   ------------------------------------------------------------------------- */
.alert {
    padding: 12px 15px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 18px;
    border: 1px solid transparent;
    display: none;
}

.alert.show { display: block; }

.alert-success {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: #bbf7d0;
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger-text);
    border-color: #fecaca;
}

.alert-info {
    background: var(--accent-soft);
    color: var(--accent-active);
    border-color: var(--accent-ring);
}

/* ----------------------------------------------------------------------------
   11. Status pills
   ------------------------------------------------------------------------- */
.status-pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.status-pill.paid          { background: var(--success-bg); color: var(--success-text); }
.status-pill.open          { background: var(--warning-bg); color: var(--warning-text); }
.status-pill.uncollectible { background: var(--danger-bg);  color: var(--danger-text);  }
.status-pill.unknown       { background: var(--neutral-bg); color: var(--neutral-text); }

/* ----------------------------------------------------------------------------
   12. Tables
   ------------------------------------------------------------------------- */
.table-wrap {
    overflow-x: auto;
}

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

table.data th {
    text-align: left;
    color: var(--text-faint);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 10px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table.data td {
    padding: 13px 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}

table.data tbody tr:last-child td {
    border-bottom: none;
}

table.data tbody tr {
    transition: background 0.1s ease;
}

table.data tbody tr:hover td {
    background: var(--surface-sunken);
}

/* Numeric column — tabular figures so digits align. */
td.num, th.num {
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
}

td.num-strong {
    font-weight: 600;
}

/* Monospace cell — invoice numbers, IDs. */
.mono {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-muted);
}

/* ----------------------------------------------------------------------------
   13. Loading & empty states
   ------------------------------------------------------------------------- */
.loading-block {
    text-align: center;
    padding: 56px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

.loading-block::after {
    content: "";
    display: block;
    width: 30px;
    height: 30px;
    margin: 16px auto 0;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-faint);
    font-size: 14px;
}

/* ----------------------------------------------------------------------------
   14. Definition rows — label/value pairs for detail views
   ------------------------------------------------------------------------- */
.def-row {
    display: flex;
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 8px;
}

.def-row:last-child {
    border-bottom: none;
}

.def-label {
    font-weight: 500;
    color: var(--text-muted);
    font-size: 13px;
    width: 170px;
    flex-shrink: 0;
}

.def-value {
    color: var(--text);
    font-size: 14px;
    flex: 1;
    word-break: break-word;
    font-variant-numeric: tabular-nums;
}

/* ----------------------------------------------------------------------------
   15. Responsive — collapse the sidebar into a horizontal strip
   ------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: 60px auto 1fr;
        grid-template-areas:
            "topbar"
            "sidebar"
            "content";
    }

    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--chrome-border);
        padding: 10px 12px;
        overflow-x: auto;
    }

    .sidebar-section-title {
        display: none;
    }

    .sidebar-nav {
        flex-direction: row;
        gap: 6px;
        padding: 0;
    }

    .nav-item a {
        white-space: nowrap;
    }

    .page {
        padding: 24px 18px 48px;
    }

    .topbar {
        padding: 0 16px;
    }
}
