/*
 * ConsicaMS system-wide UI modernization layer.
 *
 * This stylesheet is deliberately presentation-only. It consolidates the
 * density, typography, spacing, responsiveness, and interaction rules used by
 * every Django screen while leaving routes, permissions, forms, APIs, models,
 * and business workflows unchanged.
 */

/* --------------------------------------------------------------------------
   Shared rhythm and readable density
   -------------------------------------------------------------------------- */

:root {
    --ui-page-gutter: clamp(18px, 2.2vw, 32px);
    --ui-page-gap: 20px;
    --ui-section-gap: 18px;
    --ui-card-padding: 18px;
    --ui-card-padding-compact: 14px;
    --ui-control-radius: 8px;
    --ui-card-radius: var(--radius-lg);
    --ui-muted-font-size: 11px;
    --ui-label-font-size: 12px;
    --ui-table-font-size: 12px;
    --ui-table-row-height: 44px;
}

html {
    overflow-x: hidden;
}

body.app-shell,
body:not(.auth-page) {
    background: var(--bg);
}

body {
    line-height: 1.5;
}

:where(h1, h2, h3, h4, p) {
    overflow-wrap: anywhere;
}

:where(.page-content, .panel, .card, .metric-card, .ui-dialog-shell, .table-wrap, .form-grid, .form-stack) {
    min-width: 0;
}

.page-content {
    display: grid;
    align-content: start;
    gap: var(--ui-page-gap);
    padding: 20px var(--ui-page-gutter) 44px;
}

.page-content > * {
    min-width: 0;
    margin-block: 0;
}

:where(.dashboard-grid, .metric-grid, .card-grid, .stats-grid, .content-grid, .panel-grid,
       .analytics-chart-grid, .chart-grid, .school-metric-grid, .school-card-grid,
       .school-detail-grid, .task-metric-grid, .task-performance-grid, .crm-command-strip,
       .crm-customer-grid, .crm-customer-kpis, .journal-summary-grid) {
    gap: var(--ui-section-gap);
    margin-block: 0;
}

.eyebrow,
.nav-heading,
.nav-section-label,
th,
.metric-card small,
.premium-metric-card small,
.task-metric small,
.crm-metric > span,
.financial-statement-meta small,
.journal-view-summary small,
.journal-audit-grid small,
.journal-totals span {
    font-size: 11px;
    line-height: 1.35;
    letter-spacing: .07em;
}

:where(.page-description, .panel-header p:not(.eyebrow), .ui-dialog-header p:not(.eyebrow),
       .metric-card p, .premium-metric-card p, .task-metric span, .empty-state p,
       .form-status, .flash, .app-toast, .confirm-copy p, .journal-section-heading p,
       .journal-accounting-reminder, .journal-immutable-note, .journal-line-add-row p,
       .file-picker-copy small, .auth-card small, .muted) {
    font-size: 12px;
    line-height: 1.55;
}

:where(label small, label em, .form-stack small, .dialog-form label small,
       .dialog-form label em, .field-error, td small, .compact-row small,
       .search-result small, .module-card small, .document-card small,
       .note-card small, .provider-card small, .school-card small,
       .crm-opportunity-card small, .crm-followup-item small) {
    font-size: 11px;
    line-height: 1.45;
}

/* --------------------------------------------------------------------------
   Application shell
   -------------------------------------------------------------------------- */

.app-sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-deep) 100%);
    box-shadow: 12px 0 30px rgba(2, 12, 28, .06);
}

.app-sidebar::after {
    opacity: .32;
}

.sidebar-brand {
    min-height: 74px;
    gap: 12px;
    padding: 15px 16px;
}

.sidebar-brand .brand-logo {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    box-shadow: 0 5px 14px rgba(0, 0, 0, .14);
}

.sidebar-brand strong {
    font-size: 13px;
}

.sidebar-brand small {
    margin-top: 2px;
    font-size: 11px;
}

.sidebar-nav {
    padding: 10px 9px 14px;
}

.nav-heading,
.nav-section-label {
    margin: 16px 10px 6px;
    padding: 0;
    color: var(--sidebar-muted);
}

.nav-link {
    min-height: 40px;
    gap: 10px;
    margin: 1px 0;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 12px;
}

.nav-child-link {
    min-height: 36px;
    padding-block: 7px;
    font-size: 11px;
}

.nav-link:hover {
    transform: none;
}

.nav-link.active,
.nav-group.is-active > .nav-group-toggle {
    background: rgba(9, 89, 200, .38);
    border-color: rgba(126, 181, 255, .18);
    box-shadow: inset 3px 0 0 #72b1ff;
}

.sidebar-footer {
    padding: 9px 10px calc(10px + env(safe-area-inset-bottom));
}

.user-chip {
    padding: 10px 8px 3px;
}

.user-chip strong {
    font-size: 11px;
}

.user-chip small {
    font-size: 11px;
}

.app-main {
    min-width: 0;
}

.page-topbar {
    min-height: var(--topbar-height);
    gap: 18px;
    padding: 13px var(--ui-page-gutter);
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.page-topbar.is-scrolled {
    box-shadow: 0 5px 18px rgba(15, 23, 42, .055);
}

.page-heading {
    gap: 3px;
}

.page-breadcrumb {
    gap: 5px;
    font-size: 11px;
    letter-spacing: .05em;
}

.page-topbar h1 {
    max-width: 960px;
    font-size: clamp(21px, 2vw, 27px);
    line-height: 1.18;
    letter-spacing: -.03em;
}

.page-description {
    max-width: 820px;
    margin-top: 1px;
    color: var(--text-muted);
}

.topbar-actions,
.page-actions {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.page-actions:empty {
    display: none;
}

.toggle {
    width: var(--control-height);
    height: var(--control-height);
    border-radius: var(--ui-control-radius);
    box-shadow: none;
}

.flash-stack {
    top: calc(var(--topbar-height) + 10px);
    left: calc(var(--sidebar-width) + var(--ui-page-gutter));
}

.flash {
    max-width: min(480px, calc(100vw - var(--sidebar-width) - 56px));
    padding: 11px 14px;
    border-radius: 10px;
}

/* --------------------------------------------------------------------------
   Panels, cards, and information hierarchy
   -------------------------------------------------------------------------- */

.panel,
.form-panel,
.table-card,
.content-card,
.metric-card,
.premium-metric-card,
.task-metric,
.crm-metric,
.school-card,
.document-card,
.note-card,
.provider-card,
.module-card,
.premium-chart-card,
.analytics-chart-panel {
    border-color: var(--border);
    border-radius: var(--ui-card-radius);
    box-shadow: var(--shadow-xs);
}

.panel {
    overflow: clip;
}

.panel-header {
    min-height: 62px;
    align-items: center;
    gap: 16px;
    padding: 14px var(--ui-card-padding);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.panel-header h2,
.section-title {
    margin-top: 2px;
    font-size: 16px;
    line-height: 1.3;
    letter-spacing: -.02em;
}

.panel-header p:not(.eyebrow) {
    max-width: 820px;
    margin-top: 4px;
}

.metric-grid,
.school-metric-grid,
.task-metric-grid,
.crm-command-strip {
    margin-bottom: 0;
}

.metric-card,
.premium-metric-card,
.task-metric,
.crm-metric {
    min-height: 82px;
    gap: 10px;
    padding: 12px 13px;
    background: var(--surface);
    overflow: hidden;
    transition: border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}

.metric-card::after,
.premium-metric-card::after,
.analytics-intro::before,
.dashboard-intro::before {
    display: none;
}

.metric-card:hover,
.premium-metric-card:hover,
.task-metric:hover,
.crm-metric:hover,
.document-card:hover,
.note-card:hover,
.module-card:hover,
.task-performance-grid article:hover,
.info-grid > div:hover,
.financial-report-link:hover {
    transform: none;
    border-color: var(--border-strong);
    box-shadow: var(--shadow);
}

.metric-icon,
.premium-metric-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    box-shadow: none;
}

.metric-card strong,
.premium-metric-card strong,
.task-metric strong,
.crm-metric strong {
    margin-top: 2px;
    font-size: clamp(17px, 1.3vw, 20px);
    line-height: 1.2;
}

.metric-card p,
.premium-metric-card p {
    margin-top: 4px;
}

.analytics-intro,
.dashboard-intro,
.context-banner,
.school-hero,
.crm-customer-hero,
.journal-control-note {
    margin-bottom: 0;
    padding: 18px 20px;
    background: color-mix(in srgb, var(--primary-soft) 32%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--primary) 14%, var(--border));
    border-radius: var(--ui-card-radius);
    box-shadow: var(--shadow-xs);
}

.analytics-intro h2,
.dashboard-intro h2 {
    margin: 3px 0 6px;
    font-size: clamp(20px, 1.8vw, 25px);
}

.analytics-intro p:not(.eyebrow),
.dashboard-intro p:not(.eyebrow) {
    max-width: 820px;
    font-size: 13px;
    line-height: 1.6;
}

/* --------------------------------------------------------------------------
   Buttons and action groups
   -------------------------------------------------------------------------- */

.button {
    min-height: var(--control-height);
    gap: 7px;
    padding: 8px 13px;
    border-radius: var(--ui-control-radius);
    font-size: 12px;
    line-height: 1.2;
    box-shadow: none;
}

.button:hover:not(:disabled) {
    transform: none;
}

.button-primary {
    color: var(--primary-contrast);
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: none;
}

.button-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    box-shadow: none;
}

.button-secondary {
    background: var(--surface);
    border-color: var(--border-strong);
}

.button-danger,
.button-success {
    box-shadow: none;
}

.button-compact,
.button-small,
.button-sm {
    min-height: var(--control-height-sm);
    padding: 6px 10px;
    font-size: 11px;
}

.icon-button {
    width: 36px;
    height: 36px;
    border-radius: var(--ui-control-radius);
}

.icon-button:hover {
    transform: none;
}

:where(.topbar-actions, .page-actions, .form-actions, .table-actions, .card-actions,
       .toolbar, .action-row, .inline-actions, .row-actions, .ui-dialog-footer) {
    gap: 8px;
}

.form-actions {
    align-items: center;
    flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   Forms, search, filters, and validation
   -------------------------------------------------------------------------- */

.form-grid {
    gap: 15px;
    padding: var(--ui-card-padding);
}

.form-stack {
    gap: 14px;
}

.form-panel > .form-stack,
.crud-form > .form-stack {
    padding: var(--ui-card-padding);
}

.form-grid label,
.form-stack label,
.dialog-form .ui-dialog-body > label,
.financial-report-filter label,
.form-field,
.journal-main-grid > label,
.journal-advanced-grid > label,
.journal-line-main-grid > label,
.journal-line-optional-grid > label {
    gap: 6px;
    color: var(--text-soft);
    font-size: var(--ui-label-font-size);
    font-weight: 600;
}

input,
select,
textarea,
.custom-select-trigger {
    min-height: var(--control-height);
    padding: 8px 10px;
    border-color: var(--border-strong);
    border-radius: var(--ui-control-radius);
    font-size: 13px;
    line-height: 1.35;
}

textarea {
    min-height: 96px;
}

input:hover:not(:disabled):not([readonly]),
select:hover:not(:disabled),
textarea:hover:not(:disabled):not([readonly]),
.custom-select-trigger:hover {
    border-color: color-mix(in srgb, var(--primary) 25%, var(--border-strong));
}

input:focus,
select:focus,
textarea:focus,
.custom-select-trigger:focus-visible {
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}

.form-error-summary,
.field-error,
label em {
    font-size: 11px;
}

.field-checkbox,
.form-grid label.field-checkbox,
.dialog-form .ui-dialog-body > label.field-checkbox {
    min-height: 44px;
    padding: 10px 12px;
    border-radius: var(--ui-control-radius);
}

.filter-bar,
.task-filter-bar,
.financial-report-filter,
.journal-filter-grid {
    display: flex;
    align-items: end;
    gap: 10px;
    flex-wrap: wrap;
    padding: 13px var(--ui-card-padding);
    background: var(--surface-muted);
    border-bottom: 1px solid var(--border);
}

.filter-bar > *,
.task-filter-bar > *,
.financial-report-filter > *,
.journal-filter-grid > * {
    min-width: 0;
}

.filter-bar .search-field,
.task-filter-bar .search-field,
.journal-filter-search {
    flex: 1 1 280px;
}

.filter-bar select,
.filter-bar .custom-select,
.task-filter-bar select,
.task-filter-bar .custom-select,
.financial-report-filter select,
.financial-report-filter .custom-select {
    width: auto;
    min-width: 160px;
    flex: 0 1 220px;
}

.search-field svg {
    top: 11px;
}

.file-picker {
    min-height: 68px;
    padding: 11px;
    border-radius: var(--ui-control-radius);
}

.file-picker-copy strong {
    font-size: 12px;
}

.custom-select-menu {
    border-radius: 10px;
    box-shadow: var(--shadow-md);
}

.custom-select-option {
    min-height: 38px;
    font-size: 12px;
}

/* --------------------------------------------------------------------------
   Data tables, lists, pagination, and status
   -------------------------------------------------------------------------- */

.table-wrap {
    width: 100%;
    overflow: auto;
    overscroll-behavior-inline: contain;
    scrollbar-gutter: stable;
}

.table-wrap.has-overflow {
    box-shadow: inset -12px 0 16px -18px rgba(15, 23, 42, .42);
}

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

th {
    height: 38px;
    padding: 9px 12px;
    color: var(--text-muted);
    background: var(--surface-muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .055em;
}

td {
    min-height: var(--ui-table-row-height);
    padding: 10px 12px;
    color: var(--text-soft);
    font-size: var(--ui-table-font-size);
    line-height: 1.45;
}

td strong {
    font-size: 12px;
    line-height: 1.4;
}

tbody tr:hover td {
    background: color-mix(in srgb, var(--primary-soft) 28%, var(--surface));
}

.row-actions {
    gap: 4px;
    flex-wrap: wrap;
}

.row-actions .row-action-form {
    gap: 5px;
}

.row-actions .row-action-form input,
.row-actions .row-action-form input[type="date"],
.row-actions .row-action-form input[type="number"] {
    min-height: 34px;
    width: 118px;
    padding: 6px 8px;
    font-size: 11px;
}

.status-badge,
.crm-stage-pill,
.crm-detail-badges span {
    min-height: 24px;
    padding: 3px 8px;
    font-size: 11px;
    line-height: 1.25;
}

.compact-list,
.activity-list,
.notification-list,
.search-results {
    gap: 8px;
}

.compact-row,
.activity-list article,
.notification-list article,
.search-result {
    min-height: 48px;
    padding: 11px 13px;
}

.pagination-bar {
    min-height: 54px;
    gap: 12px;
    padding: 10px var(--ui-card-padding);
    color: var(--text-muted);
    font-size: 12px;
    background: var(--surface-muted);
    border-top: 1px solid var(--border);
}

.pagination-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --------------------------------------------------------------------------
   Tabs, sub-navigation, and secondary navigation
   -------------------------------------------------------------------------- */

.subnav,
.dashboard-analytics-tabs {
    gap: 4px;
    margin: 0;
    padding: 5px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-xs);
    scrollbar-width: thin;
}

.subnav a,
.dashboard-analytics-tab {
    min-height: 36px;
    padding: 7px 10px;
    border-radius: 7px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.subnav a:hover,
.subnav a.active,
.dashboard-analytics-tab:hover,
.dashboard-analytics-tab.is-active {
    color: var(--primary);
    background: var(--primary-soft);
    box-shadow: none;
}

/* --------------------------------------------------------------------------
   Dialogs, notifications, and empty states
   -------------------------------------------------------------------------- */

.ui-dialog {
    padding: 18px;
}

.ui-dialog-shell {
    max-height: min(90dvh, 840px);
    border-radius: var(--ui-card-radius);
    box-shadow: var(--shadow-lg);
}

.ui-dialog-header {
    min-height: 64px;
    align-items: center;
    gap: 14px;
    padding: 14px 17px;
    background: var(--surface);
}

.ui-dialog-header h2 {
    font-size: 17px;
}

.ui-dialog-body,
.ui-dialog-body.form-grid {
    padding: 17px;
}

.dialog-form .ui-dialog-body {
    gap: 14px;
}

.ui-dialog-footer {
    min-height: 58px;
    padding: 10px 17px;
    background: var(--surface-muted);
    box-shadow: none;
}

.confirm-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
}

.app-toast {
    min-height: 50px;
    padding: 10px 12px;
    border-radius: 10px;
}

.empty-state {
    max-width: 680px;
    padding: 32px 20px;
}

.empty-state-visual {
    width: 46px;
    height: 46px;
    margin-bottom: 12px;
    border-radius: 13px;
    box-shadow: none;
}

.empty-state h3 {
    margin-bottom: 6px;
    font-size: 15px;
}

.empty-state.compact {
    padding: 24px 14px;
}


.progress-track > i,
.progress-track > span,
.crm-wip-meter > i {
    width: var(--progress-value, 0%);
}

/* --------------------------------------------------------------------------
   Dashboard and analytics
   -------------------------------------------------------------------------- */

.dashboard-analytics-tabs {
    position: sticky;
    top: calc(var(--topbar-height) + 8px);
    z-index: 12;
    overflow-x: auto;
}

.dashboard-analytics-tab svg {
    width: 16px;
    height: 16px;
}

.analytics-chart-panel,
.premium-chart-card {
    background: var(--surface);
}

.premium-chart-header {
    min-height: 64px;
    padding: 13px 16px;
    background: var(--surface);
}

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

.chart-info-button,
.chart-report-button {
    width: 34px;
    height: 34px;
    box-shadow: none;
}

.financial-report-links {
    gap: 10px;
}

.financial-report-link {
    min-height: 66px;
    padding: 12px 13px;
    background: var(--surface);
    border-radius: 10px;
}

/* --------------------------------------------------------------------------
   Finance and journal screens
   -------------------------------------------------------------------------- */

.financial-statement-header,
.financial-statement-section,
.financial-report-panel {
    box-shadow: var(--shadow-xs);
}

.financial-statement-meta {
    gap: 1px;
    background: var(--border);
}

.financial-statement-meta span {
    padding: 10px 13px;
}

.financial-statement-table th,
.financial-statement-table td {
    padding-inline: 13px;
}

.statement-lines > div,
.financial-statement-result,
.financial-analysis-summary,
.financial-analysis-section,
.financial-analysis-quality,
.financial-analysis-error {
    border-radius: 10px;
}

.journal-control-note {
    gap: 14px;
}

.journal-summary-grid {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.journal-form-section {
    padding: 17px;
}

.journal-section-heading {
    gap: 16px;
    margin-bottom: 14px;
}

.journal-main-grid,
.journal-advanced-grid,
.journal-line-main-grid,
.journal-line-optional-grid {
    gap: 12px;
}

.journal-advanced-grid {
    padding: 14px;
}

.journal-advanced-details {
    margin-top: 14px;
    border-radius: 10px;
}

.journal-advanced-details > summary {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 12px;
}

.journal-advanced-details > summary small,
.journal-main-grid label small,
.journal-advanced-grid label small,
.journal-line-optional-grid label small,
.journal-line-card-header small,
.journal-line-optional > summary,
.journal-totals span,
.journal-view-summary small,
.journal-audit-grid small {
    font-size: 11px;
}

.journal-line-cards {
    gap: 10px;
}

.journal-line-card {
    padding: 13px;
    border-left-width: 3px;
    border-radius: 10px;
    box-shadow: none;
}

.journal-line-card:hover {
    transform: none;
    box-shadow: var(--shadow-xs);
}

.journal-line-card-header {
    margin-bottom: 10px;
}

.journal-line-number {
    font-size: 12px;
}

.journal-line-optional-grid {
    padding-top: 10px;
}

.journal-totals {
    gap: 8px;
    margin-top: 13px;
}

.journal-totals > div,
.journal-view-summary > div,
.journal-audit-grid > div {
    padding: 10px 12px;
    border-radius: 9px;
}

.journal-view-summary strong,
.journal-audit-grid strong {
    font-size: 12px;
}

/* --------------------------------------------------------------------------
   CRM, school, tasks, operations, and IAM
   -------------------------------------------------------------------------- */

.crm-command-strip,
.school-metric-grid,
.task-metric-grid-expanded {
    grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
}

.crm-metric,
.task-metric {
    min-height: 86px;
}

.crm-pipeline-column,
.crm-opportunity-card,
.crm-followup-item,
.crm-stage-settings-list article,
.task-pipeline-cards article,
.task-performance-grid article,
.school-card,
.school-profile-list > div,
.school-card-stats > div,
.crm-customer-kpis article {
    border-radius: 10px;
}

.crm-pipeline-column {
    background: var(--surface-muted);
}

.crm-opportunity-card,
.crm-followup-item,
.school-card,
.task-performance-grid article {
    padding: 13px;
    box-shadow: none;
}

.crm-detail-header,
.school-hero,
.crm-customer-hero {
    min-height: auto;
}

.crm-detail-body,
.school-detail-grid,
.task-pipeline-layout,
.crm-settings-layout {
    gap: var(--ui-section-gap);
}

.task-list-header {
    min-height: 54px;
    border-radius: 9px;
    box-shadow: none;
}

.task-list-header:hover {
    box-shadow: var(--shadow-xs);
}

.permission-matrix-wrap {
    max-height: min(70vh, 760px);
}

.permission-matrix th:first-child,
.permission-matrix td:first-child {
    min-width: 220px;
}

.checkbox-grid {
    gap: 9px;
    padding: 15px;
}

.checkbox-grid > label {
    min-height: 52px;
    padding: 10px;
    border-radius: 9px;
}

.prose-panel,
.info-grid > div,
.requirement-box,
.summary-package,
.installment-card,
.revenue-grid > div {
    padding: var(--ui-card-padding);
}

/* --------------------------------------------------------------------------
   Agent and authentication
   -------------------------------------------------------------------------- */

.agent-panel {
    width: var(--agent-width);
    box-shadow: -16px 0 42px rgba(15, 23, 42, .12);
}

.agent-header {
    min-height: 72px;
    padding: 13px 16px;
    background: var(--surface);
}

.agent-scope {
    padding: 9px 16px;
}

.agent-messages {
    padding: 15px;
}

.agent-composer {
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
}

.agent-welcome {
    margin-top: 48px;
}

.auth-page {
    padding: 22px;
    background: var(--bg);
}

.auth-page::before {
    display: none;
}

.auth-shell {
    width: min(1000px, 100%);
    min-height: 560px;
    grid-template-columns: 1fr .86fr;
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
}

.auth-intro {
    padding: clamp(36px, 5vw, 58px);
    background: linear-gradient(145deg, #08234a, #04152e 72%);
}

.auth-intro::after {
    opacity: .45;
}

.auth-intro h1 {
    max-width: 580px;
    margin-top: 24px;
    font-size: clamp(31px, 4vw, 46px);
    line-height: 1.08;
}

.auth-intro p:not(.eyebrow) {
    font-size: 13px;
    line-height: 1.65;
}

.auth-meta {
    padding-top: 40px;
}

.auth-card {
    gap: 24px;
    padding: clamp(30px, 4vw, 48px);
}

.auth-card h2 {
    font-size: 27px;
}

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

@media (max-width: 1280px) {
    :root {
        --sidebar-width: 244px;
        --agent-width: 380px;
        --ui-page-gutter: 22px;
    }

    .page-topbar h1 {
        font-size: 23px;
    }
}

@media (max-width: 1024px) {
    :root {
        --ui-page-gap: 18px;
        --ui-section-gap: 15px;
    }

    .page-topbar {
        align-items: flex-start;
    }

    .topbar-actions {
        max-width: 46%;
    }

    .metric-grid,
    .school-metric-grid,
    .task-metric-grid,
    .crm-command-strip {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .chart-grid,
    .analytics-chart-grid,
    .premium-chart-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 820px) {
    :root {
        --ui-page-gutter: 16px;
        --ui-page-gap: 16px;
        --ui-section-gap: 14px;
    }

    .page-content {
        padding: 16px var(--ui-page-gutter) 36px;
    }

    .mobile-topbar {
        min-height: 60px;
        padding-inline: 12px;
    }

    .page-topbar {
        position: static;
        min-height: auto;
        display: grid;
        gap: 12px;
        padding: 15px var(--ui-page-gutter);
    }

    .topbar-actions,
    .page-actions {
        width: 100%;
        max-width: none;
        justify-content: flex-start;
    }

    .topbar-actions .button,
    .page-actions .button {
        flex: 0 1 auto;
    }

    .flash-stack {
        top: 70px;
        left: 14px;
        right: 14px;
    }

    .flash {
        max-width: none;
    }

    .dashboard-analytics-tabs {
        top: 8px;
    }

    .panel-header {
        align-items: flex-start;
    }

    .filter-bar,
    .task-filter-bar,
    .financial-report-filter,
    .journal-filter-grid {
        align-items: stretch;
    }

    .filter-bar > .button,
    .task-filter-bar > .button,
    .financial-report-filter > .button {
        flex: 0 0 auto;
    }

    .ui-dialog {
        padding: 0;
    }

    .ui-dialog-shell {
        max-height: 94dvh;
        border-radius: 15px 15px 0 0;
    }

    .agent-panel {
        width: min(100%, 430px);
    }

    .table-wrap > table:not(.permission-matrix) {
        min-width: 720px;
    }

    .table-wrap > table.financial-statement-table {
        min-width: 620px;
    }
}

@media (max-width: 620px) {
    :root {
        --ui-page-gutter: 12px;
        --ui-page-gap: 14px;
        --ui-section-gap: 12px;
        --ui-card-padding: 15px;
    }

    .page-topbar h1 {
        font-size: 21px;
    }

    .page-description {
        font-size: 11px;
    }

    .topbar-actions {
        display: flex;
        align-items: stretch;
        width: 100%;
    }

    .page-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        flex: 1 1 100%;
        width: 100%;
    }

    .page-actions > *,
    .topbar-actions > .agent-toggle {
        width: 100%;
    }

    .topbar-actions > .agent-toggle {
        flex: 1 1 100%;
    }

    .form-actions,
    .ui-dialog-footer {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
    }

    .form-actions > *,
    .ui-dialog-footer > * {
        width: 100%;
    }

    .topbar-actions .toggle {
        width: var(--control-height);
    }

    .metric-grid,
    .school-metric-grid,
    .task-metric-grid,
    .crm-command-strip,
    .journal-summary-grid {
        grid-template-columns: 1fr;
    }

    .form-grid,
    .dialog-form .ui-dialog-body,
    .journal-main-grid,
    .journal-advanced-grid,
    .journal-line-main-grid,
    .journal-line-optional-grid,
    .journal-totals {
        grid-template-columns: 1fr;
    }

    .field-span-2,
    .field-span-3,
    .journal-field-wide,
    .journal-audit-wide {
        grid-column: auto;
    }

    .filter-bar,
    .task-filter-bar,
    .financial-report-filter,
    .journal-filter-grid {
        display: grid;
        grid-template-columns: 1fr;
    }

    .filter-bar .search-field,
    .filter-bar select,
    .filter-bar .custom-select,
    .task-filter-bar .search-field,
    .task-filter-bar select,
    .task-filter-bar .custom-select,
    .financial-report-filter select,
    .financial-report-filter .custom-select {
        width: 100%;
        min-width: 0;
    }

    .filter-bar > .button,
    .task-filter-bar > .button,
    .financial-report-filter > .button {
        width: 100%;
    }

    th,
    td {
        padding-inline: 10px;
    }

    .pagination-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .pagination-bar > .pagination-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
    }

    .pagination-bar > .pagination-actions .button {
        width: 100%;
    }

    .auth-page {
        padding: 12px;
    }

    .auth-shell {
        min-height: auto;
        border-radius: 15px;
    }

    .auth-card {
        padding: 28px 20px;
    }
}

@media (max-width: 420px) {
    .form-actions,
    .ui-dialog-footer {
        grid-template-columns: 1fr;
    }

    .metric-card,
    .premium-metric-card,
    .task-metric,
    .crm-metric {
        min-height: 80px;
    }

    .panel-header {
        display: grid;
    }

    .panel-header > .button,
    .panel-header > a.button,
    .panel-header > form,
    .panel-header > form .button {
        width: 100%;
    }
}

@media (hover: none) {
    .metric-card:hover,
    .premium-metric-card:hover,
    .task-metric:hover,
    .crm-metric:hover,
    .document-card:hover,
    .note-card:hover,
    .module-card:hover,
    .task-performance-grid article:hover,
    .info-grid > div:hover,
    .financial-report-link:hover {
        border-color: var(--border);
        box-shadow: var(--shadow-xs);
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

/* --------------------------------------------------------------------------
   Compact metric flow
   --------------------------------------------------------------------------
   Icon metrics use normal document flow instead of a permanent two-column
   layout. The icon floats beside the label and value; once those lines reach
   the icon's lower edge, supporting copy naturally uses the space underneath.
   This removes the empty icon column without forcing the description into a
   separate full-width row and keeps KPI cards compact on every screen.
*/
.metric-card {
    display: flow-root;
    min-height: 82px;
    padding: 12px 13px;
}

.metric-card > .metric-icon {
    width: 32px;
    height: 32px;
    float: left;
    margin: 0 10px 2px 0;
    border-radius: 8px;
}

.metric-card > .metric-icon svg {
    width: 16px;
    height: 16px;
}

.metric-card > .metric-icon + div,
.metric-card > div:only-child {
    min-width: 0;
    display: block;
}

.metric-card > .metric-icon + div > small,
.metric-card > .metric-icon + div > .metric-label,
.metric-card > .metric-icon + div > strong,
.metric-card > .metric-icon + div > .metric-value,
.metric-card > .metric-icon + div > p,
.metric-card > .metric-icon + div > .metric-detail {
    min-width: 0;
}

.metric-card > .metric-icon + div > strong,
.metric-card > .metric-icon + div > .metric-value {
    margin-top: 2px;
}

.metric-card > .metric-icon + div > p,
.metric-card > .metric-icon + div > .metric-detail {
    width: auto;
    margin-top: 4px;
    text-align: left;
}

/* --------------------------------------------------------------------------
   Compact filter and action controls
   --------------------------------------------------------------------------
   Filter selects size to the currently visible label instead of inheriting a
   fixed minimum width or flexible basis. Horizontal action groups also keep
   their buttons intrinsic. Small-screen layouts below 620px remain full width
   for touch comfort and predictable stacking.
*/
@media (min-width: 621px) {
    :where(
        .filter-bar,
        .task-filter-bar,
        .financial-report-filter,
        .journal-filter-grid
    ) > :not(.search-field):not(.journal-filter-search):not(input[type="hidden"]) {
        width: auto;
        min-width: 0;
        flex: 0 0 auto;
    }

    :where(
        .filter-bar,
        .task-filter-bar,
        .financial-report-filter,
        .journal-filter-grid,
        .school-filter-grid
    ) select:not(.select-native) {
        width: auto;
        min-width: 0;
        max-width: 22rem;
        flex: 0 0 auto;
        field-sizing: content;
    }

    :where(
        .filter-bar,
        .task-filter-bar,
        .financial-report-filter,
        .journal-filter-grid,
        .school-filter-grid
    ) .custom-select {
        width: fit-content;
        min-width: 0;
        max-width: 100%;
        flex: 0 0 auto;
    }

    :where(
        .filter-bar,
        .task-filter-bar,
        .financial-report-filter,
        .journal-filter-grid,
        .school-filter-grid
    ) .custom-select-trigger {
        width: auto;
        min-width: 0;
        max-width: 22rem;
        justify-content: flex-start;
        gap: 6px;
        padding-inline: 10px;
    }

    :where(
        .filter-bar,
        .task-filter-bar,
        .financial-report-filter,
        .journal-filter-grid,
        .school-filter-grid
    ) .custom-select-trigger > span {
        min-width: 0;
        max-width: 18rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    :where(
        .filter-bar,
        .task-filter-bar,
        .financial-report-filter,
        .journal-filter-grid,
        .school-filter-actions
    ) > .button,
    :where(
        .topbar-actions,
        .page-actions,
        .panel-actions,
        .table-actions,
        .row-actions,
        .form-actions,
        .toolbar,
        .action-row,
        .inline-actions,
        .journal-filter-actions,
        .school-filter-actions,
        .financial-chart-actions,
        .crm-stage-actions,
        .ui-dialog-footer
    ) .button:not(.button-block) {
        width: auto;
        min-width: 0;
        flex: 0 0 auto;
        padding-inline: 11px;
    }

    .crm-filter-bar select,
    .crm-filter-bar .custom-select,
    .task-workflow-controls select:not(.select-native),
    .task-workflow-controls .custom-select {
        width: fit-content;
        min-width: 0;
        flex: 0 0 auto;
    }
}


/* --------------------------------------------------------------------------
   Finance & Accounting: bordered bookkeeping grids
   -------------------------------------------------------------------------- */

.finance-table-wrap {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--surface) 86%, transparent);
}

.finance-table-wrap > .accounting-data-table {
    width: 100%;
    min-width: 760px;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
}

.accounting-data-table > thead > tr > th,
.accounting-data-table > tbody > tr > th,
.accounting-data-table > tbody > tr > td,
.accounting-data-table > tfoot > tr > th,
.accounting-data-table > tfoot > tr > td {
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.accounting-data-table tr > :last-child {
    border-right: 0;
}

.accounting-data-table > thead > tr:first-child > th {
    border-top: 0;
}

.accounting-data-table > thead > tr > th {
    color: var(--text);
    background: var(--surface-strong);
    vertical-align: middle;
}

.accounting-data-table > thead > tr + tr > th {
    background: var(--surface-muted);
}

.accounting-data-table > tbody > tr:nth-child(even):not(.statement-section-row):not(.statement-subtotal-row) > td {
    background: color-mix(in srgb, var(--surface-muted) 46%, var(--surface));
}

.accounting-data-table > tbody > tr:hover > td {
    background: color-mix(in srgb, var(--primary-soft) 44%, var(--surface));
}

.accounting-data-table > tfoot > tr:first-child > * {
    border-top: 2px solid var(--border-strong, var(--border));
}

.accounting-data-table > tfoot > tr:last-child > *,
.accounting-data-table > tbody:last-child > tr:last-child > * {
    border-bottom: 0;
}

.accounting-data-table .amount,
.accounting-data-table th.amount {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Keep every Finance & Accounting column title centered over its column. */
.finance-table-wrap > .accounting-data-table > thead > tr > th {
    text-align: center;
}

.accounting-data-table td > small,
.accounting-data-table th > small {
    display: block;
    margin-top: 3px;
    color: var(--text-muted);
    font-weight: 500;
}

.finance-records-table {
    min-width: max(100%, 880px);
}

.finance-records-table th:last-child,
.finance-records-table td:last-child {
    min-width: 116px;
}

.journal-register-table,
.journal-lines-table,
.statement-detail-table {
    min-width: 840px;
}

.statement-detail-table td:first-child {
    width: 120px;
    white-space: nowrap;
}

.statement-detail-table td:last-child,
.statement-detail-table th:last-child {
    width: 180px;
}

.statement-section-row > th {
    padding: 10px 13px;
    color: var(--primary);
    background: var(--primary-soft) !important;
    font-size: 11px;
    letter-spacing: .08em;
    text-align: left;
    text-transform: uppercase;
}

.statement-subtotal-row > th {
    color: var(--text);
    background: var(--surface-muted) !important;
    font-weight: 700;
}

.accounting-data-table .statement-subtotal-row > th.amount,
.accounting-data-table .statement-grand-total-row > th.amount {
    text-align: right;
}

.statement-grand-total-row > th {
    color: var(--text);
    background: color-mix(in srgb, var(--success-soft, var(--primary-soft)) 68%, var(--surface)) !important;
    font-size: 12px;
    font-weight: 700;
}

.equity-movement-table {
    min-width: 560px !important;
}

@media (max-width: 720px) {
    .finance-table-wrap {
        border-radius: 10px;
    }

    .finance-table-wrap > .accounting-data-table {
        min-width: 720px;
    }

    .equity-movement-table {
        min-width: 520px !important;
    }
}

.finance-records-table :is(th, td)[data-field*="amount"],
.finance-records-table :is(th, td)[data-field*="balance"],
.finance-records-table :is(th, td)[data-field*="debit"],
.finance-records-table :is(th, td)[data-field*="credit"],
.finance-records-table :is(th, td)[data-field*="cost"],
.finance-records-table :is(th, td)[data-field*="quantity"],
.finance-records-table :is(th, td)[data-field*="value"],
.finance-records-table :is(th, td)[data-field*="total"],
.finance-records-table :is(th, td)[data-field="rate"],
.finance-records-table :is(th, td)[data-field$="_rate"] {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
