/* ─────────────────────────────────────────────────────────────────────────
   app.css — Tadash global styles
   Rule: tokens.css must always be the first import. Never add anything above it.
   ───────────────────────────────────────────────────────────────────────── */

@import url('tokens.css');


/* ─── Fonts ─────────────────────────────────────────────────────────────── */

@font-face {
    font-family: 'Geist';
    src: url('../fonts/Geist-variable.woff2') format('woff2');
    font-weight: 100 900;
    font-style: normal;
    font-display: optional;
}

@font-face {
    font-family: 'Geist Mono';
    src: url('../fonts/GeistMono-variable.woff2') format('woff2');
    font-weight: 100 900;
    font-style: normal;
    font-display: optional;
}


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

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


/* ─── Base ───────────────────────────────────────────────────────────────── */

html {
    font-family: 'Geist', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 24px;
    font-weight: 400;
    font-feature-settings: "ss01", "cv11";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background-color: var(--bg-canvas);
    color: var(--text-primary);
    min-height: 100dvh;
}

code, kbd, samp, pre {
    font-family: 'Geist Mono', ui-monospace, 'Cascadia Code', monospace;
    font-feature-settings: normal;
}

/* Tabular numerals — all table cells, inputs, and data displays */
table, input, textarea, select, [data-numeric] {
    font-variant-numeric: tabular-nums;
}


/* ─── Typography ─────────────────────────────────────────────────────────── */

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    text-wrap: pretty;
}

p {
    max-width: 640px; /* reading-width ceiling — Body 15px */
}


/* ─── Links ──────────────────────────────────────────────────────────────── */

a {
    color: var(--accent-base);
    text-decoration: none;
}

/* Underline only for inline body-copy links */
p a, li a {
    text-decoration: underline;
    text-underline-offset: 2px;
}


/* ─── Focus ──────────────────────────────────────────────────────────────── */

/* Global focus ring — never outline: none without a replacement */
:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}


/* ─── Page header (§2 Content Page Layout) ──────────────────────────────── */

.page-hd {
    margin-bottom: var(--space-7);
}

.page-hd-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-5);
}

.page-hd-title {
    font-size: var(--text-h1-size);
    font-weight: 600;
    line-height: var(--text-h1-line);
    letter-spacing: var(--text-h1-track);
    color: var(--text-primary);
}

.page-hd-subtitle {
    margin-top: var(--space-2);
    font-size: var(--text-body-lg-size);
    line-height: var(--text-body-lg-line);
    color: var(--text-secondary);
    max-width: none;
}

.page-hd-meta {
    font-size: var(--text-small-size);
    line-height: var(--text-small-line);
    color: var(--text-tertiary);
    flex-shrink: 0;
}


/* ─── Breadcrumb (§22) ───────────────────────────────────────────────────── */

.breadcrumb {
    margin-bottom: var(--space-6);
}

.breadcrumb-list {
    list-style: none;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}

.breadcrumb-sep {
    padding: 0 var(--space-3);
    font-size: var(--text-small-size);
    line-height: var(--text-small-line);
    color: var(--text-quaternary);
    user-select: none;
}

.breadcrumb-link {
    font-size: var(--text-small-size);
    line-height: var(--text-small-line);
    color: var(--text-tertiary);
    text-decoration: none;
}

@media (hover: hover) and (pointer: fine) {
    .breadcrumb-link:hover {
        color: var(--text-primary);
        text-decoration: underline;
        text-underline-offset: 2px;
    }
}

.breadcrumb-link:focus-visible {
    border-radius: var(--radius-sm);
}

.breadcrumb-current {
    font-size: var(--text-small-size);
    line-height: var(--text-small-line);
    color: var(--text-primary);
}


/* ─── Screen-reader only ─────────────────────────────────────────────────── */

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


/* ─── Badge ──────────────────────────────────────────────────────────────── */

.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    height: 22px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-sm);
    font-size: var(--text-caption-size);
    font-weight: var(--weight-medium);
    line-height: var(--text-caption-line);
    white-space: nowrap;
    flex-shrink: 0;
}

.badge-neutral { background-color: var(--bg-muted);              color: var(--text-secondary); }
.badge-info    { background-color: var(--status-info-subtle);    color: var(--status-info-text); }
.badge-success { background-color: var(--status-success-subtle); color: var(--status-success-text); }
.badge-warning { background-color: var(--status-warning-subtle); color: var(--status-warning-text); }
.badge-danger  { background-color: var(--status-danger-subtle);  color: var(--status-danger-text); }


/* ─── Card ───────────────────────────────────────────────────────────────── */

.card {
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: var(--space-7);
}

a.card {
    display: block;
    text-decoration: none;
    color: inherit;
    transition: var(--transition-colors), var(--transition-shadow);
}

@media (hover: hover) and (pointer: fine) {
    a.card:hover {
        border-color: var(--border-strong);
        box-shadow: var(--shadow-md);
    }
}

a.card:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}


/* ─── Button (§1) ────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    height: 36px;
    padding: 0 var(--space-5);
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-family: inherit;
    font-size: var(--text-small-size);
    font-weight: var(--weight-medium);
    line-height: var(--text-small-line);
    letter-spacing: 0;
    white-space: nowrap;
    cursor: pointer;
    text-decoration: none;
    transition:
        background-color var(--duration-micro) var(--ease-out),
        border-color     var(--duration-micro) var(--ease-out),
        box-shadow       var(--duration-micro) var(--ease-out),
        transform        100ms var(--ease-out);
    user-select: none;
    -webkit-user-select: none;
}

.btn:active {
    transform: scale(0.97);
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus-ring);
}

/* Primary */
.btn-primary {
    background-color: var(--accent-base);
    color: var(--accent-on);
    box-shadow: var(--shadow-xs);
}

@media (hover: hover) and (pointer: fine) {
    .btn-primary:hover {
        background-color: var(--accent-hover);
        box-shadow: var(--shadow-sm);
    }
}

.btn-primary:active {
    background-color: var(--accent-press);
    box-shadow: none;
}

.btn-primary:disabled,
.btn-primary[aria-disabled="true"] {
    opacity: 0.40;
    cursor: not-allowed;
    box-shadow: none;
}

/* Secondary */
.btn-secondary {
    background-color: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-default);
    box-shadow: var(--shadow-xs);
}

@media (hover: hover) and (pointer: fine) {
    .btn-secondary:hover {
        background-color: var(--bg-muted);
        border-color: var(--border-strong);
        box-shadow: var(--shadow-sm);
    }
}

.btn-secondary:active {
    background-color: var(--bg-muted);
    border-color: var(--border-strong);
    box-shadow: none;
}

.btn-secondary:disabled,
.btn-secondary[aria-disabled="true"] {
    color: var(--text-quaternary);
    border-color: var(--border-subtle);
    box-shadow: none;
    cursor: not-allowed;
}

/* Ghost */
.btn-ghost {
    background-color: transparent;
    color: var(--text-secondary);
}

@media (hover: hover) and (pointer: fine) {
    .btn-ghost:hover {
        background-color: var(--bg-muted);
        color: var(--text-primary);
    }
}

.btn-ghost:active {
    background-color: var(--bg-subtle);
    color: var(--text-primary);
}

/* Icon-only square variant */
.btn-icon {
    width: 36px;
    padding: 0;
    flex-shrink: 0;
}


/* ─── Modal (§17) ────────────────────────────────────────────────────────── */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: var(--z-overlay);
    background-color: var(--bg-overlay);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration-standard) var(--ease-out);
}

.modal-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.modal-panel {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.modal-panel[aria-hidden="false"] {
    pointer-events: auto;
}

.modal-box {
    width: 480px;
    max-width: calc(100vw - var(--space-7) * 2);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    opacity: 0;
    transform: scale(0.97);
    transform-origin: center;
    transition:
        opacity  var(--duration-standard) var(--ease-out),
        transform var(--duration-standard) var(--ease-out);
    will-change: opacity, transform;
}

.modal-panel.is-visible .modal-box {
    opacity: 1;
    transform: scale(1);
}

/* Header */
.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-7) var(--space-7) var(--space-5);
    flex-shrink: 0;
}

.modal-title {
    font-size: var(--text-h3-size);
    font-weight: 600;
    line-height: var(--text-h3-line);
    letter-spacing: var(--text-h3-track);
    color: var(--text-primary);
}

.modal-close {
    margin-top: -2px; /* optical alignment with title */
    flex-shrink: 0;
}

/* Body */
.modal-body {
    padding: 0 var(--space-7);
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

/* Footer */
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-5) var(--space-7) var(--space-7);
    flex-shrink: 0;
    border-top: 1px solid var(--border-subtle);
    margin-top: var(--space-7);
}

.modal-footer .btn-secondary {
    margin-right: auto;
}

/* Brand wordmark centred at the top of the modal */
.modal-brand {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: clamp(var(--space-4), 4vw, var(--space-6)) var(--space-5) 0;
    flex-shrink: 0;
}

.modal-brand .brand-logo {
    height: clamp(22px, 4vw, 28px);
    width: auto;
    max-width: 60%;
}

/* Reduce top padding of the header when a brand block precedes it */
.modal-brand + .modal-header {
    padding-top: var(--space-5);
}


/* ─── Form fields (§2 / §26) ─────────────────────────────────────────────── */

.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-label {
    font-size: var(--text-small-size);
    font-weight: var(--weight-medium);
    line-height: var(--text-small-line);
    color: var(--text-primary);
    letter-spacing: 0;
}

.form-required {
    color: var(--status-danger-text);
    margin-left: 2px;
}

.form-input,
.form-select {
    height: 36px;
    padding: 0 var(--space-4);
    background-color: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: var(--text-small-size);
    line-height: var(--text-small-line);
    font-variant-numeric: tabular-nums;
    transition: border-color var(--duration-micro) var(--ease-out),
                box-shadow   var(--duration-micro) var(--ease-out);
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
}

.form-input::placeholder {
    color: var(--text-tertiary);
}

@media (hover: hover) and (pointer: fine) {
    .form-input:hover,
    .form-select:hover {
        border-color: var(--border-strong);
    }
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: var(--shadow-focus-ring);
}

/* Error state — applied when parent has .form-field-invalid */
.form-field-invalid .form-input,
.form-field-invalid .form-select {
    border-color: var(--status-danger-bg);
}

.form-field-invalid .form-input:focus,
.form-field-invalid .form-select:focus {
    border-color: var(--status-danger-bg);
    box-shadow: var(--shadow-focus-ring-danger);
}

/* Select chevron */
.form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235A5A5E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-4) center;
    padding-right: var(--space-8);
    cursor: pointer;
}

/* Date input — ensure consistent height in Webkit */
.form-input-date {
    cursor: text;
}

.form-hint {
    font-size: var(--text-caption-size);
    line-height: var(--text-caption-line);
    color: var(--text-tertiary);
    letter-spacing: var(--text-caption-track);
}

.form-error {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-caption-size);
    font-weight: var(--weight-medium);
    line-height: var(--text-caption-line);
    color: var(--status-danger-text);
}

/* Read-only display value (e.g. lead assessor) */
.form-static {
    font-size: var(--text-small-size);
    line-height: var(--text-small-line);
    color: var(--text-secondary);
    padding: 0 2px;
    max-width: none;
}

/* Dark mode overrides */
[data-theme="dark"] .form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238A8A8E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}


/* ─── Wordmark theme switching ───────────────────────────────────────────── */
/*
 * Specificity is deliberately 0-2-0 throughout (.wordmark .wordmark--X).
 * layout.css defines .brand-logo { display: block } at 0-1-0 and loads AFTER
 * app.css, so any 0-1-0 rule here loses the cascade. The extra class selector
 * raises us to 0-2-0 and wins regardless of stylesheet order.
 */

.wordmark {
    display: inline-flex;
    align-items: center;
}

/* Neutralise layout.css display:block on .brand-logo inside the wordmark span */
.wordmark .brand-logo      { display: inline; }

/* Hide dark variant by default (light mode) */
.wordmark .wordmark--dark  { display: none; }

/* Explicit dark theme */
[data-theme="dark"] .wordmark .wordmark--light { display: none; }
[data-theme="dark"] .wordmark .wordmark--dark  { display: inline; }

/* System dark preference when no explicit data-theme="light" override */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .wordmark .wordmark--light { display: none; }
    :root:not([data-theme="light"]) .wordmark .wordmark--dark  { display: inline; }
}


/* ─── Reduced motion ─────────────────────────────────────────────────────── */

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