/* ═══════════════════════════════════════════════════════
   ALACTIC FINANCE — "Punchy & Clean" Light Theme
   Professional yet funky invoicing software
   ═══════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,400;12..96,500;12..96,600;12..96,700;12..96,800&family=Gabarito:wght@400;500;600;700;800;900&display=swap');

:root {
    /* Brand — punchy orange-coral */
    --brand: #ff6b35;
    --brand-hover: #e85a27;
    --brand-light: #fff1eb;
    --brand-glow: rgba(255, 107, 53, 0.12);

    /* Surfaces */
    --bg: #f5f3ef;
    --bg-card: #ffffff;
    --bg-sidebar: #1b1b1f;
    --bg-inset: #f9f7f4;
    --bg-input: #ffffff;

    /* Text */
    --text: #1a1a1a;
    --text-secondary: #555555;
    --text-muted: #999999;

    /* Borders */
    --border: #e5e2dc;
    --border-light: #f0ede8;

    /* Semantic */
    --green: #22a06b;
    --green-bg: #e6f9f0;
    --yellow: #cf8600;
    --yellow-bg: #fff7e0;
    --red: #e5483e;
    --red-bg: #ffeeed;
    --blue: #2c7be5;
    --blue-bg: #e8f1fd;
    --purple: #7c5cfc;
    --purple-bg: #f0edff;

    /* Layout */
    --sidebar-w: 240px;

    /* Radii */
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-xl: 20px;
    --r-full: 9999px;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.10);

    /* Motion */
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ─── Reset ─────────────────────────────────────────── */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Bricolage Grotesque', system-ui, sans-serif;
    font-weight: 450;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
}

a {
    text-decoration: none;
    color: inherit;
}

::selection {
    background: var(--brand-light);
    color: var(--brand);
}

/* ─── Layout ────────────────────────────────────────── */

.app-container {
    display: flex;
    min-height: 100vh;
}

/* ─── Sidebar ───────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-header {
    padding: 1.75rem 1.5rem 1.5rem;
}

.sidebar-header h2 {
    font-family: 'Gabarito', sans-serif;
    font-weight: 800;
    font-size: 1.5rem;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    letter-spacing: -0.02em;
}

.sidebar-header h2 i {
    color: var(--brand);
    font-size: 1.15rem;
}

.sidebar-nav {
    padding: 0.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.9rem;
    border-radius: var(--r-sm);
    color: rgba(255,255,255,0.5);
    font-weight: 500;
    font-size: 0.925rem;
    transition: all 0.2s var(--ease);
    cursor: pointer;
}

.nav-item i {
    width: 1.3rem;
    text-align: center;
    font-size: 0.9rem;
    transition: color 0.2s var(--ease);
}

.nav-item:hover {
    background: rgba(255,255,255,0.07);
    color: rgba(255,255,255,0.85);
}

.nav-item.active {
    background: var(--brand);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 2px 12px rgba(255, 107, 53, 0.35);
}

.nav-item.active i {
    color: #fff;
}

/* ─── Main Content ──────────────────────────────────── */

.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    /* Without this, a flex item refuses to shrink below the intrinsic
       min-width of its content — and any wide child (eg a table with
       min-width: 600px) blows out the viewport on mobile. */
    min-width: 0;
}

.topbar {
    background: var(--bg-card);
    padding: 0 2.5rem;
    height: 72px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-title h1 {
    font-family: 'Gabarito', sans-serif;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

.content {
    padding: 2rem 2.5rem 3rem;
    flex: 1;
    animation: pageIn 0.35s var(--ease);
}

@keyframes pageIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─── Flash Messages ────────────────────────────────── */

.flash-messages {
    margin-bottom: 1.5rem;
}

.alert {
    padding: 0.9rem 1.25rem;
    border-radius: var(--r-md);
    font-size: 0.95rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    animation: slideIn 0.3s var(--ease);
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.alert-success { background: var(--green-bg); color: var(--green); }
.alert-danger, .alert-error { background: var(--red-bg); color: var(--red); }
.alert-warning { background: var(--yellow-bg); color: var(--yellow); }
.alert-info { background: var(--blue-bg); color: var(--blue); }

/* ─── Dashboard Stats ───────────────────────────────── */

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

.stat-card {
    background: var(--bg-card);
    padding: 1.35rem 1.25rem;
    border-radius: var(--r-lg);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all 0.25s var(--ease);
    animation: cardPop 0.4s var(--ease) both;
}

.stat-card:nth-child(1) { animation-delay: 0s; }
.stat-card:nth-child(2) { animation-delay: 0.05s; }
.stat-card:nth-child(3) { animation-delay: 0.1s; }
.stat-card:nth-child(4) { animation-delay: 0.15s; }
.stat-card:nth-child(5) { animation-delay: 0.2s; }

@keyframes cardPop {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--brand);
}

.stat-icon {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: var(--r-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    flex-shrink: 0;
}

.revenue-icon  { background: var(--blue-bg);   color: var(--blue); }
.pending-icon  { background: var(--yellow-bg);  color: var(--yellow); }
.customer-icon { background: var(--green-bg);   color: var(--green); }
.invoice-icon  { background: var(--purple-bg);  color: var(--purple); }

.stat-details h3 {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.15rem;
}

.stat-value {
    font-family: 'Gabarito', sans-serif;
    font-size: 1.55rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

/* ─── Dashboard Sections ────────────────────────────── */

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

/* ─── Cards ─────────────────────────────────────────── */

.card {
    background: var(--bg-card);
    border-radius: var(--r-lg);
    border: 1px solid var(--border);
    overflow: hidden;
    animation: fadeUp 0.35s var(--ease) both;
    animation-delay: 0.1s;
}

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

.card-header {
    padding: 1.15rem 1.5rem;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h2 {
    font-family: 'Gabarito', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}

.card-body {
    padding: 1.25rem 1.5rem;
}

/* ─── Buttons ───────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.6rem 1.15rem;
    border-radius: var(--r-sm);
    font-family: 'Bricolage Grotesque', sans-serif;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s var(--ease);
    white-space: nowrap;
}

.btn-sm {
    padding: 0.4rem 0.7rem;
    font-size: 0.8rem;
    border-radius: 6px;
}

.btn-primary {
    background: var(--brand);
    color: #fff;
    box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
}

.btn-primary:hover {
    background: var(--brand-hover);
    box-shadow: 0 4px 16px rgba(255, 107, 53, 0.4);
    transform: translateY(-1px);
    color: #fff;
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-outline {
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    color: var(--text-secondary);
}

.btn-outline:hover {
    border-color: var(--brand);
    color: var(--brand);
    background: var(--brand-light);
}

.btn-block {
    width: 100%;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

/* ─── Tables ────────────────────────────────────────── */

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

.table th {
    padding: 0.8rem 1.25rem;
    text-align: left;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    background: var(--bg-inset);
}

.table td {
    padding: 0.85rem 1.25rem;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.95rem;
    color: var(--text-secondary);
}

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

.table tbody tr:hover {
    background: var(--bg-inset);
}

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

.table td strong {
    color: var(--text);
    font-weight: 600;
}

.table td a {
    color: var(--brand);
    font-weight: 600;
}

.table td a:hover {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.table tfoot td {
    padding: 0.85rem 1.25rem;
    font-weight: 700;
    color: var(--text);
    border-top: 2px solid var(--border);
}

/* ─── Badges ────────────────────────────────────────── */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.7rem;
    border-radius: var(--r-full);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-draft   { background: #f0ede8; color: #777; }
.badge-pending { background: var(--yellow-bg); color: var(--yellow); }
.badge-paid    { background: var(--green-bg); color: var(--green); }
.badge-partial { background: var(--blue-bg); color: var(--blue); }
.badge-overdue { background: var(--red-bg); color: var(--red); }

/* ─── Empty State ───────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 3.5rem 1.5rem;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.4;
}

.empty-state h3 {
    font-family: 'Gabarito', sans-serif;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
    font-size: 1.2rem;
}

.empty-state p {
    font-size: 0.95rem;
    margin-bottom: 1.25rem;
}

.muted-line {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-top: 0.15rem;
}

/* ─── Forms ─────────────────────────────────────────── */

.form-group {
    margin-bottom: 1.15rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="password"],
input[type="date"],
input[type="file"],
select,
textarea {
    font-family: 'Bricolage Grotesque', sans-serif;
    font-size: 0.95rem;
    font-weight: 450;
    color: var(--text);
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: var(--r-sm);
    padding: 0.7rem 0.85rem;
    transition: all 0.2s var(--ease);
    outline: none;
    width: 100%;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-glow);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

input[type="checkbox"] {
    accent-color: var(--brand);
}

input[type="file"] {
    padding: 0.55rem 0.75rem;
    cursor: pointer;
}

input[type="file"]::file-selector-button {
    font-family: 'Bricolage Grotesque', sans-serif;
    font-weight: 600;
    font-size: 0.8rem;
    background: var(--brand-light);
    color: var(--brand);
    border: 1.5px solid rgba(255, 107, 53, 0.25);
    border-radius: 6px;
    padding: 0.35rem 0.75rem;
    cursor: pointer;
    margin-right: 0.75rem;
    transition: all 0.15s ease;
}

input[type="file"]::file-selector-button:hover {
    background: var(--brand);
    color: #fff;
}

/* ─── Payroll ──────────────────────────────────────── */

.payroll-workspace,
.payroll-detail {
    display: grid;
    gap: 1.25rem;
}

.payroll-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
    gap: 1rem;
    align-items: stretch;
}

.payroll-filter-form,
.payroll-generate-form {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 1rem;
    display: flex;
    align-items: end;
    gap: 0.75rem;
}

.payroll-filter-form .form-group,
.payroll-generate-form .form-group {
    margin-bottom: 0;
}

.payroll-filter-form .form-group {
    min-width: 180px;
}

.payroll-generate-form {
    justify-content: flex-end;
}

.payroll-table-wrap {
    padding: 0;
    overflow-x: auto;
}

.payroll-table {
    min-width: 760px;
}

.table-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.35rem;
}

.payroll-status {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.65rem;
    border-radius: var(--r-full);
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.payroll-status.paid { background: var(--green-bg); color: var(--green); }
.payroll-status.due { background: var(--blue-bg); color: var(--blue); }
.payroll-status.overdue { background: var(--red-bg); color: var(--red); }
.payroll-status.cancelled { background: #f0ede8; color: #777; }

.payroll-detail-band {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.payroll-detail-band h2 {
    font-family: 'Gabarito', sans-serif;
    font-size: 1.35rem;
    margin-top: 0.45rem;
}

.payroll-detail-band p,
.payroll-amount-block span,
.payroll-notes {
    color: var(--text-secondary);
}

.payroll-amount-block {
    text-align: right;
}

.payroll-amount-block strong {
    display: block;
    font-family: 'Gabarito', sans-serif;
    font-size: 1.55rem;
    color: var(--text);
}

.payroll-notes {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-light);
}

.payroll-cancel-form {
    display: flex;
    justify-content: flex-end;
}

.payroll-cancel-form .btn {
    color: var(--red);
    border-color: #fecaca;
}

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

.document-actions {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.document-actions form {
    margin: 0;
}

.legal-document {
    max-width: 880px;
    margin: 0 auto;
    background: #fff;
    border: 1px solid #ded7ce;
    border-radius: var(--r-sm);
    padding: 3rem 3.25rem;
    box-shadow: 0 12px 40px rgba(45, 36, 28, 0.10);
    color: #17130f;
    font-family: Georgia, 'Times New Roman', serif;
    line-height: 1.68;
    position: relative;
}

.legal-letterhead {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 2rem;
    padding-bottom: 1.35rem;
    margin-bottom: 1.55rem;
    border-bottom: 3px solid #17130f;
}

.legal-brand-lockup {
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

.legal-brand-mark {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    background: var(--brand);
    color: #fff;
    border-radius: 6px;
    box-shadow: 0 8px 18px rgba(255, 107, 53, 0.24);
}

.legal-brand-name {
    font-family: 'Gabarito', sans-serif;
    font-size: 2.55rem;
    line-height: 0.95;
    font-weight: 900;
    color: #17130f;
}

.legal-brand-subtitle,
.legal-letterhead-meta,
.legal-document-title span {
    font-family: 'Gabarito', sans-serif;
    color: #766d63;
}

.legal-brand-subtitle {
    margin-top: 0.35rem;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.legal-letterhead-meta {
    text-align: right;
    font-size: 0.86rem;
    line-height: 1.45;
}

.legal-letterhead-meta strong,
.legal-letterhead-meta span {
    display: block;
}

.legal-letterhead-meta strong {
    color: #17130f;
    font-weight: 800;
}

.legal-document-title {
    margin-bottom: 1.8rem;
}

.legal-document-title span {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.16em;
}

.legal-document h1,
.legal-document h2 {
    font-family: 'Gabarito', sans-serif;
    color: #17130f;
}

.legal-document h1 {
    font-size: 2.05rem;
    line-height: 1.1;
    font-weight: 900;
}

.legal-section {
    break-inside: avoid;
    margin-top: 1.35rem;
    padding-top: 1rem;
    border-top: 1px solid #eee8df;
}

.legal-section-intro {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
}

.legal-section h2 {
    font-size: 1rem;
    line-height: 1.2;
    font-weight: 800;
    margin-bottom: 0.7rem;
}

.legal-section-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.legal-section-body p {
    margin: 0;
}

.legal-section-intro .legal-field-grid > p,
.legal-section-intro .legal-field-grid > .legal-signature-heading,
.legal-section-intro .legal-field-grid > .legal-signature-line,
.legal-section-intro .legal-field-grid > .legal-signature-name {
    grid-column: 1 / -1;
}

.legal-section-intro .legal-field-grid > p {
    margin: 0.25rem 0;
}

.legal-field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.7rem 0.9rem;
}

.legal-field {
    display: grid;
    grid-template-columns: minmax(130px, 0.42fr) minmax(0, 1fr);
    gap: 0.85rem;
    align-items: start;
    margin: 0;
}

.legal-section-intro .legal-field {
    display: block;
    padding: 0.8rem 0.9rem;
    background: #fbfaf8;
    border: 1px solid #eee8df;
    border-radius: 6px;
}

.legal-field dt {
    font-family: 'Gabarito', sans-serif;
    font-size: 0.73rem;
    line-height: 1.25;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: #8a7f73;
}

.legal-field dd {
    min-width: 0;
    color: #17130f;
    overflow-wrap: anywhere;
}

.legal-section-intro .legal-field dd {
    margin-top: 0.22rem;
}

.legal-signature-heading {
    font-family: 'Gabarito', sans-serif;
    font-weight: 800;
    margin-top: 0.85rem !important;
}

.legal-signature-line {
    display: grid;
    grid-template-columns: 90px minmax(220px, 1fr);
    align-items: end;
    gap: 0.75rem;
    max-width: 430px;
    margin: 0.25rem 0 0.9rem;
    font-family: 'Gabarito', sans-serif;
    font-weight: 700;
    color: #5f574f;
}

.legal-signature-line b {
    display: block;
    height: 1.4rem;
    border-bottom: 1.5px solid #17130f;
}

.legal-signature-name {
    display: grid;
    grid-template-columns: 90px minmax(220px, 1fr);
    gap: 0.75rem;
    max-width: 430px;
    font-family: 'Gabarito', sans-serif;
    color: #5f574f;
}

.legal-signature-name span {
    font-weight: 700;
}

.legal-signature-name strong {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1rem;
    font-weight: 400;
    color: #17130f;
}

@media (max-width: 760px) {
    .legal-document {
        padding: 1.5rem;
    }

    .legal-field,
    .legal-field-grid,
    .legal-signature-line,
    .legal-signature-name {
        grid-template-columns: 1fr;
    }

    .legal-letterhead {
        flex-direction: column;
        gap: 1rem;
    }

    .legal-letterhead-meta {
        text-align: left;
    }

    .legal-brand-name {
        font-size: 2.1rem;
    }
}

@media print {
    @page {
        size: A4 portrait;
        margin: 18mm;
    }

    html,
    body {
        background: #fff !important;
        width: auto !important;
        min-width: 0 !important;
    }

    .sidebar,
    .topbar,
    .topbar-menu-btn,
    .flash-messages,
    .print-actions {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
    }

    .content {
        padding: 0 !important;
        animation: none !important;
        overflow: visible !important;
    }

    .legal-document {
        border: 0;
        box-shadow: none;
        padding: 0;
        margin: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 0;
        font-size: 10.5pt;
        line-height: 1.42;
        overflow: visible !important;
        break-before: auto;
        break-after: auto;
    }

    .legal-letterhead {
        gap: 10mm;
        padding-bottom: 5mm;
        margin-bottom: 5mm;
        border-bottom-width: 1.5pt;
    }

    .legal-brand-mark {
        width: 30px;
        height: 30px;
        border-radius: 4px;
        box-shadow: none;
    }

    .legal-brand-name {
        font-size: 22pt;
        line-height: 1;
    }

    .legal-brand-subtitle,
    .legal-letterhead-meta,
    .legal-document-title span,
    .legal-field dt {
        letter-spacing: 0.08em;
    }

    .legal-brand-subtitle,
    .legal-document-title span,
    .legal-field dt {
        font-size: 7.5pt;
    }

    .legal-letterhead-meta {
        font-size: 8.5pt;
    }

    .legal-document-title {
        margin-bottom: 5mm;
    }

    .legal-document h1 {
        font-size: 18pt;
        line-height: 1.1;
    }

    .legal-section {
        break-inside: auto;
        page-break-inside: auto;
        margin-top: 4mm;
        padding-top: 3mm;
    }

    .legal-section h2 {
        font-size: 10pt;
        margin-bottom: 2.5mm;
        break-after: avoid;
        page-break-after: avoid;
    }

    .legal-section-body {
        gap: 2.5mm;
    }

    .legal-field-grid {
        grid-template-columns: 1fr;
        gap: 2.5mm;
    }

    .legal-field {
        grid-template-columns: 34mm minmax(0, 1fr);
        gap: 4mm;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .legal-section-intro .legal-field {
        padding: 2.5mm 3mm;
        border-radius: 3px;
        background: #fff;
    }

    .legal-section-body p,
    .legal-section-intro .legal-field-grid > p {
        margin: 0 0 2.5mm;
        widows: 3;
        orphans: 3;
    }

    .legal-signature-heading {
        margin-top: 4mm !important;
    }

    .legal-signature-line,
    .legal-signature-name {
        grid-template-columns: 26mm minmax(55mm, 1fr);
        max-width: 95mm;
        gap: 4mm;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .legal-signature-line {
        margin: 1mm 0 3mm;
    }

    .legal-signature-line b {
        height: 7mm;
    }
}

/* ─── Employees ─────────────────────────────────────── */

.employees-table td:first-child {
    min-width: 180px;
}

.employee-form,
.employee-dossier {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.employee-form-grid,
.document-upload-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem 1.15rem;
}

.employee-form-grid .form-group,
.document-upload-form .form-group {
    margin-bottom: 0;
}

.form-span {
    grid-column: 1 / -1;
}

.employee-dossier-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
    gap: 1.25rem;
    align-items: start;
}

.employee-save {
    max-width: 420px;
    align-self: flex-end;
    padding: 0.85rem 1rem;
}

.employee-profile-band {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    gap: 1rem;
    align-items: center;
    padding: 1.15rem;
    background:
        linear-gradient(135deg, rgba(255,107,53,0.08), transparent 38%),
        var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
}

.employee-avatar {
    width: 58px;
    height: 58px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: var(--bg-sidebar);
    color: #fff;
    font-family: 'Gabarito', sans-serif;
    font-size: 1.7rem;
    font-weight: 800;
    box-shadow: inset 0 -3px 0 rgba(255,255,255,0.1);
}

.employee-kicker {
    color: var(--brand);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.employee-profile-band h2 {
    font-family: 'Gabarito', sans-serif;
    font-size: 1.55rem;
    line-height: 1.15;
    margin: 0.08rem 0;
}

.employee-profile-band p {
    color: var(--text-secondary);
    margin: 0;
}

.employee-profile-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.employee-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.9rem 1rem;
}

.employee-facts div {
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-light);
}

.employee-facts dt {
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.employee-facts dd {
    margin-top: 0.25rem;
    color: var(--text);
    font-weight: 600;
    word-break: break-word;
}

.retention-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.retention-list li {
    display: grid;
    grid-template-columns: 22px 1fr;
    gap: 0.7rem;
    align-items: start;
    color: var(--text-secondary);
    padding: 0.72rem;
    background: var(--bg-inset);
    border: 1px solid var(--border-light);
    border-radius: var(--r-sm);
}

.retention-list li i {
    color: var(--text-muted);
    margin-top: 0.18rem;
}

.retention-list li.complete {
    background: var(--green-bg);
    border-color: rgba(34,160,107,0.16);
}

.retention-list li.complete i {
    color: var(--green);
}

.retention-list strong {
    display: block;
    color: var(--text);
}

.doc-cabinet {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 0.9rem;
}

.doc-tile {
    min-height: 138px;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: linear-gradient(180deg, #fff, var(--bg-inset));
    color: var(--text-secondary);
    transition: transform 0.18s var(--ease), border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}

.doc-tile:hover {
    transform: translateY(-2px);
    border-color: rgba(255,107,53,0.35);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
}

.doc-tile i {
    color: var(--brand);
    font-size: 1.35rem;
}

.doc-tile strong {
    color: var(--text);
    line-height: 1.25;
}

.doc-tile span {
    font-size: 0.82rem;
    overflow-wrap: anywhere;
}

.doc-tile small {
    margin-top: auto;
    color: var(--text-muted);
    font-weight: 700;
}

/* ─── Invoice table (backfill page) ─────────────────── */

.invoice-table {
    width: 100%;
    border-collapse: collapse;
}

.invoice-table th {
    padding: 0.8rem 1.25rem;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    background: var(--bg-inset);
    border-bottom: 2px solid var(--border);
}

.invoice-table td {
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.invoice-table tbody tr:hover {
    background: var(--bg-inset);
}

.invoice-table a {
    color: var(--brand);
    font-weight: 600;
}

.invoice-table a:hover {
    text-decoration: underline;
}

/* ─── Expenses page ─────────────────────────────────── */

.expenses-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.expenses-toolbar .toolbar-left {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    flex-wrap: wrap;
}

.expenses-toolbar .year-filter select {
    padding: 0.55rem 2.2rem 0.55rem 0.9rem;
    font-size: 0.9rem;
    font-weight: 600;
    border: 1.5px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%23999' d='M6 8.5 1.5 4h9z'/></svg>");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.expenses-toolbar .year-filter select:hover {
    border-color: var(--text-muted);
}

.expenses-toolbar .year-filter select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-glow);
}

.expenses-card {
    overflow: hidden;
}

.expenses-card .table-wrap {
    overflow-x: auto;
    overflow-y: hidden;
}

.expenses-table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.expenses-table th,
.expenses-table td {
    padding: 0.7rem 0.85rem;
    font-size: 0.88rem;
    vertical-align: middle;
    white-space: nowrap;
}

.expenses-table th {
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    background: var(--bg-inset);
    border-bottom: 2px solid var(--border);
}

.expenses-table td {
    border-bottom: 1px solid var(--border-light);
    color: var(--text-secondary);
}

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

.expenses-table tbody tr:hover {
    background: var(--bg-inset);
}

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

.expenses-table th.num,
.expenses-table td.num {
    text-align: right;
}

.expenses-table .col-date {
    color: var(--text-muted);
    font-size: 0.82rem;
    padding-left: 1.25rem;
}

.expenses-table .col-desc {
    max-width: 260px;
    white-space: normal;
}

.expenses-table .col-desc .expense-link {
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
    border-bottom: 1px dashed transparent;
    transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.expenses-table .col-desc .expense-link:hover {
    color: var(--brand);
    border-bottom-color: var(--brand);
}

.expenses-table .col-provider {
    color: var(--text);
    font-weight: 500;
}

.expenses-table .fx-pair .fx-cur {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    margin-right: 0.2rem;
}

.expenses-table td.charges {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.expenses-table td.total {
    color: var(--text);
    font-weight: 700;
}

.expenses-table .muted-dash {
    color: var(--border);
}

.expenses-table .itc-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.18rem 0.55rem;
    border-radius: var(--r-full);
    background: var(--green-bg);
    color: var(--green);
    font-size: 0.78rem;
    font-weight: 700;
}

.expenses-table .itc-pill i {
    font-size: 0.72rem;
}

.expenses-table .col-actions {
    width: 1%;
    padding-right: 1rem;
}

.expenses-table .row-actions {
    display: inline-flex;
    gap: 0.15rem;
    opacity: 0.55;
    transition: opacity 0.15s var(--ease);
}

.expenses-table tbody tr:hover .row-actions {
    opacity: 1;
}

.icon-btn {
    width: 1.9rem;
    height: 1.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    font-size: 0.82rem;
    transition: all 0.15s var(--ease);
    text-decoration: none;
}

.icon-btn:hover {
    color: var(--brand);
    background: var(--brand-light);
    border-color: var(--brand-light);
}

.expenses-table .badge-draft {
    font-size: 0.66rem;
    padding: 0.2rem 0.55rem;
}

/* ─── Scrollbar ─────────────────────────────────────── */

::-webkit-scrollbar {
    width: 7px;
    height: 7px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #ccc;
}

/* ─── Mobile sidebar controls ───────────────────────── */

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s var(--ease);
}
.sidebar-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}

.topbar-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    cursor: pointer;
    color: var(--text);
    font-size: 1rem;
    transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
    flex-shrink: 0;
}
.topbar-menu-btn:hover {
    background: var(--bg-inset);
    border-color: var(--brand);
}

/* ─── Responsive ────────────────────────────────────── */

@media (max-width: 1024px) {
    .dashboard-sections {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    /* Belt-and-suspenders: stop the page itself from ever scrolling
       horizontally. Wide children scroll inside their own container. */
    html, body { overflow-x: hidden; max-width: 100vw; }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s var(--ease);
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.35);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
        max-width: 100vw;
    }
    .content { max-width: 100%; }
    .card { max-width: 100%; }

    .topbar-menu-btn { display: inline-flex; }
    .topbar {
        padding: 0 1rem;
        gap: 0.6rem;
        height: 64px;
    }
    .topbar-title h1 {
        font-size: 1.2rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .content {
        padding: 1.25rem 1rem 2rem;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }
    .stat-card {
        padding: 1rem;
        gap: 0.75rem;
    }
    .stat-icon {
        width: 38px; height: 38px;
        font-size: 0.9rem;
    }
    .stat-value { font-size: 1.4rem !important; }
    .stat-details h3 { font-size: 0.7rem; }

    /* Cards: tighter padding, header may stack */
    .card-header {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.9rem 1rem;
    }
    .card-header h2 {
        font-size: 1rem;
    }
    .card-body { padding: 1rem; }
    /* When a table is inside a card-body, allow horizontal scroll. */
    .card-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    .table th, .table td {
        padding: 0.7rem 0.6rem;
        font-size: 0.85rem;
    }
    .table { min-width: 600px; }

    .employee-dossier-grid,
    .employee-form-grid,
    .document-upload-form {
        grid-template-columns: 1fr;
    }

    .employee-profile-band {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .employee-profile-band > .badge,
    .employee-profile-actions {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }

    .employee-facts {
        grid-template-columns: 1fr;
    }

    .employee-save {
        max-width: none;
        align-self: stretch;
    }

    .btn { padding: 0.6rem 0.85rem; font-size: 0.875rem; }
    .btn-sm { padding: 0.35rem 0.55rem; font-size: 0.78rem; }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .topbar { padding: 0 0.85rem; height: 60px; }
    .topbar-title h1 { font-size: 1.1rem; }
    .content { padding: 1rem 0.85rem 2rem; }
    .card-header { padding: 0.8rem 0.85rem; }
    .card-body { padding: 0.85rem; }
    .stat-value { font-size: 1.25rem !important; }
}

@media print {
    body { background: #ffffff !important; color: #1a1a1a !important; }
}
