/* =================================================================
   J.M.K Groupe — Business Management System
   Design system for the authenticated application.

   Visual direction: trustworthy, premium, financially professional.
   Restrained colour, generous spacing, strong focus states, no
   decorative gradients or glassmorphism.

   Brand colours are inherited from the public J.M.K Groupe site
   (deep navy + blue/violet accent) so the two feel related without
   the app looking like a marketing page.
   ================================================================= */

/* ---------- Design tokens ---------- */
:root {
    /* Brand */
    --navy-900: #0b1f3a;
    --navy-800: #12294b;
    --navy-700: #1c3a63;
    --navy-600: #294b7c;

    --blue-700: #1d4ed8;
    --blue-600: #2563eb;
    --blue-500: #3b82f6;
    --blue-100: #dbeafe;
    --blue-50:  #eff6ff;

    --violet-500: #8b5cf6;

    /* Neutrals */
    --ink:        #101828;
    --ink-soft:   #344054;
    --muted:      #667085;
    --muted-soft: #98a2b3;
    --line:       #e4e7ec;
    --line-soft:  #f0f2f5;
    --surface:    #ffffff;
    --canvas:     #f7f8fa;
    --canvas-alt: #fbfcfd;

    /* Status */
    --success-700: #027a48;
    --success-100: #d1fadf;
    --success-50:  #ecfdf3;
    --warning-700: #b54708;
    --warning-100: #fef0c7;
    --warning-50:  #fffaeb;
    --danger-700:  #b42318;
    --danger-100:  #fee4e2;
    --danger-50:   #fef3f2;
    --info-700:    #175cd3;

    /* Typography */
    --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI',
            Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;

    /* Radii */
    --r-xs: 6px;
    --r-sm: 8px;
    --r-md: 10px;
    --r-lg: 14px;
    --r-xl: 18px;
    --r-pill: 999px;

    /* Shadows — subtle, never decorative */
    --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, .1), 0 1px 2px rgba(16, 24, 40, .06);
    --shadow-md: 0 4px 8px -2px rgba(16, 24, 40, .1), 0 2px 4px -2px rgba(16, 24, 40, .06);
    --shadow-lg: 0 12px 16px -4px rgba(16, 24, 40, .08), 0 4px 6px -2px rgba(16, 24, 40, .03);

    /* Layout */
    --sidebar-w: 264px;
    --topbar-h: 64px;
    --page-max: 1360px;
    --gutter: 24px;

    --focus-ring: 0 0 0 3px rgba(37, 99, 235, .35);
}

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

html {
    -webkit-text-size-adjust: 100%;
    height: 100%;
}

body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--canvas);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100%;
    /* Guarantees the "no horizontal scrolling on mobile" requirement. */
    overflow-x: hidden;
}

img, svg { max-width: 100%; display: block; }
a { color: var(--blue-700); text-decoration: none; }
a:hover { text-decoration: underline; }
ul, ol { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }

h1, h2, h3, h4 {
    line-height: 1.25;
    font-weight: 700;
    letter-spacing: -0.015em;
    color: var(--ink);
}

/* Application headings stay restrained — this is a work tool, not a
   landing page. */
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

/* ---------- Focus visibility ---------- */
:focus-visible {
    outline: 2px solid var(--blue-600);
    outline-offset: 2px;
    border-radius: var(--r-xs);
}

/* Remove the default ring only where a custom one is provided. */
.btn:focus-visible,
.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
    outline: 2px solid transparent;
    outline-offset: 0;
    box-shadow: var(--focus-ring);
    border-color: var(--blue-600);
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 999;
    background: var(--navy-900);
    color: #fff;
    padding: 12px 20px;
    border-radius: 0 0 var(--r-sm) 0;
    font-weight: 600;
}
.skip-link:focus { left: 0; text-decoration: none; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}

/* =================================================================
   Application shell
   ================================================================= */

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

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--navy-900);
    color: #cfd8e6;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--topbar-h);
    padding: 0 20px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    flex-shrink: 0;
}

.sidebar__mark {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--blue-500), var(--violet-500));
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 800;
    font-size: .72rem;
    letter-spacing: .02em;
    flex-shrink: 0;
}

.sidebar__name {
    color: #fff;
    font-weight: 700;
    font-size: .95rem;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar__nav {
    padding: 16px 12px;
    overflow-y: auto;
    flex: 1;
}

.sidebar__section {
    padding: 16px 10px 6px;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #6b7f9c;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 11px;
    border-radius: var(--r-sm);
    color: #cfd8e6;
    font-weight: 500;
    font-size: .9rem;
    transition: background-color .15s ease, color .15s ease;
}

.nav-link:hover {
    background: rgba(255, 255, 255, .07);
    color: #fff;
    text-decoration: none;
}

.nav-link[aria-current="page"] {
    background: var(--blue-600);
    color: #fff;
    font-weight: 600;
}

.nav-link__icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sidebar__footer {
    padding: 14px 16px;
    border-top: 1px solid rgba(255, 255, 255, .08);
    font-size: .72rem;
    color: #6b7f9c;
    flex-shrink: 0;
}

/* ---------- Main column ---------- */
.app-main {
    flex: 1;
    min-width: 0;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
}

/* ---------- Top bar ---------- */
.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 var(--gutter);
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar__toggle {
    display: none;
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--surface);
    cursor: pointer;
    place-items: center;
    flex-shrink: 0;
}

.topbar__spacer { flex: 1; min-width: 0; }

/* ---------- Business selector ---------- */
.biz-selector { position: relative; min-width: 0; }

.biz-selector__label {
    display: block;
    font-size: .66rem;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 3px;
}

.biz-selector__row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.biz-selector__select {
    appearance: none;
    -webkit-appearance: none;
    background: var(--canvas)
        url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6.5 8 10.5l4-4' fill='none' stroke='%23667085' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
        no-repeat right 10px center / 15px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    padding: 7px 34px 7px 11px;
    font-size: .875rem;
    font-weight: 600;
    color: var(--ink);
    max-width: 260px;
    min-width: 0;
    text-overflow: ellipsis;
    cursor: pointer;
}

/* The current scope must be unmistakable at a glance. */
.biz-selector__badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 9px;
    border-radius: var(--r-pill);
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .02em;
    white-space: nowrap;
}

.biz-selector__badge--all {
    background: var(--blue-50);
    color: var(--blue-700);
    border: 1px solid var(--blue-100);
}

.biz-selector__badge--one {
    background: var(--success-50);
    color: var(--success-700);
    border: 1px solid var(--success-100);
}

.biz-selector__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

/* ---------- User menu ---------- */
.usermenu { position: relative; flex-shrink: 0; }

.usermenu__trigger {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 5px 9px 5px 5px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--r-pill);
    cursor: pointer;
}

.usermenu__trigger:hover { background: var(--canvas); border-color: var(--line); }

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--navy-700), var(--blue-600));
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: .8rem;
    flex-shrink: 0;
}

.usermenu__meta { text-align: left; line-height: 1.25; min-width: 0; }
.usermenu__name {
    font-size: .85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}
.usermenu__role { font-size: .7rem; color: var(--muted); text-transform: capitalize; }

.usermenu__panel {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 230px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    z-index: 50;
}

.usermenu__panel[hidden] { display: none; }

.usermenu__header {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line-soft);
    margin-bottom: 4px;
}

.usermenu__email {
    font-size: .78rem;
    color: var(--muted);
    word-break: break-all;
}

.usermenu__item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 9px 12px;
    border-radius: var(--r-sm);
    font-size: .875rem;
    color: var(--ink-soft);
    background: none;
    border: 0;
    text-align: left;
    cursor: pointer;
}

.usermenu__item:hover { background: var(--canvas); text-decoration: none; }
.usermenu__item--danger { color: var(--danger-700); }

/* ---------- Page area ---------- */
.page {
    padding: 26px var(--gutter) 56px;
    width: 100%;
    max-width: var(--page-max);
    margin-inline: auto;
    flex: 1;
}

.page__header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

.page__heading { min-width: 0; }
.page__title { font-size: 1.5rem; }
.page__subtitle { color: var(--muted); font-size: .9rem; margin-top: 4px; }
.page__actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Breadcrumbs ---------- */
.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: .8rem;
    color: var(--muted);
    margin-bottom: 8px;
}

.breadcrumbs a { color: var(--muted); }
.breadcrumbs a:hover { color: var(--blue-700); }
.breadcrumbs__sep { color: var(--muted-soft); }
.breadcrumbs [aria-current="page"] { color: var(--ink-soft); font-weight: 600; }

/* =================================================================
   Components
   ================================================================= */

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-xs);
}

.card__header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--line-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.card__title { font-size: .95rem; font-weight: 700; }
.card__hint { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.card__body { padding: 20px; }
.card__footer {
    padding: 14px 20px;
    border-top: 1px solid var(--line-soft);
    background: var(--canvas-alt);
    border-radius: 0 0 var(--r-lg) var(--r-lg);
}

/* ---------- Grid ---------- */
.grid { display: grid; gap: 16px; }
.grid--kpi { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid--cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stack { display: grid; gap: 16px; }
.stack--lg { gap: 24px; }

/* ---------- KPI cards ---------- */
.kpi {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 18px;
    box-shadow: var(--shadow-xs);
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.kpi__label {
    font-size: .78rem;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: .01em;
}

.kpi__value {
    font-size: 1.65rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

/* An empty KPI must read as "no data", never as a zero balance. */
.kpi__value--empty { color: var(--muted-soft); font-weight: 600; }

.kpi__note {
    font-size: .75rem;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: auto;
    padding-top: 6px;
}

.kpi__note svg { width: 13px; height: 13px; flex-shrink: 0; }

/* ---------- Stat row ---------- */
.stat {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.stat__number {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
}

.stat__unit { font-size: .85rem; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 16px;
    border-radius: var(--r-sm);
    border: 1px solid transparent;
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
    white-space: nowrap;
    text-decoration: none;
    /* Comfortable touch target on mobile. */
    min-height: 40px;
}

.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn--primary { background: var(--blue-600); color: #fff; border-color: var(--blue-600); }
.btn--primary:hover { background: var(--blue-700); border-color: var(--blue-700); }

.btn--secondary { background: var(--surface); color: var(--ink-soft); border-color: var(--line); }
.btn--secondary:hover { background: var(--canvas); border-color: var(--muted-soft); }

.btn--subtle { background: var(--canvas); color: var(--ink-soft); border-color: transparent; }
.btn--subtle:hover { background: var(--line-soft); }

.btn--danger { background: var(--surface); color: var(--danger-700); border-color: var(--danger-100); }
.btn--danger:hover { background: var(--danger-50); border-color: var(--danger-700); }

.btn--block { width: 100%; }
.btn--sm { padding: 6px 12px; font-size: .8rem; min-height: 34px; }
.btn--lg { padding: 12px 20px; font-size: .95rem; min-height: 46px; }

.btn__icon { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.8; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: var(--r-pill);
    font-size: .72rem;
    font-weight: 600;
    white-space: nowrap;
    border: 1px solid transparent;
}

.badge--success { background: var(--success-50); color: var(--success-700); border-color: var(--success-100); }
.badge--warning { background: var(--warning-50); color: var(--warning-700); border-color: var(--warning-100); }
.badge--danger  { background: var(--danger-50);  color: var(--danger-700);  border-color: var(--danger-100); }
.badge--info    { background: var(--blue-50);    color: var(--blue-700);    border-color: var(--blue-100); }
.badge--muted   { background: var(--line-soft);  color: var(--muted);       border-color: var(--line); }

.badge__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- Forms ---------- */
.form-grid { display: grid; gap: 18px; }
.form-grid--2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.field__label {
    font-size: .82rem;
    font-weight: 600;
    color: var(--ink-soft);
}

.field__optional { color: var(--muted-soft); font-weight: 500; }

.field__hint { font-size: .76rem; color: var(--muted); }

.input, .select, .textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--surface);
    font-size: .9rem;
    color: var(--ink);
    transition: border-color .15s ease, box-shadow .15s ease;
    /* 16px on mobile prevents iOS zoom-on-focus. */
    min-height: 42px;
}

.textarea { min-height: 96px; resize: vertical; }

.input::placeholder { color: var(--muted-soft); }

.input[aria-invalid="true"],
.select[aria-invalid="true"],
.textarea[aria-invalid="true"] {
    border-color: var(--danger-700);
}

.input:disabled, .select:disabled {
    background: var(--canvas);
    color: var(--muted);
    cursor: not-allowed;
}

.select {
    appearance: none;
    -webkit-appearance: none;
    background: var(--surface)
        url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6.5 8 10.5l4-4' fill='none' stroke='%23667085' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
        no-repeat right 11px center / 15px;
    padding-right: 34px;
    cursor: pointer;
}

.input-group { display: flex; align-items: stretch; }
.input-group__prefix {
    display: inline-flex;
    align-items: center;
    padding: 0 11px;
    background: var(--canvas);
    border: 1px solid var(--line);
    border-right: 0;
    border-radius: var(--r-sm) 0 0 var(--r-sm);
    font-size: .82rem;
    color: var(--muted);
    white-space: nowrap;
}
.input-group .input { border-radius: 0 var(--r-sm) var(--r-sm) 0; }

.field-error {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: .78rem;
    color: var(--danger-700);
    font-weight: 500;
}

.field-error__icon { width: 14px; height: 14px; flex-shrink: 0; margin-top: 2px; }

.form-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

fieldset { border: 0; padding: 0; min-width: 0; }
legend { padding: 0; font-weight: 700; font-size: .95rem; margin-bottom: 4px; }

/* ---------- Alerts / flash ---------- */
.flash-stack { display: grid; gap: 10px; margin-bottom: 20px; }

.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--r-md);
    border: 1px solid transparent;
    font-size: .875rem;
}

.alert__icon { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.alert__body { min-width: 0; }

.alert--success { background: var(--success-50); border-color: var(--success-100); color: var(--success-700); }
.alert--error   { background: var(--danger-50);  border-color: var(--danger-100);  color: var(--danger-700); }
.alert--warning { background: var(--warning-50); border-color: var(--warning-100); color: var(--warning-700); }
.alert--info    { background: var(--blue-50);    border-color: var(--blue-100);    color: var(--blue-700); }

/* ---------- Tables ---------- */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

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

.table th {
    text-align: left;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 11px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--canvas-alt);
    white-space: nowrap;
}

.table td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--canvas-alt); }

.table__primary { font-weight: 600; color: var(--ink); }
.table__meta { font-size: .78rem; color: var(--muted); }
.table__actions { text-align: right; white-space: nowrap; }
.table__num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Empty states ---------- */
.empty {
    text-align: center;
    padding: 44px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.empty__icon {
    width: 46px;
    height: 46px;
    border-radius: 13px;
    background: var(--canvas);
    border: 1px solid var(--line);
    display: grid;
    place-items: center;
    color: var(--muted-soft);
    margin-bottom: 2px;
}

.empty__icon svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.5; }
.empty__title { font-weight: 700; font-size: .95rem; }
.empty__text { color: var(--muted); font-size: .86rem; max-width: 46ch; }

/* Placeholder for charts introduced in a later phase. No chart library
   is loaded and no data is fabricated. */
.chart-placeholder {
    min-height: 200px;
    border: 1px dashed var(--line);
    border-radius: var(--r-md);
    background: var(--canvas-alt);
    display: grid;
    place-items: center;
    text-align: center;
    padding: 24px;
    color: var(--muted);
    font-size: .84rem;
}

/* ---------- Definition list ---------- */
.detail-list { display: grid; gap: 0; }

.detail-list__row {
    display: grid;
    grid-template-columns: minmax(140px, 32%) 1fr;
    gap: 16px;
    padding: 11px 0;
    border-bottom: 1px solid var(--line-soft);
}

.detail-list__row:last-child { border-bottom: 0; }
.detail-list__key { font-size: .82rem; color: var(--muted); font-weight: 500; }
.detail-list__value { font-size: .88rem; color: var(--ink); word-break: break-word; }
.detail-list__value--empty { color: var(--muted-soft); }

/* ---------- Activity feed ---------- */
.activity { display: grid; gap: 2px; }

.activity__item {
    display: flex;
    gap: 12px;
    padding: 11px 0;
    border-bottom: 1px solid var(--line-soft);
    align-items: flex-start;
}

.activity__item:last-child { border-bottom: 0; }

.activity__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 7px;
}

.activity__dot--success { background: var(--success-700); }
.activity__dot--warning { background: var(--warning-700); }
.activity__dot--info    { background: var(--blue-600); }
.activity__dot--muted   { background: var(--muted-soft); }

.activity__body { min-width: 0; flex: 1; }
.activity__title { font-size: .86rem; font-weight: 600; }
.activity__meta { font-size: .76rem; color: var(--muted); margin-top: 1px; }

/* ---------- Tabs ---------- */
.tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 22px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tabs__link {
    padding: 10px 16px;
    font-size: .875rem;
    font-weight: 600;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    margin-bottom: -1px;
}

.tabs__link:hover { color: var(--ink-soft); text-decoration: none; }

.tabs__link[aria-current="page"] {
    color: var(--blue-700);
    border-bottom-color: var(--blue-600);
}

/* ---------- Filter bar ---------- */
.filterbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    margin-bottom: 18px;
}

.filterbar .field { flex: 0 1 200px; }
.filterbar__search { flex: 1 1 260px; }

/* ---------- Pagination ---------- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding-top: 16px;
}

.pagination__info { font-size: .82rem; color: var(--muted); }
.pagination__links { display: flex; gap: 8px; }

/* ---------- Misc ---------- */
.muted { color: var(--muted); }
.text-sm { font-size: .82rem; }
.mono { font-family: var(--font-mono); font-size: .82rem; }
.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.divider { height: 1px; background: var(--line); border: 0; margin: 4px 0; }
.divider--spaced { margin: 16px 0; }

/* ---------- Utilities ----------
   The Content-Security-Policy forbids inline styles (style-src 'self'), so
   every one-off adjustment uses a class here rather than a style attribute.
   This keeps the CSP strict: no 'unsafe-inline' is needed anywhere. */
.u-center      { text-align: center; }
.u-upper       { text-transform: uppercase; }
.u-mt-xs       { margin-top: 6px; }
.u-mt-sm       { margin-top: 12px; }
.u-mt-md       { margin-top: 14px; }
.u-mb-xs       { margin-bottom: 6px; }
.u-mb-md       { margin-bottom: 20px; }
.u-mb-lg       { margin-bottom: 22px; }
.u-w-sm        { max-width: 220px; }
.u-w-md        { max-width: 420px; }

.callout {
    display: flex;
    gap: 10px;
    padding: 13px 15px;
    background: var(--blue-50);
    border: 1px solid var(--blue-100);
    border-radius: var(--r-md);
    font-size: .84rem;
    color: var(--blue-700);
}

.callout--neutral {
    background: var(--canvas);
    border-color: var(--line);
    color: var(--ink-soft);
}

.callout__icon { width: 17px; height: 17px; flex-shrink: 0; margin-top: 1px; }

/* =================================================================
   Auth pages (signed-out)
   ================================================================= */

.auth {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr;
    background: var(--canvas);
}

.auth__aside {
    display: none;
    background: var(--navy-900);
    color: #cfd8e6;
    padding: 48px;
    flex-direction: column;
    justify-content: space-between;
}

.auth__aside-brand { display: flex; align-items: center; gap: 12px; }
.auth__aside-name { color: #fff; font-weight: 700; font-size: 1.05rem; }

.auth__aside-headline {
    color: #fff;
    font-size: 1.7rem;
    line-height: 1.3;
    font-weight: 700;
    letter-spacing: -0.02em;
    max-width: 22ch;
}

.auth__aside-text { color: #93a5bf; font-size: .92rem; max-width: 40ch; margin-top: 12px; }

.auth__aside-points { display: grid; gap: 12px; margin-top: 28px; }
.auth__aside-point { display: flex; gap: 10px; align-items: flex-start; font-size: .88rem; color: #b6c4d8; }
.auth__aside-point svg { width: 17px; height: 17px; flex-shrink: 0; margin-top: 2px; color: var(--blue-500); }

.auth__aside-footer { font-size: .76rem; color: #6b7f9c; }

.auth__main {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 20px;
    min-height: 100vh;
}

.auth__card { width: 100%; max-width: 408px; }

.auth__brand {
    display: flex;
    align-items: center;
    gap: 11px;
    justify-content: center;
    margin-bottom: 26px;
}

.auth__brand-name { font-weight: 700; font-size: 1.05rem; color: var(--ink); }

.auth__panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-md);
    padding: 30px;
}

.auth__title { font-size: 1.3rem; margin-bottom: 5px; }
.auth__subtitle { color: var(--muted); font-size: .88rem; margin-bottom: 24px; }

.auth__form { display: grid; gap: 17px; }

.auth__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.auth__link { font-size: .82rem; font-weight: 600; }

.auth__note {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--line-soft);
    font-size: .78rem;
    color: var(--muted);
    text-align: center;
    line-height: 1.5;
}

.auth__footer { text-align: center; margin-top: 22px; font-size: .76rem; color: var(--muted); }

/* Password visibility toggle */
.password-field { position: relative; }
.password-field .input { padding-right: 46px; }

.password-toggle {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    background: none;
    border: 0;
    border-radius: var(--r-xs);
    color: var(--muted);
    cursor: pointer;
}

.password-toggle:hover { color: var(--ink-soft); background: var(--canvas); }
.password-toggle svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.6; }

/* =================================================================
   Error pages
   ================================================================= */

.errorpage {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px 20px;
    text-align: center;
}

.errorpage__inner { max-width: 470px; }

.errorpage__code {
    font-size: 3.2rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    color: var(--navy-900);
    line-height: 1;
}

.errorpage__title { font-size: 1.25rem; margin: 12px 0 8px; }
.errorpage__text { color: var(--muted); font-size: .92rem; margin-bottom: 24px; }

.errorpage__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.errorpage__ref {
    margin-top: 26px;
    font-size: .74rem;
    color: var(--muted-soft);
    font-family: var(--font-mono);
}

.errorpage__debug {
    margin-top: 26px;
    text-align: left;
    background: var(--ink);
    color: #e4e7ec;
    border-radius: var(--r-md);
    padding: 16px;
    font-family: var(--font-mono);
    font-size: .76rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

/* =================================================================
   Mobile drawer + responsive rules
   ================================================================= */

.drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, .5);
    z-index: 35;
}

body.drawer-open { overflow: hidden; }

/* ---------- >= 1024px: two-column auth ---------- */
@media (min-width: 1024px) {
    .auth { grid-template-columns: 1.05fr 1fr; }
    .auth__aside { display: flex; }
}

/* ---------- <= 1024px: sidebar becomes a drawer ---------- */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .22s ease;
        box-shadow: none;
    }

    .sidebar.is-open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .app-main { margin-left: 0; }

    .topbar__toggle { display: grid; }

    .drawer-backdrop.is-visible { display: block; }
}

/* ---------- <= 768px ---------- */
@media (max-width: 768px) {
    :root { --gutter: 16px; }

    .page { padding: 20px var(--gutter) 48px; }

    .page__header { flex-direction: column; align-items: stretch; }
    .page__actions .btn { flex: 1 1 auto; }

    .biz-selector__select { max-width: 170px; }
    .biz-selector__label { display: none; }

    .usermenu__meta { display: none; }

    .detail-list__row { grid-template-columns: 1fr; gap: 3px; padding: 10px 0; }

    /* Tables become stacked cards rather than scrolling sideways. */
    .table--stacked thead { display: none; }

    .table--stacked tbody tr {
        display: block;
        border: 1px solid var(--line);
        border-radius: var(--r-md);
        margin-bottom: 10px;
        background: var(--surface);
        padding: 4px 0;
    }

    .table--stacked tbody tr:hover { background: var(--surface); }

    .table--stacked td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 14px;
        padding: 9px 14px;
        border-bottom: 1px solid var(--line-soft);
        text-align: left;
    }

    .table--stacked td:last-child { border-bottom: 0; }

    /* The header text comes from each cell's data-label attribute. */
    .table--stacked td::before {
        content: attr(data-label);
        font-size: .72rem;
        font-weight: 700;
        letter-spacing: .04em;
        text-transform: uppercase;
        color: var(--muted);
        flex-shrink: 0;
    }

    .table--stacked td[data-label=""]::before { content: none; }
    .table--stacked .table__actions { justify-content: flex-end; }
}

/* ---------- <= 430px ---------- */
@media (max-width: 430px) {
    body { font-size: 14.5px; }

    .auth__panel { padding: 22px 18px; border-radius: var(--r-lg); }
    .auth__main { padding: 22px 14px; }

    .stat__number { font-size: 1.7rem; }
    .kpi__value { font-size: 1.45rem; }

    .form-actions { flex-direction: column; align-items: stretch; }
    .form-actions .btn { width: 100%; }

    .filterbar .field, .filterbar__search { flex: 1 1 100%; }
}

/* ---------- <= 360px (320px safety) ---------- */
@media (max-width: 360px) {
    :root { --gutter: 12px; }

    .topbar { gap: 8px; padding: 0 12px; }
    .biz-selector__select { max-width: 120px; font-size: .8rem; }
    .sidebar { width: min(86vw, var(--sidebar-w)); }
    .page__title { font-size: 1.3rem; }
    .errorpage__code { font-size: 2.6rem; }
}

/* ---------- Print ---------- */
@media print {
    .sidebar, .topbar, .page__actions, .drawer-backdrop { display: none !important; }
    .app-main { margin-left: 0; }
    body { background: #fff; }
    .card { box-shadow: none; border-color: #ccc; }
}
