/*
 * ConsicaMS Enterprise UI System
 * Presentation-only layer. It intentionally does not alter application logic,
 * routes, permissions, forms, APIs, database behavior, or business workflows.
 */

/* --------------------------------------------------------------------------
   Foundation
   -------------------------------------------------------------------------- */

:root {
    --content-gap: var(--space-5);
    --action-gap: 10px;
    --table-row-height: 52px;
}

html {
    scroll-behavior: smooth;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-size: var(--font-size-base);
    line-height: 1.55;
    background:
        radial-gradient(circle at 92% -10%, rgba(9, 89, 200, 0.07), transparent 28rem),
        var(--bg);
}

::selection {
    color: var(--primary-contrast);
    background: var(--primary);
}

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

:where(button, input, select, textarea) {
    font-family: var(--font);
}

:where(input, select, textarea)::placeholder {
    color: var(--text-muted);
    opacity: 0.72;
}

.skip-link {
    position: fixed;
    z-index: 1000;
    top: 10px;
    left: 12px;
    padding: 10px 14px;
    color: var(--primary-contrast);
    background: var(--primary);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    text-decoration: none;
    transform: translateY(-160%);
    transition: transform var(--duration) var(--ease-standard);
}

.skip-link:focus {
    transform: translateY(0);
}

.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.muted { color: var(--text-muted); }

.eyebrow {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .12em;
    line-height: 1.3;
    text-transform: uppercase;
}

/* --------------------------------------------------------------------------
   Application shell and navigation
   -------------------------------------------------------------------------- */

.app-sidebar {
    width: var(--sidebar-width);
    isolation: isolate;
    background:
        radial-gradient(circle at 20% 0%, rgba(52, 134, 255, .2), transparent 19rem),
        linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-deep) 100%);
    border-right-color: var(--sidebar-border);
    box-shadow: 18px 0 42px rgba(2, 12, 28, .08);
}

.app-sidebar::after {
    position: absolute;
    z-index: -1;
    inset: 0;
    content: '';
    pointer-events: none;
    background-image: linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px);
    background-size: 32px 32px;
    mask-image: linear-gradient(to bottom, black, transparent 72%);
}

.sidebar-brand {
    min-height: 86px;
    gap: 13px;
    padding: 20px 18px;
    border-bottom-color: var(--sidebar-border);
}

.sidebar-brand .brand-logo {
    width: 42px;
    height: 42px;
    padding: 5px;
    background: rgba(255,255,255,.96);
    border: 1px solid rgba(255,255,255,.22);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}

.sidebar-brand strong {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: -.01em;
}

.sidebar-brand small {
    margin-top: 3px;
    font-size: 11px;
    letter-spacing: .04em;
}

.sidebar-nav {
    padding: 12px 10px 18px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.16) transparent;
}

.sidebar-nav::-webkit-scrollbar { display: block; width: 5px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 999px; }

.nav-heading {
    margin: 20px 12px 8px;
    font-size: 11px;
    letter-spacing: .15em;
}

.nav-link {
    position: relative;
    min-width: 0;
    min-height: 43px;
    gap: 11px;
    margin: 2px 0;
    padding: 9px 11px;
    color: var(--sidebar-text);
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    transition:
        color var(--duration-fast) ease,
        background var(--duration-fast) ease,
        border-color var(--duration-fast) ease,
        transform var(--duration-fast) ease;
}

.nav-link > span:not(.nav-badge) {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-link svg {
    width: 18px;
    height: 18px;
    color: var(--sidebar-icon);
    transition: transform var(--duration-fast) ease, color var(--duration-fast) ease;
}

.nav-link:hover {
    color: var(--sidebar-strong);
    background: var(--sidebar-hover);
    border-color: rgba(255,255,255,.055);
    transform: translateX(1px);
}

.nav-link:hover > svg:first-child { transform: scale(1.05); }

.nav-link.active,
.nav-group.is-active > .nav-group-toggle {
    color: #fff;
    background: linear-gradient(135deg, rgba(9, 89, 200, .5), rgba(9, 89, 200, .24));
    border-color: rgba(126, 181, 255, .2);
    box-shadow: inset 3px 0 0 #72b1ff, 0 8px 24px rgba(0, 0, 0, .12);
}

.nav-group.is-active > .nav-group-toggle::before { display: none; }

.nav-group-toggle .nav-chevron {
    width: 13px;
    height: 13px;
    opacity: .72;
}

.nav-children-inner {
    padding: 3px 0 4px 17px;
}

.nav-child-link {
    min-height: 38px;
    color: var(--sidebar-muted);
    font-size: 12px;
}

.nav-child-link::before {
    position: absolute;
    left: -8px;
    width: 1px;
    height: 100%;
    content: '';
    background: rgba(255,255,255,.075);
}

.nav-badge {
    min-width: 20px;
    height: 20px;
    color: #fff;
    background: #2478e8;
    border: 1px solid rgba(255,255,255,.2);
    box-shadow: 0 2px 8px rgba(0,0,0,.18);
}

.sidebar-footer {
    padding: 10px 11px calc(11px + env(safe-area-inset-bottom));
    background: rgba(0,0,0,.08);
    border-top-color: var(--sidebar-border);
    backdrop-filter: blur(14px);
}

.sidebar-footer .nav-link { min-height: 40px; }

.user-chip {
    gap: 10px;
    padding: 12px 9px 4px;
}

.user-chip > span {
    width: 34px;
    height: 34px;
    background: rgba(255,255,255,.08);
    border-color: rgba(255,255,255,.15);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
}

.user-chip strong { max-width: 168px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.user-chip small { max-width: 168px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.app-main {
    margin-left: var(--sidebar-width);
    min-width: 0;
}

.page-topbar {
    position: sticky;
    z-index: 30;
    top: 0;
    min-height: var(--topbar-height);
    align-items: center;
    padding: 18px clamp(22px, 2.6vw, 38px);
    background: color-mix(in srgb, var(--surface) 91%, transparent);
    border-bottom-color: color-mix(in srgb, var(--border) 78%, transparent);
    backdrop-filter: blur(18px) saturate(1.35);
    -webkit-backdrop-filter: blur(18px) saturate(1.35);
    transition: box-shadow var(--duration) ease, border-color var(--duration) ease;
}

.page-topbar.is-scrolled {
    border-bottom-color: var(--border);
    box-shadow: 0 8px 30px rgba(15, 23, 42, .055);
}

.page-heading {
    min-width: 0;
    display: grid;
    gap: 4px;
}

.page-breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.page-breadcrumb svg { width: 12px; height: 12px; }
.page-breadcrumb span:last-child { color: var(--primary); }

.page-topbar h1 {
    max-width: 920px;
    margin: 0;
    font-size: clamp(21px, 2.2vw, 29px);
    font-weight: 700;
    line-height: 1.22;
    letter-spacing: -.035em;
    overflow-wrap: anywhere;
}

.page-description {
    max-width: 760px;
    margin: 0;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.5;
}

.topbar-actions {
    min-width: 0;
    gap: 9px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.page-content {
    max-width: var(--content-max);
    padding: clamp(20px, 2.5vw, 34px) clamp(18px, 2.6vw, 38px) 64px;
}

.mobile-topbar {
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(18px);
}

.mobile-brand { font-weight: 700; letter-spacing: -.01em; }

.sidebar-overlay,
.modal-overlay,
.ui-dialog-backdrop {
    background: var(--overlay);
    backdrop-filter: blur(3px);
}

/* Cleaner theme control; preserves the existing checkbox behavior. */
.toggle {
    width: 42px;
    height: 42px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: var(--shadow-xs);
    overflow: hidden;
}

.toggle::before,
.toggle .button { display: none !important; }

.toggle input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.toggle .label {
    position: static;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-soft);
    font-size: 0;
    line-height: 1;
    transform: none;
}

.toggle .label::before {
    display: block;
    content: '☾';
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-size: 20px;
    line-height: 1;
    transform: translateY(-1px);
}

[data-theme="dark"] .toggle .label::before { content: '☀'; font-size: 18px; line-height: 1; }
.toggle:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.toggle:has(input:focus-visible) { box-shadow: var(--focus-ring); border-color: var(--primary); }

/* --------------------------------------------------------------------------
   Panels, cards, sections and metrics
   -------------------------------------------------------------------------- */

.panel,
.form-panel,
.table-card,
.content-card {
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.panel {
    overflow: clip;
    transition: border-color var(--duration) ease, box-shadow var(--duration) ease;
}

.panel-header {
    min-height: 74px;
    gap: 20px;
    padding: 19px 22px;
    background: linear-gradient(180deg, color-mix(in srgb, var(--surface-muted) 45%, var(--surface)), var(--surface));
    border-bottom-color: var(--border);
}

.panel-header > div { min-width: 0; }

.panel-header h2,
.section-title {
    margin: 3px 0 0;
    color: var(--text);
    font-size: 16px;
    font-weight: 700;
    line-height: 1.35;
    letter-spacing: -.025em;
}

.panel-header p:not(.eyebrow) {
    max-width: 760px;
    margin: 6px 0 0;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.55;
}

:where(.card-grid, .dashboard-grid, .stats-grid, .content-grid, .panel-grid, .analytics-chart-grid, .chart-grid) {
    gap: var(--content-gap);
}

.metric-grid {
    gap: 14px;
    margin-bottom: var(--content-gap);
}

.metric-card,
.premium-metric-card,
.task-metric {
    position: relative;
    min-height: 104px;
    gap: 14px;
    padding: 17px;
    overflow: hidden;
    background:
        linear-gradient(145deg, color-mix(in srgb, var(--surface-muted) 38%, var(--surface)), var(--surface) 62%);
    border-color: var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    transition: transform var(--duration) var(--ease-standard), border-color var(--duration) ease, box-shadow var(--duration) ease;
}

.metric-card::after,
.premium-metric-card::after {
    position: absolute;
    inset: auto -30px -42px auto;
    width: 105px;
    height: 105px;
    content: '';
    pointer-events: none;
    background: radial-gradient(circle, rgba(9,89,200,.12), transparent 68%);
}

.metric-card:hover,
.premium-metric-card:hover,
.task-metric:hover {
    transform: translateY(-2px);
    border-color: color-mix(in srgb, var(--primary) 28%, var(--border));
    box-shadow: var(--shadow-md);
}

.metric-icon,
.premium-metric-icon {
    width: 40px;
    height: 40px;
    color: var(--primary);
    background: var(--primary-soft);
    border: 1px solid var(--primary-border);
    border-radius: 12px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.5);
}

.metric-card small,
.premium-metric-card small {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .02em;
}

.metric-card strong,
.premium-metric-card strong {
    margin-top: 6px;
    color: var(--text);
    font-size: clamp(18px, 1.5vw, 23px);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.04em;
}

.metric-card p,
.premium-metric-card p {
    margin-top: 5px;
    color: var(--text-muted);
    font-size: 11px;
    line-height: 1.45;
}

.analytics-intro,
.dashboard-intro {
    position: relative;
    overflow: hidden;
    margin-bottom: var(--content-gap);
    padding: clamp(20px, 3vw, 30px);
    color: var(--text);
    background:
        radial-gradient(circle at 88% 10%, rgba(9,89,200,.16), transparent 19rem),
        linear-gradient(135deg, var(--surface), color-mix(in srgb, var(--primary-soft) 52%, var(--surface)));
    border: 1px solid color-mix(in srgb, var(--primary) 18%, var(--border));
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
}

.analytics-intro::before,
.dashboard-intro::before {
    position: absolute;
    inset: -70px -40px auto auto;
    width: 190px;
    height: 190px;
    content: '';
    border: 1px solid rgba(9,89,200,.14);
    border-radius: 50%;
    box-shadow: 0 0 0 30px rgba(9,89,200,.035), 0 0 0 60px rgba(9,89,200,.025);
}

.analytics-intro > *,
.dashboard-intro > * { position: relative; }

.analytics-intro h2,
.dashboard-intro h2 {
    margin: 5px 0 8px;
    font-size: clamp(20px, 2vw, 28px);
    font-weight: 700;
    letter-spacing: -.04em;
}

.analytics-intro p:not(.eyebrow),
.dashboard-intro p:not(.eyebrow) {
    max-width: 760px;
    color: var(--text-soft);
    font-size: 11px;
    line-height: 1.7;
}

.analytics-live,
.live-dot {
    background: color-mix(in srgb, var(--success-soft) 86%, var(--surface));
    box-shadow: inset 0 1px 0 rgba(255,255,255,.35);
}

/* --------------------------------------------------------------------------
   Button system
   -------------------------------------------------------------------------- */

.button,
.icon-button {
    position: relative;
    flex: 0 0 auto;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.button {
    min-height: var(--control-height);
    gap: 8px;
    padding: 9px 15px;
    border-radius: 9px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -.005em;
    white-space: nowrap;
    box-shadow: var(--shadow-xs);
    transition:
        transform var(--duration-fast) var(--ease-standard),
        background var(--duration-fast) ease,
        border-color var(--duration-fast) ease,
        color var(--duration-fast) ease,
        box-shadow var(--duration-fast) ease;
}

.button svg { width: 16px; height: 16px; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(0); box-shadow: none; }
.button:focus-visible { outline: 0; box-shadow: var(--focus-ring); }

.button-primary {
    color: var(--primary-contrast);
    background: linear-gradient(180deg, color-mix(in srgb, var(--primary) 88%, white), var(--primary));
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(9, 89, 200, .19), inset 0 1px 0 rgba(255,255,255,.19);
}

.button-primary:hover:not(:disabled) {
    background: linear-gradient(180deg, color-mix(in srgb, var(--primary-hover) 88%, white), var(--primary-hover));
    border-color: var(--primary-hover);
    box-shadow: 0 7px 18px rgba(9, 89, 200, .24), inset 0 1px 0 rgba(255,255,255,.18);
}

.button-secondary {
    color: var(--text-soft);
    background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--surface-muted) 55%, var(--surface)));
    border-color: var(--border-strong);
}

.button-secondary:hover:not(:disabled) {
    color: var(--text);
    background: var(--surface-hover);
    border-color: color-mix(in srgb, var(--primary) 22%, var(--border-strong));
}

.button-danger {
    color: #fff;
    background: var(--danger);
    border-color: var(--danger);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--danger) 23%, transparent);
}

.button-danger:hover:not(:disabled) { background: var(--danger-hover); border-color: var(--danger-hover); }

.button-success {
    color: #fff;
    background: var(--success);
    border-color: var(--success);
}

.button-ghost {
    color: var(--text-soft);
    background: transparent;
    border-color: transparent;
    box-shadow: none;
}

.button-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-hover); }

.button:disabled,
.button[aria-disabled="true"] {
    color: var(--text-disabled);
    background: var(--surface-strong);
    border-color: var(--border);
    box-shadow: none;
    opacity: .72;
    cursor: not-allowed;
    transform: none;
}

.button.is-loading { color: transparent !important; pointer-events: none; }
.button.is-loading::after {
    position: absolute;
    width: 15px;
    height: 15px;
    content: '';
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: uiSpin .7s linear infinite;
}
.button-primary.is-loading::after,
.button-danger.is-loading::after { color: var(--primary-contrast); }

.icon-button {
    width: 38px;
    height: 38px;
    color: var(--text-soft);
    background: transparent;
    border-color: transparent;
    border-radius: 9px;
    transition: transform var(--duration-fast) ease, color var(--duration-fast) ease, background var(--duration-fast) ease, border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}

.icon-button:hover {
    color: var(--primary);
    background: var(--primary-soft);
    border-color: var(--primary-border);
    transform: translateY(-1px);
}

.icon-button.danger:hover {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: var(--danger-border);
}

.icon-button:focus-visible { outline: 0; box-shadow: var(--focus-ring); }

:where(.topbar-actions, .form-actions, .table-actions, .card-actions, .toolbar, .action-row, .inline-actions, .row-actions) {
    gap: var(--action-gap);
}

.row-actions { flex-wrap: nowrap; }
.row-actions form { display: inline-flex; }

.text-link {
    color: var(--primary);
    text-underline-offset: 3px;
}

/* --------------------------------------------------------------------------
   Forms and inputs
   -------------------------------------------------------------------------- */

.form-grid,
.form-stack,
.dialog-form .ui-dialog-body {
    align-content: start;
}

.form-grid {
    gap: 18px;
    padding: 22px;
}

.form-stack { gap: 17px; }
.form-panel > .form-stack,
.crud-form > .form-stack { padding: 22px; }

.form-grid label,
.form-stack label,
.dialog-form .ui-dialog-body > label,
.financial-report-filter label,
.form-field {
    min-width: 0;
    gap: 7px;
    color: var(--text-soft);
    font-size: 12px;
    font-weight: 600;
}

.form-grid label > span,
.form-stack label > span,
.dialog-form .ui-dialog-body > label > span {
    color: var(--text-soft);
    line-height: 1.35;
}

:where(input:not([type='checkbox']):not([type='radio']):not([type='hidden']), select, textarea, .custom-select-trigger) {
    width: 100%;
    max-width: 100%;
    min-height: var(--control-height);
    padding: 9px 12px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, .025);
    outline: none;
    transition: border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease, background var(--duration-fast) ease;
}

:where(input:not([type='checkbox']):not([type='radio']):not([type='hidden']), select, textarea, .custom-select-trigger):hover:not(:disabled) {
    border-color: color-mix(in srgb, var(--primary) 24%, var(--border-strong));
}

:where(input:not([type='checkbox']):not([type='radio']):not([type='hidden']), select, textarea):focus,
.custom-select.open .custom-select-trigger,
.custom-select-trigger:focus-visible {
    border-color: var(--border-focus);
    box-shadow: var(--focus-ring);
}

textarea {
    min-height: 106px;
    resize: vertical;
    line-height: 1.6;
}

:where(input, select, textarea):disabled {
    color: var(--text-disabled);
    background: var(--surface-strong);
    border-color: var(--border);
    cursor: not-allowed;
}

:where(input, textarea)[readonly] {
    color: var(--text-soft);
    background: var(--surface-muted);
}

:where(input, select, textarea)[aria-invalid="true"],
.field-invalid :where(input, textarea, .custom-select-trigger, .file-picker) {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 13%, transparent);
}

:where(input, select, textarea)[data-state="success"] {
    border-color: var(--success);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 12%, transparent);
}

input[type='checkbox'],
input[type='radio'] {
    width: 18px;
    height: 18px;
    min-height: 18px;
    flex: 0 0 auto;
    margin: 0;
    accent-color: var(--primary);
    cursor: pointer;
}

.form-grid label.field-checkbox,
.dialog-form .ui-dialog-body > label.field-checkbox,
.checkbox-grid > label {
    min-height: 52px;
    padding: 12px 13px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 10px;
    transition: background var(--duration-fast) ease, border-color var(--duration-fast) ease;
}

.form-grid label.field-checkbox:hover,
.dialog-form .ui-dialog-body > label.field-checkbox:hover,
.checkbox-grid > label:hover {
    background: var(--primary-subtle);
    border-color: var(--primary-border);
}

label small,
.form-stack small,
.field-help {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 400;
    line-height: 1.5;
}

label em,
.field-error,
.client-field-error {
    color: var(--danger);
    font-size: 11px;
    font-style: normal;
    font-weight: 500;
}

.form-actions {
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
    padding-top: 5px;
}

.form-error-summary {
    padding: 12px 14px;
    color: var(--danger);
    background: var(--danger-soft);
    border-color: var(--danger-border);
    border-radius: 10px;
    font-size: 12px;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.filter-bar,
.task-filter-bar,
.financial-report-filter {
    gap: 10px;
    padding: 14px 18px;
    background: color-mix(in srgb, var(--surface-muted) 45%, var(--surface));
    border-bottom-color: var(--border);
}

.filter-bar { flex-wrap: wrap; }
.filter-bar .button { min-width: 88px; }
.filter-bar .custom-select { flex: 0 1 190px; }
.search-field { min-width: min(260px, 100%); }
.search-field svg { top: 12px; color: var(--text-muted); }
.search-field input { padding-left: 39px; }
.search-field:focus-within svg { color: var(--primary); }

.custom-select-menu {
    padding: 6px;
    background: var(--surface-elevated);
    border-color: var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
}

.custom-select-option {
    min-height: 38px;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 12px;
}

.custom-select-option:hover,
.custom-select-option:focus { background: var(--surface-hover); }
.custom-select-option.selected { color: var(--primary); background: var(--primary-soft); }

.file-picker {
    border-style: dashed;
    border-width: 1px;
    border-radius: 12px;
    background: var(--surface-muted);
}

.file-picker:hover,
.file-picker.dragging { border-color: var(--primary); background: var(--primary-subtle); }

.segmented-control {
    padding: 3px;
    gap: 3px;
    background: var(--surface-strong);
    border-color: var(--border);
    border-radius: 10px;
}

.segmented-control span {
    min-height: 36px;
    border: 0;
    border-radius: 8px;
    background: transparent;
}

.segmented-control input:checked + span {
    color: var(--primary);
    background: var(--surface);
    box-shadow: var(--shadow-xs);
}

/* --------------------------------------------------------------------------
   Tables, lists, search, filters and pagination
   -------------------------------------------------------------------------- */

.table-wrap {
    position: relative;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
    outline: none;
}

.table-wrap:focus-visible { box-shadow: inset var(--focus-ring); }
.table-wrap.has-overflow::after {
    position: sticky;
    right: 0;
    float: right;
    width: 26px;
    height: 0;
    content: '';
    pointer-events: none;
    box-shadow: -14px 0 24px rgba(15, 23, 42, .1);
}

.table-wrap table { width: 100%; }

table { font-variant-numeric: tabular-nums; }

th {
    height: 43px;
    padding: 11px 15px;
    color: var(--text-muted);
    background: var(--surface-muted);
    border-bottom-color: var(--border);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .075em;
    white-space: nowrap;
}

td {
    min-height: var(--table-row-height);
    padding: 14px 15px;
    color: var(--text-soft);
    border-bottom-color: var(--border);
    font-size: 12px;
    line-height: 1.45;
    vertical-align: middle;
    overflow-wrap: anywhere;
}

tbody tr { transition: background var(--duration-fast) ease; }
tbody tr:hover td { background: color-mix(in srgb, var(--primary-soft) 40%, var(--surface)); }
tbody tr:last-child td { border-bottom: 0; }

td strong { color: var(--text); font-size: 12px; font-weight: 600; }
td small { margin-top: 3px; color: var(--text-muted); font-size: 11px; line-height: 1.45; }

.align-right,
.amount { font-variant-numeric: tabular-nums; }

.status-badge {
    min-height: 24px;
    gap: 5px;
    padding: 3px 8px;
    color: var(--text-soft);
    background: var(--surface-strong);
    border-color: var(--border);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .015em;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.28);
}

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

.pagination,
.pagination-bar {
    gap: 8px;
    flex-wrap: wrap;
    padding: 14px 18px;
    background: color-mix(in srgb, var(--surface-muted) 35%, var(--surface));
    border-top-color: var(--border);
}

.pagination a,
.pagination span,
.pagination-bar a,
.pagination-bar span {
    min-width: 34px;
    min-height: 34px;
    display: inline-grid;
    place-items: center;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    text-decoration: none;
}

.pagination a:hover,
.pagination-bar a:hover { color: var(--primary); background: var(--primary-soft); border-color: var(--primary-border); }

.search-results { gap: 10px; }
.search-result {
    min-height: 66px;
    border-radius: 12px;
    transition: transform var(--duration-fast) ease, background var(--duration-fast) ease, border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}
.search-result:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

.subnav,
.task-view-tabs,
.dashboard-analytics-tabs {
    gap: 5px;
    padding: 5px;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    border-color: var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-xs);
    scrollbar-width: none;
}

.subnav::-webkit-scrollbar,
.task-view-tabs::-webkit-scrollbar,
.dashboard-analytics-tabs::-webkit-scrollbar { display: none; }

.subnav a,
.task-view-tabs a,
.dashboard-analytics-tab {
    min-height: 36px;
    padding: 8px 12px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 11px;
    transition: color var(--duration-fast) ease, background var(--duration-fast) ease, border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}

.subnav a:hover,
.subnav a.active,
.task-view-tabs a:hover,
.task-view-tabs a.active,
.dashboard-analytics-tab:hover,
.dashboard-analytics-tab.is-active {
    color: var(--primary);
    background: var(--primary-soft);
    border-color: var(--primary-border);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.4);
}

/* --------------------------------------------------------------------------
   Dialog, popup, notification and state systems
   -------------------------------------------------------------------------- */

.ui-dialog {
    align-items: center;
    padding: clamp(12px, 3vw, 28px);
    overflow: hidden;
}

.ui-dialog.open { animation: dialogBackdropIn var(--duration) ease both; }

.ui-dialog-shell {
    max-height: calc(100dvh - clamp(24px, 6vw, 56px));
    min-height: 0;
    overflow: hidden;
    background: var(--surface-elevated);
    border-color: var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.ui-dialog-header,
.ui-dialog-footer { flex: 0 0 auto; }

.ui-dialog-header {
    min-width: 0;
    min-height: 78px;
    padding: 18px 20px;
    background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--surface-muted) 42%, var(--surface)));
    border-bottom-color: var(--border);
}

.ui-dialog-header > div { min-width: 0; }
.ui-dialog-header h2 { margin: 3px 0 0; font-size: 17px; font-weight: 700; letter-spacing: -.025em; overflow-wrap: anywhere; }
.ui-dialog-header p:not(.eyebrow) { margin: 6px 0 0; color: var(--text-muted); font-size: 12px; line-height: 1.55; overflow-wrap: anywhere; }

.dialog-form {
    min-height: 0;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
}

.ui-dialog-body {
    min-height: 0;
    flex: 1 1 auto;
    padding: 20px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.ui-dialog-footer {
    position: relative;
    z-index: 1;
    min-height: 66px;
    gap: 9px;
    flex-wrap: wrap;
    padding: 12px 20px;
    background: color-mix(in srgb, var(--surface-muted) 55%, var(--surface));
    border-top-color: var(--border);
    box-shadow: 0 -8px 24px rgba(15,23,42,.035);
}

.ui-dialog-confirm { border-radius: var(--radius-lg); }
.confirm-icon { width: 44px; height: 44px; border-radius: 12px; }
.confirm-copy h2 { font-size: 16px; font-weight: 700; }
.confirm-copy p { font-size: 12px; }

.toast-region {
    top: 18px;
    right: 18px;
    width: min(400px, calc(100% - 28px));
    gap: 9px;
}

.app-toast,
.flash {
    border-radius: 12px;
    box-shadow: var(--shadow-md);
}

.app-toast {
    min-height: 54px;
    padding: 11px 12px;
    background: color-mix(in srgb, var(--surface-elevated) 96%, transparent);
    backdrop-filter: blur(16px);
}

.flash-stack {
    top: calc(var(--topbar-height) + 14px);
    left: calc(var(--sidebar-width) + clamp(18px, 2.6vw, 38px));
    gap: 9px;
}

.flash {
    max-width: min(460px, calc(100vw - var(--sidebar-width) - 56px));
    padding: 12px 15px;
    font-size: 12px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.empty-state {
    max-width: 680px;
    margin-inline: auto;
    padding: clamp(38px, 6vw, 64px) 22px;
    text-align: center;
}

.empty-state-visual {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    margin: 0 auto 14px;
    color: var(--primary);
    background: var(--primary-soft);
    border: 1px solid var(--primary-border);
    border-radius: 16px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.5);
}

.empty-state-visual svg { width: 23px; height: 23px; }
.empty-state h3 { margin-bottom: 7px; font-size: 15px; font-weight: 700; letter-spacing: -.02em; }
.empty-state p { max-width: 480px; margin: 0 auto; color: var(--text-muted); font-size: 12px; line-height: 1.65; }
.empty-state .button { margin-top: 16px; }
.empty-state.compact { padding: 28px 15px; }
.empty-state.compact .empty-state-visual { width: 42px; height: 42px; border-radius: 12px; }

.skeleton {
    position: relative;
    overflow: hidden;
    color: transparent !important;
    background: var(--surface-strong) !important;
    border-color: transparent !important;
    border-radius: 7px;
}

.skeleton::after {
    position: absolute;
    inset: 0;
    content: '';
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.38), transparent);
    transform: translateX(-100%);
    animation: skeletonSweep 1.35s ease-in-out infinite;
}

.progress-track { height: 6px; background: var(--surface-strong); }
.progress-track span,
.progress-track i { background: linear-gradient(90deg, var(--primary), color-mix(in srgb, var(--primary) 66%, #59b0ff)); }

/* --------------------------------------------------------------------------
   Charts, analytics and financial interfaces
   -------------------------------------------------------------------------- */

.chart-grid,
.analytics-chart-grid,
.premium-chart-grid { gap: var(--content-gap); }

.analytics-chart-panel,
.premium-chart-card {
    overflow: hidden;
    border-radius: var(--radius-lg);
}

.premium-chart-header {
    min-height: 78px;
    padding: 17px 19px;
    background: linear-gradient(180deg, color-mix(in srgb, var(--surface-muted) 45%, var(--surface)), var(--surface));
    border-bottom: 1px solid var(--border);
}

.premium-chart-heading h3,
.premium-chart-heading h2 { font-weight: 700; letter-spacing: -.02em; }

.premium-chart-icon {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.45);
}

.chart-box,
.premium-chart-box { min-height: 300px; }

.chart-info-button,
.chart-report-button {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    font-family: var(--font);
    font-size: 13px;
    box-shadow: var(--shadow-xs);
    transition: transform var(--duration-fast) ease, box-shadow var(--duration-fast) ease, background var(--duration-fast) ease;
}

.chart-info-button:hover,
.chart-report-button:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

.financial-report-links { gap: 12px; }
.financial-report-link {
    min-height: 78px;
    padding: 14px;
    background: linear-gradient(145deg, var(--surface-muted), var(--surface));
    border-radius: 12px;
}
.financial-report-link:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.financial-statement-meta { background: var(--border); }
.financial-statement-meta span { padding: 13px 16px; }
.financial-statement-table .amount,
.statement-total,
.statement-lines > div > strong,
.financial-statement-result strong { font-variant-numeric: tabular-nums; }

.financial-analysis-summary,
.financial-analysis-section,
.financial-analysis-quality,
.financial-analysis-error { border-radius: 12px; }

/* --------------------------------------------------------------------------
   Module-specific consistency refinements
   -------------------------------------------------------------------------- */

.document-card,
.note-card,
.module-card,
.task-performance-grid article,
.info-grid > div,
.requirement-box,
.summary-package,
.installment-card,
.revenue-grid > div {
    border-radius: 12px;
    transition: transform var(--duration-fast) ease, border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}

.document-card:hover,
.note-card:hover,
.module-card:hover,
.task-performance-grid article:hover,
.info-grid > div:hover {
    transform: translateY(-1px);
    border-color: color-mix(in srgb, var(--primary) 22%, var(--border));
    box-shadow: var(--shadow-md);
}

.document-icon { width: 40px; height: 40px; border-radius: 11px; border: 1px solid var(--primary-border); }
.note-card.pinned { background: color-mix(in srgb, var(--warning-soft) 58%, var(--surface)); border-color: var(--warning-border); }

.task-list-header {
    min-height: 62px;
    border-radius: 11px;
    box-shadow: var(--shadow-xs);
}
.task-list-header:hover { border-color: var(--primary-border); box-shadow: var(--shadow); }

.permission-matrix-wrap {
    border-top: 1px solid var(--border);
    scrollbar-color: var(--border-strong) transparent;
}

.agent-panel {
    background: var(--surface-elevated);
    border-left-color: var(--border);
    box-shadow: -20px 0 60px rgba(15,23,42,.13);
}

.agent-header { min-height: 84px; padding: 16px 18px; background: linear-gradient(180deg, var(--surface), var(--surface-muted)); }
.agent-scope { padding: 11px 18px; }
.agent-messages { padding: 18px; }
.agent-composer { padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); background: var(--surface); }
.agent-bubble { border-radius: 14px; }
.agent-welcome { margin-top: 72px; }
.agent-orb { width: 54px; height: 54px; border-radius: 17px; box-shadow: var(--shadow-md); }

/* --------------------------------------------------------------------------
   Authentication
   -------------------------------------------------------------------------- */

.auth-page {
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(circle at 14% 8%, rgba(9,89,200,.18), transparent 30rem),
        radial-gradient(circle at 90% 88%, rgba(29,126,236,.1), transparent 28rem),
        var(--bg);
}

.auth-page::before {
    position: fixed;
    inset: 0;
    content: '';
    pointer-events: none;
    background-image: linear-gradient(rgba(9,89,200,.025) 1px, transparent 1px), linear-gradient(90deg, rgba(9,89,200,.025) 1px, transparent 1px);
    background-size: 42px 42px;
}

.auth-shell {
    position: relative;
    width: min(1080px, 100%);
    min-height: 620px;
    grid-template-columns: 1.08fr .92fr;
    border-color: color-mix(in srgb, var(--primary) 14%, var(--border));
    border-radius: 24px;
    box-shadow: var(--shadow-lg);
}

.auth-intro {
    position: relative;
    isolation: isolate;
    padding: clamp(42px, 6vw, 72px);
    background:
        radial-gradient(circle at 75% 15%, rgba(83,157,255,.32), transparent 20rem),
        linear-gradient(145deg, #08234a, #04152e 72%);
}

.auth-intro::after {
    position: absolute;
    z-index: -1;
    inset: 0;
    content: '';
    background-image: linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
    background-size: 36px 36px;
    mask-image: linear-gradient(black, transparent);
}

.auth-intro h1 { max-width: 620px; margin-top: 30px; font-size: clamp(34px, 5vw, 58px); line-height: 1.04; }
.auth-intro p:not(.eyebrow) { max-width: 590px; color: rgba(255,255,255,.74); font-size: 12px; line-height: 1.75; }
.auth-meta { margin-top: auto; padding-top: 60px; }
.auth-card { padding: clamp(36px, 5vw, 62px); gap: 32px; }
.auth-card h2 { margin: 5px 0 6px; font-size: 30px; letter-spacing: -.04em; }
.auth-card .form-stack { gap: 18px; }

/* --------------------------------------------------------------------------
   Responsive behavior
   -------------------------------------------------------------------------- */

@media (max-width: 1280px) {
    :root { --sidebar-width: 250px; --agent-width: 390px; }
    .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .task-metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 1024px) {
    .page-topbar { align-items: flex-start; }
    .topbar-actions { max-width: 48%; }
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid,
    .settings-layout,
    .estimator-layout { grid-template-columns: 1fr; }
    .estimator-summary { position: static; }
    .analytics-chart-grid,
    .chart-grid { grid-template-columns: 1fr; }
    .analytics-chart-wide,
    .chart-grid .panel-full { grid-column: auto; }
}

@media (max-width: 820px) {
    :root { --topbar-height: auto; }

    .app-sidebar { width: min(88vw, 310px); box-shadow: 24px 0 60px rgba(0,0,0,.28); }
    .app-main { margin-left: 0; padding-top: 60px; }
    .mobile-topbar { height: 60px; padding: 8px 14px; }
    .mobile-topbar .icon-button { width: 40px; height: 40px; }

    .page-topbar {
        position: relative;
        min-height: auto;
        flex-direction: column;
        align-items: stretch;
        gap: 14px;
        padding: 20px 18px 17px;
        backdrop-filter: none;
    }

    .page-breadcrumb { display: none; }
    .page-description { font-size: 12px; }
    .topbar-actions { width: 100%; max-width: none; justify-content: flex-start; }
    .topbar-actions .toggle { order: 2; margin-left: auto; }
    .page-content { padding: 18px 16px 52px; overflow-x: hidden; }
    .flash-stack { top: 72px; left: 14px; right: 14px; }
    .flash { max-width: none; }

    .form-grid,
    .dialog-form .ui-dialog-body,
    .task-form-grid { grid-template-columns: 1fr; }
    .field-span-2 { grid-column: 1 / -1; }

    .filter-bar,
    .task-filter-bar,
    .financial-report-filter { align-items: stretch; }
    .filter-bar .search-field { flex-basis: 100%; }
    .filter-bar .custom-select { flex: 1 1 160px; min-width: 0; }

    .ui-dialog { align-items: flex-end; padding: 0; }
    .ui-dialog-shell,
    .ui-dialog-wide { width: 100%; max-height: 94dvh; border-radius: 18px 18px 0 0; }
    .ui-dialog-header { padding: 16px 17px; }
    .ui-dialog-body,
    .ui-dialog-body.form-grid { padding: 17px; }
    .ui-dialog-footer { padding: 12px 17px max(12px, env(safe-area-inset-bottom)); }
    .ui-dialog-confirm { width: calc(100% - 24px); margin: auto 12px; border-radius: 16px; }

    .toast-region { top: 72px; right: 14px; }
    .row-actions { gap: 5px; }
    .icon-button { width: 40px; height: 40px; }

    .auth-page { padding: 16px; }
    .auth-shell { min-height: 0; grid-template-columns: 1fr; border-radius: 20px; }
    .auth-intro { display: none; }
    .auth-card { min-height: min(640px, calc(100dvh - 32px)); }
}

@media (max-width: 600px) {
    :root { --content-gap: 14px; --action-gap: 7px; }

    .page-topbar h1 { font-size: 23px; }
    .topbar-actions .button { min-width: 0; flex: 1 1 145px; }
    .topbar-actions .toggle { flex: 0 0 auto; }

    .panel { border-radius: 14px; }
    .panel-header { min-height: 0; flex-direction: column; align-items: stretch; gap: 12px; padding: 16px; }
    .panel-header > :last-child:not(:first-child) { align-self: flex-start; }

    .metric-grid,
    .task-metric-grid,
    .financial-analysis-metrics { grid-template-columns: 1fr; }
    .metric-card,
    .premium-metric-card { min-height: 92px; }

    .analytics-intro,
    .dashboard-intro { padding: 20px; border-radius: 16px; }
    .analytics-live { align-self: flex-start; }

    .filter-bar,
    .task-filter-bar,
    .financial-report-filter { padding: 13px; }
    .filter-bar .custom-select,
    .filter-bar .button { flex: 1 1 100%; width: 100%; }

    .form-grid,
    .form-panel > .form-stack,
    .crud-form > .form-stack { padding: 17px; }

    .table-wrap { margin-inline: -1px; padding-bottom: 5px; }
    .table-wrap table { min-width: 680px; }
    th, td { padding-inline: 13px; }

    .pagination,
    .pagination-bar { justify-content: center; padding: 12px; }

    .ui-dialog { align-items: stretch; }
    .ui-dialog-shell,
    .ui-dialog-wide,
    .ui-dialog-confirm { width: 100%; max-height: 100dvh; border-inline: 0; border-radius: 0; }
    .ui-dialog-footer .button { min-width: 0; flex: 1 1 130px; }
    .ui-dialog-confirm { align-self: flex-end; max-height: min(100dvh, 540px); border-radius: 18px 18px 0 0; border-top: 1px solid var(--border); }

    .document-grid,
    .notes-grid,
    .info-grid,
    .module-grid { grid-template-columns: 1fr; }

    .auth-page { padding: 0; }
    .auth-shell { min-height: 100dvh; border: 0; border-radius: 0; }
    .auth-card { padding: 32px 22px; }
}

@media (max-width: 390px) {
    .ui-dialog-footer { display: grid; grid-template-columns: 1fr; }
    .ui-dialog-footer .button { width: 100%; }
    .topbar-actions { display: grid; grid-template-columns: 1fr auto; }
    .topbar-actions .button { width: 100%; }
}

@media (hover: none) {
    .button:hover:not(:disabled),
    .icon-button:hover,
    .metric-card:hover,
    .premium-metric-card:hover,
    .task-metric:hover,
    .document-card:hover,
    .note-card:hover,
    .module-card:hover { transform: none; }
}

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

@media (prefers-contrast: more) {
    :root { --border: #b8c2d0; --border-strong: #7b8798; }
    .button,
    .panel,
    input,
    select,
    textarea { border-width: 2px; }
}

@keyframes uiSpin { to { transform: rotate(360deg); } }
@keyframes skeletonSweep { 100% { transform: translateX(100%); } }
@keyframes dialogBackdropIn { from { opacity: 0; } }

/* Final interaction refinements */
.page-breadcrumb svg { transform: rotate(-90deg); }
.button.is-loading::after { color: var(--text-soft); }
.button-primary.is-loading::after,
.button-danger.is-loading::after,
.button-success.is-loading::after { color: var(--primary-contrast); }

@media (max-width: 820px) {
    .icon-button { width: 44px; height: 44px; }
}

/* --------------------------------------------------------------------------
   Unified journal-entry workspace
   -------------------------------------------------------------------------- */

.journal-control-note {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 20px;
    margin-bottom: var(--space-5);
    border-color: var(--primary-border);
    background: linear-gradient(135deg, var(--primary-soft), var(--surface) 58%);
}

.journal-control-note h2,
.journal-control-note p { margin: 0; }
.journal-control-note h2 { margin-top: 4px; font-size: 17px; }
.journal-control-note p:last-child { margin-top: 6px; color: var(--text-soft); max-width: 980px; }
.journal-control-icon {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    color: var(--primary);
    background: var(--surface);
    border: 1px solid var(--primary-border);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}
.journal-control-icon svg { width: 20px; height: 20px; }

.journal-summary-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric-card-warning { border-color: var(--warning-border); background: linear-gradient(135deg, var(--warning-soft), var(--surface)); }
.metric-card-warning .metric-icon { color: var(--warning); background: var(--warning-soft); }

.journal-register-panel { overflow: visible; }
.journal-register-header { margin-bottom: 18px; }
.journal-filter-grid {
    display: grid;
    grid-template-columns: minmax(280px, 2fr) repeat(3, minmax(145px, 1fr)) repeat(2, minmax(132px, .8fr));
    gap: 12px;
    align-items: end;
    padding: 16px;
    margin-bottom: 18px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.journal-filter-grid > label:not(.search-field) {
    min-width: 0;
    display: grid;
    gap: 6px;
    color: var(--text-soft);
    font-size: 12px;
    font-weight: 600;
}
.journal-filter-grid > label > span { color: var(--text-muted); }
.journal-filter-search { align-self: end; }
.journal-filter-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 9px; }

.journal-register-table { min-width: 1020px; }
.journal-register-table td { vertical-align: top; }
.journal-register-table td:nth-child(1) { min-width: 145px; }
.journal-register-table td:nth-child(2) { min-width: 270px; }
.journal-register-table td:nth-child(3) { min-width: 160px; }
.journal-register-table .amount { text-align: right; font-variant-numeric: tabular-nums; }
.journal-register-row:has(+ .journal-lines-detail:not([hidden])) td { background: var(--primary-soft); border-bottom-color: var(--primary-border); }
.journal-row-actions .icon-button.is-open svg { transform: rotate(180deg); }
.journal-balanced,
.journal-unbalanced {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 7px;
    font-weight: 600;
}
.journal-balanced { color: var(--success); }
.journal-unbalanced { color: var(--warning); }
.journal-balanced svg,
.journal-unbalanced svg { width: 12px; height: 12px; }
.journal-lines-detail[hidden] { display: none; }
.journal-lines-detail td { padding: 0; background: var(--surface-muted); }
.journal-lines-detail:hover td { background: var(--surface-muted); }
.journal-lines-card { padding: 18px 22px 22px; border-bottom: 1px solid var(--border); }
.journal-lines-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
}
.journal-lines-heading strong,
.journal-lines-heading small { display: block; }
.journal-lines-heading small { margin-top: 3px; color: var(--text-muted); }
.journal-lines-heading > span {
    padding: 5px 9px;
    color: var(--text-soft);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}
.journal-lines-table { min-width: 760px; background: var(--surface); border: 1px solid var(--border); }
.journal-lines-table .amount { text-align: right; font-variant-numeric: tabular-nums; }
.journal-lines-table tfoot th { color: var(--text); background: var(--surface-strong); }
.journal-source-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 20px;
    margin-top: 12px;
    color: var(--text-muted);
    font-size: 11px;
}
.journal-source-meta strong { color: var(--text-soft); }

.journal-editor-shell { width: min(1220px, 100%); max-height: min(94dvh, 980px); }
.journal-editor-body { display: block !important; padding: 0 !important; }
.journal-form-section { padding: 22px 24px; }
.journal-form-section + .journal-form-section { border-top: 1px solid var(--border); }
.journal-section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 17px;
}
.journal-section-heading > div { display: flex; align-items: center; gap: 10px; }
.journal-section-heading > div > span {
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    color: var(--primary);
    background: var(--primary-soft);
    border: 1px solid var(--primary-border);
    border-radius: 8px;
    font-size: 12px;
    font-weight: 800;
}
.journal-section-heading h3,
.journal-section-heading p { margin: 0; }
.journal-section-heading h3 { font-size: 14px; }
.journal-section-heading p { max-width: 540px; color: var(--text-muted); font-size: 12px; text-align: right; }
.journal-header-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 15px;
}
.journal-header-grid > label {
    min-width: 0;
    display: grid;
    align-content: start;
    gap: 6px;
    color: var(--text-soft);
    font-size: 12px;
    font-weight: 600;
}
.journal-header-grid > label > span em { color: var(--danger); font-style: normal; }
.journal-header-grid > label small { color: var(--text-muted); font-size: 11px; font-weight: 400; }
.journal-field-wide { grid-column: span 2; }
.field-error { display: block; margin-top: 4px; color: var(--danger); font-size: 11px; font-weight: 600; }

.journal-line-editor { background: var(--surface-muted); }
.journal-line-editor-wrap { overflow: visible; }
.journal-line-editor-table { min-width: 1040px; border: 1px solid var(--border); background: var(--surface); }
.journal-line-editor-table th:nth-child(1) { width: 24%; }
.journal-line-editor-table th:nth-child(2) { width: 18%; }
.journal-line-editor-table th:nth-child(3) { width: 27%; }
.journal-line-editor-table th:nth-child(4),
.journal-line-editor-table th:nth-child(5) { width: 13%; }
.journal-line-editor-table th:last-child { width: 48px; }
.journal-line-editor-table td { padding: 9px; vertical-align: top; }
.journal-line-editor-table input,
.journal-line-editor-table select,
.journal-line-editor-table .custom-select-trigger { min-height: 38px; }
.journal-line-editor-table input[type='checkbox'][name$='-DELETE'] { display: none; }
.journal-line-editor-table .amount { text-align: right; }
.journal-line-editor-table tfoot td,
.journal-line-editor-table tfoot th { padding: 11px; background: var(--surface-strong); }
.journal-line-editor-table tfoot th span,
.journal-line-editor-table tfoot th strong { display: block; }
.journal-line-editor-table tfoot th span { color: var(--text-muted); font-size: 11px; }
.journal-line-editor-table tfoot th strong { margin-top: 2px; color: var(--text); font-size: 13px; font-variant-numeric: tabular-nums; }
.journal-line-form.has-errors td { background: var(--danger-soft); }
.journal-line-error { min-width: 170px; }

.journal-balance-bar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 13px 15px;
    margin-top: 14px;
    border: 1px solid var(--warning-border);
    border-radius: var(--radius-md);
    background: var(--warning-soft);
}
.journal-balance-bar > span {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    color: var(--warning);
    background: var(--surface);
    border-radius: 9px;
}
.journal-balance-bar svg { width: 17px; height: 17px; }
.journal-balance-bar strong,
.journal-balance-bar p { margin: 0; }
.journal-balance-bar p { margin-top: 2px; color: var(--text-muted); font-size: 11px; }
.journal-balance-bar output { color: var(--warning); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.journal-balance-bar.is-balanced { border-color: var(--success-border); background: var(--success-soft); }
.journal-balance-bar.is-balanced > span,
.journal-balance-bar.is-balanced output { color: var(--success); }
.journal-editor-footer { justify-content: space-between; }
.journal-editor-footer > div { display: flex; align-items: center; gap: 9px; }
.journal-accounting-reminder,
.journal-immutable-note { display: flex; align-items: center; gap: 7px; color: var(--text-muted); font-size: 11px; }
.journal-accounting-reminder svg,
.journal-immutable-note svg { width: 15px; height: 15px; color: var(--primary); }

.journal-view-shell { width: min(980px, 100%); }
.journal-view-body { display: grid; gap: 18px; }
.journal-view-summary,
.journal-audit-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}
.journal-view-summary > div,
.journal-audit-grid > div {
    padding: 12px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}
.journal-view-summary small,
.journal-view-summary strong,
.journal-audit-grid small,
.journal-audit-grid strong { display: block; }
.journal-view-summary small,
.journal-audit-grid small { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; }
.journal-view-summary strong,
.journal-audit-grid strong { margin-top: 5px; color: var(--text); font-size: 12px; overflow-wrap: anywhere; }
.journal-audit-wide { grid-column: 1 / -1; }
.journal-view-dialog .ui-dialog-footer > div { display: flex; align-items: center; gap: 9px; }
.journal-view-dialog .ui-dialog-footer form { margin: 0; }

.nav-section-label {
    display: block;
    padding: 12px 10px 5px 16px;
    color: var(--sidebar-muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .13em;
    text-transform: uppercase;
}
.nav-section-label:not(:first-child) { margin-top: 4px; border-top: 1px solid rgba(255,255,255,.07); }

@media (max-width: 1180px) {
    .journal-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .journal-filter-grid { grid-template-columns: minmax(240px, 2fr) repeat(2, minmax(150px, 1fr)); }
    .journal-filter-search { grid-column: span 2; }
}

@media (max-width: 820px) {
    .journal-control-note { padding: 17px; }
    .journal-summary-grid { grid-template-columns: 1fr 1fr; }
    .journal-filter-grid { grid-template-columns: 1fr 1fr; }
    .journal-filter-search { grid-column: 1 / -1; }
    .journal-section-heading { display: block; }
    .journal-section-heading p { margin-top: 7px; text-align: left; }
    .journal-header-grid { grid-template-columns: 1fr 1fr; }
    .journal-field-wide { grid-column: 1 / -1; }
    .journal-editor-footer { display: grid; grid-template-columns: 1fr; }
    .journal-editor-footer > div { flex-wrap: wrap; }
    .journal-view-summary,
    .journal-audit-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
    .journal-control-note { display: block; }
    .journal-control-icon { margin-bottom: 12px; }
    .journal-summary-grid,
    .journal-filter-grid,
    .journal-header-grid,
    .journal-view-summary,
    .journal-audit-grid { grid-template-columns: 1fr; }
    .journal-filter-search,
    .journal-field-wide,
    .journal-audit-wide { grid-column: auto; }
    .journal-filter-actions { display: grid; grid-template-columns: 1fr 1fr; }
    .journal-form-section { padding: 18px 16px; }
    .journal-balance-bar { grid-template-columns: auto 1fr; }
    .journal-balance-bar output { grid-column: 1 / -1; }
    .journal-lines-heading { display: block; }
    .journal-lines-heading > span { display: inline-flex; margin-top: 9px; }
    .journal-view-dialog .ui-dialog-footer > div { display: grid; width: 100%; }
}

/* Simplified journal editor: one side + one amount per line. */
.journal-main-grid,
.journal-advanced-grid,
.journal-line-main-grid,
.journal-line-optional-grid {
    display: grid;
    gap: 14px;
}
.journal-main-grid { grid-template-columns: minmax(150px, .7fr) minmax(280px, 1.7fr) minmax(210px, 1fr); }
.journal-advanced-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 16px; }
.journal-line-main-grid { grid-template-columns: minmax(280px, 2fr) minmax(150px, .8fr) minmax(170px, 1fr); }
.journal-line-optional-grid { grid-template-columns: minmax(220px, .8fr) minmax(300px, 1.5fr); padding-top: 12px; }
.journal-main-grid > label,
.journal-advanced-grid > label,
.journal-line-main-grid > label,
.journal-line-optional-grid > label {
    min-width: 0;
    display: grid;
    align-content: start;
    gap: 6px;
    color: var(--text-soft);
    font-size: 12px;
    font-weight: 600;
}
.journal-main-grid label > span em,
.journal-line-main-grid label > span em { color: var(--danger); font-style: normal; }
.journal-main-grid label small,
.journal-advanced-grid label small,
.journal-line-optional-grid label small { color: var(--text-muted); font-size: 11px; font-weight: 400; }

.journal-advanced-details {
    margin-top: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface-muted);
    overflow: hidden;
}
.journal-advanced-details > summary {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 11px 14px;
    cursor: pointer;
    color: var(--text-soft);
    list-style: none;
    font-size: 12px;
    font-weight: 700;
}
.journal-advanced-details > summary::-webkit-details-marker,
.journal-line-optional > summary::-webkit-details-marker { display: none; }
.journal-advanced-details > summary span { display: flex; align-items: center; gap: 8px; }
.journal-advanced-details > summary svg { width: 16px; height: 16px; color: var(--primary); }
.journal-advanced-details > summary small { color: var(--text-muted); font-size: 11px; font-weight: 400; }
.journal-advanced-details[open] > summary { border-bottom: 1px solid var(--border); background: var(--surface); }
[data-cash-flow-field].is-required-context {
    padding: 10px;
    margin: -10px;
    border: 1px solid var(--warning-border);
    border-radius: var(--radius-md);
    background: var(--warning-soft);
}

.journal-line-cards { display: grid; gap: 12px; }
.journal-line-card {
    padding: 15px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary-border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-xs);
    transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.journal-line-card:hover { border-color: var(--primary-border); box-shadow: var(--shadow-sm); }
.journal-line-card.is-debit { border-left-color: var(--primary); }
.journal-line-card.is-credit { border-left-color: var(--success); }
.journal-line-card.has-errors { border-color: var(--danger-border); background: var(--danger-soft); }
.journal-line-card input[type='checkbox'][name$='-DELETE'] { display: none; }
.journal-line-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.journal-line-card-header > div { display: grid; gap: 3px; }
.journal-line-number { color: var(--text); font-size: 11px; font-weight: 800; }
.journal-line-card-header small { color: var(--text-muted); font-size: 11px; }
.journal-line-card-header .icon-button:disabled { opacity: .32; cursor: not-allowed; }

.journal-line-optional {
    margin-top: 12px;
    border-top: 1px dashed var(--border);
}
.journal-line-optional > summary {
    width: fit-content;
    padding-top: 10px;
    cursor: pointer;
    color: var(--primary);
    list-style: none;
    font-size: 11px;
    font-weight: 700;
}
.journal-line-optional > summary::after { content: ' +'; }
.journal-line-optional[open] > summary::after { content: ' -'; }
.journal-line-error { display: block; margin-top: 10px; }

.journal-line-add-row {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 14px;
}
.journal-line-add-row p { margin: 0; color: var(--text-muted); font-size: 11px; }
.journal-totals {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 16px;
}
.journal-totals > div {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
}
.journal-totals span,
.journal-totals strong { display: block; }
.journal-totals span { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.journal-totals strong { margin-top: 4px; color: var(--text); font-size: 15px; font-variant-numeric: tabular-nums; }
.journal-totals > div:last-child strong { color: var(--warning); }
.journal-totals.is-balanced > div:last-child strong { color: var(--success); }

@media (max-width: 980px) {
    .journal-main-grid { grid-template-columns: 1fr 2fr; }
    .journal-main-grid > label:last-child { grid-column: 1 / -1; }
    .journal-advanced-grid { grid-template-columns: 1fr 1fr; }
    .journal-advanced-grid > label:last-child { grid-column: 1 / -1; }
    .journal-line-main-grid { grid-template-columns: minmax(240px, 1.5fr) 150px 170px; }
}

@media (max-width: 720px) {
    .journal-main-grid,
    .journal-advanced-grid,
    .journal-line-main-grid,
    .journal-line-optional-grid,
    .journal-totals { grid-template-columns: 1fr; }
    .journal-main-grid > label:last-child,
    .journal-advanced-grid > label:last-child { grid-column: auto; }
    .journal-advanced-details > summary { align-items: flex-start; flex-direction: column; gap: 4px; }
    .journal-line-add-row { align-items: flex-start; flex-direction: column; }
    .journal-line-add-row .button { width: 100%; }
}

/* Controlled finance lifecycle inputs remain compact inside row actions. */
.row-actions .row-action-form {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.row-actions .row-action-form input {
    width: 124px;
    min-height: 34px;
    padding: 6px 8px;
    font-size: 0.78rem;
}
.row-actions .row-action-form input[type="date"],
.row-actions .row-action-form input[type="number"] {
    width: 118px;
}
@media (max-width: 1100px) {
    .row-actions { flex-wrap: wrap; }
}

/* Compact forms: keep required/important fields prominent and move the rest
   into a single optional section without removing existing capabilities. */
.compact-form-additional {
    grid-column: 1 / -1;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-muted);
    overflow: hidden;
}

.compact-form-additional > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 13px 15px;
    cursor: pointer;
    list-style: none;
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
}

.compact-form-additional > summary::-webkit-details-marker { display: none; }
.compact-form-additional > summary::after {
    content: '+';
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-soft);
    font-size: 16px;
    line-height: 1;
}
.compact-form-additional[open] > summary::after { content: '−'; }
.compact-form-additional > summary small {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 400;
}

.compact-form-additional-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 15px;
    padding: 15px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.compact-form-additional-grid > label {
    min-width: 0;
    display: grid;
    align-content: start;
    gap: 6px;
    color: var(--text-soft);
    font-size: 11px;
    font-weight: 500;
}
.compact-form-additional-grid > label > span { color: var(--text-soft); }
.compact-form-additional-grid > label small {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 400;
}
.compact-form-additional-grid > label > em:not(.required-marker) {
    color: var(--danger);
    font-size: 11px;
    font-style: normal;
}
.compact-form-additional-grid > label.field-checkbox {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px 12px;
    padding: 11px 12px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 9px;
}
.required-marker {
    margin-left: 3px;
    color: var(--danger);
    font-style: normal;
}

@media (max-width: 720px) {
    .compact-form-additional > summary {
        align-items: flex-start;
        flex-wrap: wrap;
    }
    .compact-form-additional > summary small {
        order: 3;
        width: 100%;
        margin-left: 0;
    }
    .compact-form-additional-grid { grid-template-columns: 1fr; }
    .compact-form-additional-grid .field-span-2 { grid-column: auto; }
}
