/* Layout */
:root {
    color-scheme: light;
    --bg: #f7f8fb;
    --panel: rgba(255, 255, 255, 0.86);
    --panel-strong: #ffffff;
    --text: #111827;
    --muted: #64748b;
    --line: rgba(15, 23, 42, 0.09);
    --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
    --brand: #2563eb;
    --green: #16a34a;
    --amber: #d97706;
    --purple: #7c3aed;
}

.dark {
    color-scheme: dark;
    --bg: #080b12;
    --panel: rgba(16, 23, 34, 0.84);
    --panel-strong: #101722;
    --text: #f8fafc;
    --muted: #94a3b8;
    --line: rgba(148, 163, 184, 0.16);
    --shadow: 0 18px 60px rgba(0, 0, 0, 0.34);
}

* { box-sizing: border-box; }

body.app-shell {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.11), transparent 30rem),
        linear-gradient(135deg, var(--bg), var(--bg));
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, sans-serif;
    transition: background-color 180ms ease, color 180ms ease;
}

.dashboard-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.25rem;
    border-right: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.62);
    backdrop-filter: blur(24px);
}

.dark .sidebar { background: rgba(8, 11, 18, 0.76); }

.content-panel {
    min-width: 0;
    padding: 1.25rem 1.5rem 2rem;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.topbar h1,
.section-heading h2,
.login-art h1 {
    margin: 0;
    font-weight: 800;
    letter-spacing: 0;
}

.topbar h1 { font-size: clamp(1.75rem, 4vw, 2.6rem); }

.topbar-actions,
.action-row,
.legend-row,
.revenue-band,
.filter-bar,
.pagination-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand-lockup,
.user-chip {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text);
    text-decoration: none;
}

.brand-lockup small,
.user-chip small,
.helper-copy,
.eyebrow,
.stat-card span,
.stat-card small,
.total-row span {
    color: var(--muted);
}

.brand-lockup strong,
.user-chip strong {
    display: block;
    line-height: 1.1;
}

.brand-mark,
.avatar {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, #2563eb, #14b8a6);
    color: #fff;
    font-weight: 800;
}

.side-nav {
    display: grid;
    gap: 0.35rem;
}

.side-nav a {
    padding: 0.8rem 0.9rem;
    border-radius: 14px;
    color: var(--muted);
    text-decoration: none;
    transition: 160ms ease;
}

.side-nav a:hover,
.side-nav a.is-active {
    background: var(--panel-strong);
    color: var(--text);
    box-shadow: 0 8px 30px rgba(15, 23, 42, 0.06);
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 1rem;
}

.logout-link,
.secondary-link {
    color: var(--brand);
    text-decoration: none;
    font-weight: 700;
}

/* Cards */
.panel,
.stat-card,
.login-card,
.orbital-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(20px);
}

.panel { padding: 1.25rem; }

.page-grid {
    display: grid;
    gap: 1.25rem;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
}

.stat-card {
    padding: 1.15rem;
    display: grid;
    gap: 0.5rem;
    border-top: 4px solid var(--brand);
}

.stat-card strong {
    font-size: 2rem;
    line-height: 1;
}

.accent-green { border-top-color: var(--green); }
.accent-amber { border-top-color: var(--amber); }
.accent-purple { border-top-color: var(--purple); }

.dashboard-columns {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 1.25rem;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.section-heading.compact { margin-bottom: 0.75rem; }

.eyebrow {
    margin: 0 0 0.25rem;
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0;
}

.currency-pill,
.save-indicator {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.4rem 0.65rem;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
}

.quick-actions {
    display: grid;
    gap: 0.7rem;
}

.quick-actions a,
.primary-action,
.secondary-button,
.icon-button,
.pagination-bar button,
.action-row a,
.action-row button,
.prefix-row button,
.prefix-delete button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.65rem 0.9rem;
    color: var(--text);
    background: var(--panel-strong);
    font-weight: 700;
    text-decoration: none;
    transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.quick-actions a:hover,
.primary-action:hover,
.secondary-button:hover,
.icon-button:hover,
.action-row a:hover,
.action-row button:hover {
    transform: translateY(-1px);
    border-color: rgba(37, 99, 235, 0.35);
}

.primary-action {
    border-color: transparent;
    background: var(--brand);
    color: #fff;
}

/* Forms */
input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel-strong);
    color: var(--text);
    padding: 0.7rem 0.8rem;
    outline: none;
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

textarea { resize: vertical; }

input:focus,
select:focus,
textarea:focus {
    border-color: rgba(37, 99, 235, 0.55);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

label span {
    display: block;
    margin-bottom: 0.45rem;
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 700;
}

.form-stack {
    display: grid;
    gap: 1rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.invoice-builder {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 1.25rem;
    align-items: start;
}

.totals-sidebar {
    position: sticky;
    top: 1.25rem;
    display: grid;
    gap: 1rem;
}

.total-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 1px solid var(--line);
    padding-bottom: 0.85rem;
}

.total-row.grand strong { font-size: 1.35rem; }

.item-list {
    display: grid;
    gap: 0.75rem;
}

.item-row {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 100px 140px 140px 44px;
    gap: 0.7rem;
    align-items: end;
    padding: 0.75rem;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.48);
}

.dark .item-row { background: rgba(255, 255, 255, 0.03); }

.remove-item {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid rgba(220, 38, 38, 0.22);
    color: #dc2626;
}

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

.modern-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

.modern-table th,
.modern-table td {
    border-bottom: 1px solid var(--line);
    padding: 0.85rem 0.75rem;
    text-align: left;
    vertical-align: middle;
}

.modern-table th {
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0;
}

.interactive-table th[data-sort] {
    cursor: pointer;
}

.modern-table tbody tr {
    transition: background 150ms ease;
}

.modern-table tbody tr:hover {
    background: rgba(37, 99, 235, 0.05);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border-radius: 999px;
    padding: 0.3rem 0.6rem;
    font-size: 0.78rem;
    font-weight: 800;
}

.badge-paid { background: rgba(22, 163, 74, 0.12); color: #15803d; }
.badge-pending { background: rgba(217, 119, 6, 0.14); color: #b45309; }
.badge-partial { background: rgba(124, 58, 237, 0.14); color: #6d28d9; }
.badge-unpaid { background: rgba(239, 68, 68, 0.12); color: #dc2626; }

.filter-bar {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) 180px 160px 160px;
    margin-bottom: 1rem;
}

.action-row {
    flex-wrap: wrap;
    align-items: stretch;
    position: relative;
}

.action-row form,
.inline-action-form {
    margin: 0;
}

.action-row a,
.action-row button,
.prefix-row button,
.prefix-delete button {
    min-height: 34px;
    padding: 0.45rem 0.65rem;
    font-size: 0.8rem;
}

.action-row button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.action-menu {
    position: relative;
}

.action-menu summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel-strong);
    color: var(--text);
    cursor: pointer;
    font-weight: 900;
    list-style: none;
}

.action-menu summary::-webkit-details-marker {
    display: none;
}

.action-menu[open] summary {
    border-color: rgba(37, 99, 235, 0.35);
}

.action-menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 0.4rem);
    z-index: 20;
    display: grid;
    min-width: 170px;
    gap: 0.25rem;
    padding: 0.4rem;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel-strong);
    box-shadow: var(--shadow);
}

.action-menu-panel a,
.action-menu-panel button {
    width: 100%;
    justify-content: flex-start;
    border-color: transparent;
    background: transparent;
    text-align: left;
}

.action-menu-panel a:hover,
.action-menu-panel button:hover {
    background: rgba(37, 99, 235, 0.08);
    transform: none;
}

/* Settings */
.settings-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 1.25rem;
}

.settings-tabs {
    display: grid;
    align-content: start;
    gap: 0.5rem;
}

.settings-tabs button {
    border: 0;
    border-radius: 12px;
    padding: 0.8rem 0.9rem;
    background: transparent;
    color: var(--muted);
    text-align: left;
    font-weight: 800;
}

.settings-tabs button.is-active {
    background: var(--panel-strong);
    color: var(--text);
}

.settings-panel { display: none; }
.settings-panel.is-active { display: block; }

.prefix-list {
    display: grid;
    gap: 0.45rem;
    margin-bottom: 1rem;
}

.prefix-row,
.add-prefix-form {
    display: grid;
    grid-template-columns: 1fr 120px 110px;
    gap: 0.65rem;
    align-items: center;
}

.prefix-delete {
    display: none;
}

/* Animations */
.skeleton {
    min-height: 1rem;
    border-radius: 12px;
    background: linear-gradient(90deg, rgba(148, 163, 184, 0.14), rgba(148, 163, 184, 0.28), rgba(148, 163, 184, 0.14));
    background-size: 220% 100%;
    animation: pulse-skeleton 1.25s ease-in-out infinite;
}

@keyframes pulse-skeleton {
    from { background-position: 220% 0; }
    to { background-position: -220% 0; }
}

.fade-up,
.fade-left,
.fade-right,
.zoom-in {
    opacity: 0;
    transform: translateY(14px);
    transition: opacity 520ms ease, transform 520ms ease;
}

.fade-left { transform: translateX(-14px); }
.fade-right { transform: translateX(14px); }
.zoom-in { transform: scale(0.98); }

.is-visible {
    opacity: 1;
    transform: translate(0) scale(1);
}

/* Utilities */
.toast-root {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 50;
    display: grid;
    gap: 0.7rem;
}

.toast {
    width: min(360px, calc(100vw - 2rem));
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--panel-strong);
    box-shadow: var(--shadow);
    padding: 0.9rem 1rem;
    color: var(--text);
    animation: toast-in 220ms ease;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.status-meter {
    display: flex;
    height: 12px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.16);
}

.status-meter span:nth-child(1) { background: var(--green); }
.status-meter span:nth-child(2) { background: var(--amber); }
.status-meter span:nth-child(3) { background: var(--purple); }

.dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 999px;
    margin-right: 0.35rem;
}

.dot-green { background: var(--green); }
.dot-amber { background: var(--amber); }
.dot-purple { background: var(--purple); }

.empty-state {
    display: grid;
    place-items: center;
    text-align: center;
    padding: 2rem;
    color: var(--muted);
}

.empty-state h3 {
    color: var(--text);
    margin: 0;
}

.empty-state-svg {
    width: 180px;
    max-width: 100%;
}

.svg-card {
    fill: rgba(37, 99, 235, 0.08);
    stroke: rgba(37, 99, 235, 0.28);
    animation: svg-float 2.4s ease-in-out infinite;
}

.svg-line {
    stroke: var(--brand);
    stroke-width: 8;
    stroke-linecap: round;
    opacity: 0.65;
}

.svg-dot {
    fill: #14b8a6;
    animation: svg-pulse 1.8s ease-in-out infinite;
}

@keyframes svg-float {
    50% { transform: translateY(-4px); }
}

@keyframes svg-pulse {
    50% { opacity: 0.45; transform: scale(0.92); transform-origin: center; }
}

.login-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    align-items: center;
    gap: 2rem;
    padding: 2rem;
}

.login-art,
.login-card {
    max-width: 620px;
    width: 100%;
    margin: auto;
}

.orbital-card,
.login-card {
    padding: 2rem;
}

.mini-metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-top: 2rem;
}

.mini-metrics span {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 0.85rem;
    background: var(--panel-strong);
}

.mini-metrics strong,
.mini-metrics small {
    display: block;
}

.w-full { width: 100%; }
.justify-center { justify-content: center; }
.self-start { justify-self: start; }

@media (max-width: 1100px) {
    .dashboard-layout,
    .login-page,
    .invoice-builder,
    .settings-layout,
    .dashboard-columns {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
    }

    .stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .totals-sidebar {
        position: static;
    }
}

@media (max-width: 760px) {
    .content-panel,
    .login-page {
        padding: 1rem;
    }

    .topbar,
    .section-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar-actions,
    .filter-bar,
    .form-grid,
    .form-grid.two,
    .item-row,
    .prefix-row,
    .add-prefix-form {
        grid-template-columns: 1fr;
        width: 100%;
    }

    .stat-grid {
        grid-template-columns: 1fr;
    }
}
