@font-face {
    font-family: 'Priestacy';
    src: url('/fonts/Priestacy.otf') format('opentype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

/* ════════════════════════════════════════════════════════════
   Studio Black — Portal Design System
   Scoped tokens: the portal owns its palette so marketing-site
   changes to main.css never bleed into the panels.
   ════════════════════════════════════════════════════════════ */

.portal-body {
    /* brand */
    --gold: #C9A84C;
    --gold-bright: #E6C97A;
    --gold-dark: #8B7025;
    --gold-wash: rgba(201, 168, 76, 0.07);
    --gold-line: rgba(201, 168, 76, 0.28);

    /* surfaces */
    --bg: #060607;
    --surface: #0C0C0E;
    --surface-2: #111114;
    --surface-3: #16161A;
    --border: #1C1C21;
    --border-strong: #2A2A31;

    /* text */
    --text: #ECECE8;
    --text-dim: #9C9C94;
    --text-muted: #62625C;

    /* semantics */
    --ok: #6FBF8C;
    --ok-dim: rgba(111, 191, 140, 0.10);
    --ok-line: rgba(111, 191, 140, 0.30);
    --info: #7FA6D9;
    --info-dim: rgba(127, 166, 217, 0.10);
    --info-line: rgba(127, 166, 217, 0.30);
    --warn: #D9B36A;
    --warn-dim: rgba(217, 179, 106, 0.10);
    --warn-line: rgba(217, 179, 106, 0.32);
    --danger: #D97A7A;
    --danger-dim: rgba(217, 122, 122, 0.09);
    --danger-line: rgba(217, 122, 122, 0.30);

    /* geometry */
    --sidebar-w: 232px;
    --header-h: 56px;
    --radius: 10px;
    --radius-sm: 7px;
    --shadow-card: 0 1px 0 rgba(255,255,255,0.02) inset, 0 10px 30px -18px rgba(0,0,0,0.8);
    --shadow-pop: 0 12px 40px -12px rgba(0,0,0,0.85);
}

.portal-body {
    min-height: 100vh;
    background:
        radial-gradient(1100px 420px at 50% -180px, rgba(201, 168, 76, 0.055), transparent 70%),
        var(--bg);
    color: var(--text);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
}

.portal-body ::selection { background: rgba(201, 168, 76, 0.25); color: #fff; }

.portal-body :focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
    border-radius: 2px;
}

/* thin, quiet scrollbars */
.portal-body ::-webkit-scrollbar { width: 10px; height: 10px; }
.portal-body ::-webkit-scrollbar-thumb { background: #232328; border-radius: 5px; border: 2px solid var(--bg); }
.portal-body ::-webkit-scrollbar-thumb:hover { background: #2E2E35; }
.portal-body ::-webkit-scrollbar-track { background: transparent; }

.portal-body .btn:active,
.portal-body .btn-ghost:active,
.portal-body .btn-fill:active {
    transform: translateY(1px);
}

/* ── Header ── */

.portal-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: var(--header-h);
    background: rgba(6, 6, 7, 0.82);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(14px) saturate(1.3);
    -webkit-backdrop-filter: blur(14px) saturate(1.3);
}

.portal-header::after {
    /* hairline gold signature under the header */
    content: '';
    position: absolute;
    left: 0; right: 0; bottom: -1px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold-line) 18%, var(--gold-line) 82%, transparent);
    opacity: 0.45;
    pointer-events: none;
}

.portal-header-inner {
    max-width: 100%;
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
}

.portal-header .nav-logo {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.3rem;
    background: linear-gradient(135deg, #8B7025 0%, #C9A84C 30%, #F0D68C 50%, #C9A84C 70%, #8B7025 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
    line-height: 1.4;
    padding: 0.15em 0.1em;
    text-decoration: none;
}

.portal-header-nav {
    display: flex;
    align-items: center;
    gap: 18px;
}

.portal-user-name {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 0.72rem;
    color: var(--text-dim);
    letter-spacing: 0.05em;
}

.portal-header-nav .nav-link {
    font-size: 0.62rem;
    color: var(--text-dim);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    transition: all 0.2s ease;
    text-decoration: none;
}

.portal-header-nav .nav-link:hover {
    color: var(--gold);
    border-color: var(--gold-dark);
    background: var(--gold-wash);
}

/* ── Layout ── */

.portal-layout {
    display: flex;
    padding-top: var(--header-h);
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    min-height: calc(100vh - var(--header-h));
    border-right: 1px solid var(--border);
    padding: 20px 0 32px;
    position: fixed;
    top: var(--header-h);
    left: 0;
    overflow-y: auto;
    background: linear-gradient(180deg, rgba(255,255,255,0.012), transparent 120px);
}

.sidebar-section {
    padding: 0 14px;
    margin-bottom: 24px;
}

.sidebar-label {
    font-size: 0.56rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.22em;
    color: var(--text-muted);
    padding: 0 12px;
    margin-bottom: 8px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    margin-bottom: 1px;
    font-size: 0.74rem;
    color: var(--text-dim);
    letter-spacing: 0.03em;
    border-radius: var(--radius-sm);
    border-left: 2px solid transparent;
    transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease;
    text-decoration: none;
    min-height: 38px;
}

.sidebar-link:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.03);
}

.sidebar-link:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: -2px;
}

.sidebar-link.active {
    color: var(--gold-bright);
    border-left-color: var(--gold);
    background: linear-gradient(90deg, var(--gold-wash), rgba(201, 168, 76, 0.02));
}

.sidebar-link svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    opacity: 0.75;
    transition: opacity 0.18s ease;
}

.sidebar-link:hover svg,
.sidebar-link.active svg { opacity: 1; }

.sidebar-link.sidebar-child {
    padding-left: 40px;
    min-height: 30px;
    font-size: 0.68rem;
    opacity: 0.7;
}
.sidebar-link.sidebar-child:hover { opacity: 1; }
.sidebar-link.sidebar-child.active { opacity: 1; color: var(--gold-bright); }

.sidebar-badge {
    margin-left: auto;
    background: var(--gold);
    color: #000;
    font-size: 0.56rem;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 999px;
    line-height: 1.6;
}

.portal-main {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 36px 44px 64px;
    max-width: calc(100% - var(--sidebar-w));
}

/* ── Page header ── */

.page-header {
    margin-bottom: 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.page-title {
    font-size: 1.55rem;
    font-weight: 650;
    letter-spacing: -0.025em;
    line-height: 1.2;
}

.breadcrumb {
    font-size: 0.64rem;
    font-family: var(--mono);
    color: var(--text-muted);
    margin-bottom: 10px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.breadcrumb a { color: var(--text-dim); transition: color 0.2s; text-decoration: none; }
.breadcrumb a:hover { color: var(--gold); }
.breadcrumb-sep { margin: 0 7px; color: var(--gold-dark); }

/* ── Cards ── */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 24px;
    margin-bottom: 20px;
    position: relative;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.card-title {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--text-dim);
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.card-title::before {
    content: '';
    width: 14px;
    height: 1px;
    background: var(--gold);
    opacity: 0.8;
    flex-shrink: 0;
}

/* ── Stats ── */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 30px;
}

.stat-card {
    background: linear-gradient(180deg, var(--surface-2), var(--surface));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 20px 20px 18px;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    /* gold corner signature, kept from v1 but softer */
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 26px; height: 26px;
    border-top: 1px solid var(--gold-line);
    border-left: 1px solid var(--gold-line);
    border-top-left-radius: var(--radius);
    pointer-events: none;
}

.stat-value {
    font-size: 1.7rem;
    font-weight: 650;
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.03em;
    line-height: 1.1;
    margin-bottom: 8px;
    color: var(--text);
}

.stat-label {
    font-size: 0.58rem;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ── Tables ── */

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.data-table thead th {
    font-size: 0.58rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--text-muted);
    padding: 8px 12px 10px;
    border-bottom: 1px solid var(--border-strong);
    text-align: left;
    white-space: nowrap;
}

.data-table tbody td {
    padding: 13px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}

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

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

.data-table tbody tr:hover td {
    background: rgba(201, 168, 76, 0.025);
}

.data-table a {
    color: var(--text);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}
.data-table a:hover { color: var(--gold); border-bottom-color: var(--gold-dark); }

.table-actions { display: flex; gap: 8px; }

/* ── Badges ── */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    font-size: 0.55rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    border: 1px solid;
    border-radius: 999px;
    line-height: 1.6;
    white-space: nowrap;
}

.badge::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.badge-paid, .badge-active, .badge-succeeded {
    color: var(--ok);
    border-color: var(--ok-line);
    background: var(--ok-dim);
}

.badge-draft, .badge-pending {
    color: var(--text-dim);
    border-color: var(--border-strong);
    background: rgba(255, 255, 255, 0.02);
}

.badge-sent {
    color: var(--info);
    border-color: var(--info-line);
    background: var(--info-dim);
}

.badge-overdue, .badge-past_due, .badge-failed {
    color: var(--danger);
    border-color: var(--danger-line);
    background: var(--danger-dim);
}

.badge-void, .badge-canceled {
    color: var(--text-muted);
    border-color: var(--border);
    background: transparent;
    text-decoration: line-through;
}

.badge-void::before, .badge-canceled::before { opacity: 0.5; }

/* ── Buttons (portal-scoped skins over main.css .btn) ── */

.portal-body .btn {
    border-radius: var(--radius-sm);
    font-size: 0.64rem;
    letter-spacing: 0.12em;
    transition: all 0.2s ease;
}

.portal-body .btn-fill {
    background: linear-gradient(180deg, #D8B75C, #B8933B);
    border: 1px solid #A8842E;
    color: #0A0800;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.15);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset, 0 6px 16px -8px rgba(201, 168, 76, 0.5);
}

.portal-body .btn-fill:hover {
    background: linear-gradient(180deg, #E3C670, #C4A047);
    border-color: var(--gold);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset, 0 8px 22px -8px rgba(201, 168, 76, 0.65);
}

.portal-body .btn-line {
    border: 1px solid var(--border-strong);
    color: var(--text-dim);
    background: transparent;
}

.portal-body .btn-line:hover {
    border-color: var(--gold-dark);
    color: var(--gold);
    background: var(--gold-wash);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.6rem;
    min-height: 34px;
}

.btn-danger {
    border: 1px solid var(--danger-line);
    color: var(--danger);
    border-radius: var(--radius-sm);
    background: transparent;
}

.btn-danger:hover {
    border-color: var(--danger);
    background: var(--danger-dim);
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 13px;
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-dim);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: none;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 34px;
    text-decoration: none;
}

.btn-ghost:hover {
    border-color: var(--gold-dark);
    color: var(--gold);
    background: var(--gold-wash);
}

.btn-ghost-danger { color: var(--danger); border-color: var(--danger-line); }
.btn-ghost-danger:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-dim); }

/* ── Forms ── */

.form-portal .field {
    margin-bottom: 20px;
}

.form-portal label {
    display: block;
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--text-dim);
    margin-bottom: 7px;
}

.form-portal input:not([type="checkbox"]):not([type="radio"]),
.form-portal select,
.form-portal textarea {
    width: 100%;
    padding: 12px 14px;
    font-family: var(--font);
    font-size: 0.95rem;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
    min-height: 44px;
}

.form-portal input:hover,
.form-portal select:hover,
.form-portal textarea:hover {
    border-color: #34343C;
}

.form-portal input:focus,
.form-portal select:focus,
.form-portal textarea:focus {
    border-color: var(--gold-dark);
    background: var(--surface-3);
    box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.12);
    outline: none;
}

.form-portal input[type="checkbox"],
.form-portal input[type="radio"],
.portal-body input[type="checkbox"],
.portal-body input[type="radio"] {
    -webkit-appearance: auto !important;
    appearance: auto !important;
    width: 16px !important;
    height: 16px !important;
    accent-color: var(--gold);
    cursor: pointer;
    min-height: auto;
    flex-shrink: 0;
}

.form-portal input::placeholder,
.form-portal textarea::placeholder {
    color: var(--text-muted);
}

.form-portal textarea {
    resize: vertical;
    min-height: 100px;
}

.form-portal select {
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23888' stroke-width='1.2'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
    cursor: pointer;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* ── Flash messages ── */

.flash-messages { margin-bottom: 24px; }

.flash {
    padding: 13px 16px 13px 18px;
    font-size: 0.8rem;
    border: 1px solid;
    border-left-width: 3px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    line-height: 1.55;
}

.flash-success {
    color: var(--ok);
    border-color: var(--ok-line);
    background: var(--ok-dim);
}

.flash-info {
    color: var(--info);
    border-color: var(--info-line);
    background: var(--info-dim);
}

.flash-warning {
    color: var(--warn);
    border-color: var(--warn-line);
    background: var(--warn-dim);
}

.flash-error {
    color: var(--danger);
    border-color: var(--danger-line);
    background: var(--danger-dim);
}

/* ── Pagination ── */

.pagination {
    display: flex;
    gap: 6px;
    margin-top: 24px;
    justify-content: center;
}

.pagination a, .pagination span {
    padding: 8px 14px;
    font-size: 0.7rem;
    font-family: var(--mono);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    transition: all 0.2s;
    min-height: 34px;
    display: flex;
    align-items: center;
    text-decoration: none;
}

.pagination a:hover {
    border-color: var(--gold-dark);
    color: var(--gold);
    background: var(--gold-wash);
}

.pagination .active {
    color: var(--gold);
    border-color: var(--gold-dark);
    background: var(--gold-wash);
}

/* ── Auth pages ── */

.auth-body .portal-layout { justify-content: center; }
.auth-body .sidebar { display: none; }
.auth-body .portal-main { margin-left: 0; max-width: 440px; padding-top: 80px; }

.auth-card {
    background: linear-gradient(180deg, var(--surface-2), var(--surface));
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 2px);
    box-shadow: var(--shadow-pop);
    padding: 44px 40px;
    position: relative;
}

.auth-card::before,
.auth-card::after {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    border-color: var(--gold-line);
    border-style: solid;
    pointer-events: none;
}

.auth-card::before { top: -1px; left: -1px; border-width: 1px 0 0 1px; border-top-left-radius: calc(var(--radius) + 2px); }
.auth-card::after { bottom: -1px; right: -1px; border-width: 0 1px 1px 0; border-bottom-right-radius: calc(var(--radius) + 2px); }

.auth-title {
    font-size: 1.25rem;
    font-weight: 650;
    letter-spacing: -0.02em;
    text-align: center;
    margin-bottom: 8px;
}

.auth-subtitle {
    font-size: 0.8rem;
    color: var(--text-dim);
    text-align: center;
    margin-bottom: 28px;
}

.auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 0.75rem;
    color: var(--text-dim);
}

.auth-footer a {
    color: var(--gold);
    transition: color 0.2s;
    padding: 8px;
    text-decoration: none;
}

.auth-footer a:hover { color: var(--gold-bright); }

/* ── Line items table (invoice editor) ── */

.line-items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}

.line-items-table th {
    font-size: 0.58rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--text-muted);
    padding: 8px;
    border-bottom: 1px solid var(--border-strong);
    text-align: left;
}

.line-items-table td {
    padding: 8px;
    border-bottom: 1px solid var(--border);
}

.line-items-table input {
    width: 100%;
    padding: 10px;
    font-family: var(--font);
    font-size: 0.85rem;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    min-height: 40px;
}

.line-items-table input:focus {
    border-color: var(--gold-dark);
    box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.12);
}

.line-item-total {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    font-size: 0.82rem;
    color: var(--text-dim);
    min-width: 80px;
    text-align: right;
}

.invoice-total {
    text-align: right;
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    font-size: 1.25rem;
    font-weight: 650;
    color: var(--gold-bright);
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-strong);
}

/* ── Dashboard grid ── */

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* ── Empty state ── */

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
    font-size: 0.82rem;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.008);
}

/* ── Filters ── */

.filters-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 24px;
    align-items: center;
    flex-wrap: wrap;
}

.filters-bar select,
.filters-bar input {
    padding: 9px 12px;
    font-family: var(--font);
    font-size: 0.8rem;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    outline: none;
    min-height: 38px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.filters-bar select:focus,
.filters-bar input:focus {
    border-color: var(--gold-dark);
    box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.12);
}

/* ── Activity ── */

.activity-list { list-style: none; }

.activity-item {
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text-dim);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.activity-item:last-child { border-bottom: none; }

.activity-time {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    font-size: 0.63rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ── Submissions ── */

.submission-detail {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    margin-top: 8px;
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--text-dim);
}

.submission-field { margin-bottom: 8px; }

.submission-label {
    font-size: 0.58rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin-bottom: 2px;
}

/* ── Stripe ── */

#payment-element {
    padding: 16px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    margin: 16px 0;
}

/* ── Mobile Menu Toggle ── */

.portal-menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 12px;
    color: var(--text-dim);
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 90;
}

.sidebar-overlay.overlay-open {
    display: block;
}

/* ── Responsive ── */

@media (max-width: 768px) {
    .portal-menu-toggle { display: flex; }

    .sidebar {
        display: none;
        position: fixed;
        top: var(--header-h);
        left: 0;
        bottom: 0;
        width: 264px;
        z-index: 95;
        background: var(--bg);
        border-right: 1px solid var(--border);
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

    .sidebar.sidebar-open {
        display: block;
        transform: translateX(0);
    }

    /* Layout */
    .portal-main { margin-left: 0; max-width: 100%; padding: 16px 12px 48px; }
    .portal-header-inner { padding: 0 8px 0 4px; }
    .portal-user-name { display: none; }

    /* Page header */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        margin-bottom: 20px;
    }
    .page-title { font-size: 1.2rem; }
    .breadcrumb { font-size: 0.58rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

    /* Cards */
    .card { padding: 14px 12px; margin-bottom: 14px; }
    .card-header { margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }

    /* Stats */
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 20px; }
    .stat-card { padding: 14px 12px; }
    .stat-value { font-size: 1.15rem; word-break: break-all; }
    .stat-label { font-size: 0.5rem; letter-spacing: 0.08em; }

    /* Tables — horizontal scroll wrapper */
    .data-table { font-size: 0.72rem; display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .data-table thead, .data-table tbody, .data-table tr { min-width: 500px; }
    .data-table thead th { padding: 8px 6px; font-size: 0.5rem; white-space: nowrap; }
    .data-table tbody td { padding: 10px 6px; }
    .table-actions { gap: 4px; }
    .table-actions .btn-ghost { padding: 5px 8px; font-size: 0.5rem; min-height: 30px; }

    /* Forms */
    .form-row { grid-template-columns: 1fr; gap: 12px; }
    .form-portal .field { margin-bottom: 14px; }

    /* Filters */
    .filters-bar { gap: 8px; }
    .filters-bar select,
    .filters-bar input { width: 100%; font-size: 1rem; }

    /* Line items — stack on mobile */
    .line-items-table { font-size: 0.7rem; display: block; overflow-x: auto; }
    .line-items-table input { font-size: 0.85rem; padding: 8px 6px; min-height: 36px; }
    .line-item-total { min-width: 60px; font-size: 0.7rem; }
    .invoice-total { font-size: 1rem; }

    /* Buttons */
    .btn-sm { padding: 8px 12px; font-size: 0.55rem; min-height: 40px; }
    .btn-ghost { padding: 8px 10px; font-size: 0.55rem; min-height: 36px; }
    .btn-danger { min-height: 40px; }

    /* Flash */
    .flash { font-size: 0.75rem; padding: 10px 12px; word-break: break-word; }

    /* Pagination */
    .pagination { flex-wrap: wrap; }
    .pagination a, .pagination span { padding: 6px 10px; font-size: 0.6rem; }

    /* Empty */
    .empty-state { padding: 32px 12px; font-size: 0.78rem; }

    /* Auth */
    .auth-card { padding: 24px 16px; }
    .auth-body .portal-main { padding-top: 30px; max-width: 100%; }
    .auth-body .portal-menu-toggle { display: none; }
    .auth-title { font-size: 1rem; }

    /* Badges */
    .badge { font-size: 0.5rem; padding: 2px 8px; }

    /* Activity */
    .activity-item { font-size: 0.72rem; flex-wrap: wrap; gap: 4px; }

    /* Submissions */
    .submission-detail { padding: 10px; font-size: 0.75rem; }

    /* Dashboard */
    .dashboard-grid { grid-template-columns: 1fr; gap: 14px; }

    /* Client detail info grid */
    .card [style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }
    .card [style*="grid-template-columns: 1fr 1fr"] { grid-template-columns: 1fr !important; }

    /* Flex rows that need to stack */
    .card [style*="justify-content:space-between"] { flex-wrap: wrap !important; }
    .card [style*="display:flex;gap:12px;align-items:flex-end"] { flex-direction: column !important; align-items: stretch !important; }

    /* Timer form */
    .form-portal [style*="display:flex;gap:12px;align-items:flex-end"] { flex-direction: column !important; align-items: stretch !important; }

    /* Page header action buttons */
    .page-header [style*="display:flex;gap:8px"] { flex-wrap: wrap !important; }

    /* File upload form */
    form[enctype] { flex-direction: column !important; align-items: stretch !important; }
    form[enctype] [style*="flex:1"] { min-width: 0 !important; width: 100% !important; }

    /* Invoice detail flex layout */
    [style*="display:flex;justify-content:space-between;margin-bottom:20px"] { flex-direction: column !important; gap: 16px !important; }

    /* Email preview grid */
    [style*="grid-template-columns:80px 1fr"] { grid-template-columns: 1fr !important; }

    /* Inline grids with 3+ columns */
    [style*="grid-template-columns:repeat(3"] { grid-template-columns: 1fr !important; }

    /* Ensure no horizontal overflow on body */
    .portal-body { overflow-x: hidden; }
    .portal-main { overflow-x: hidden; }
}
