/* ============================================================================
   JFDA E-Services Register — Arabic-first (RTL) styling on top of MudBlazor.

   MudBlazor supplies the component layer and the theme tokens (see JfdaTheme.cs);
   this file adds the app's own surface treatment, the status ramp helpers, and
   markdown/typography rules MudBlazor doesn't cover.

   Status colours come from StatusPalette and were validated for colourblind
   separation and contrast against each mode's own surface, not eyeballed.
   ========================================================================= */

/* ---------- fonts (self-hosted: this runs on an internal network) --------- */
@font-face {
    font-family: "Plex Sans";
    src: url("fonts/ibm-plex-sans-latin-400.woff2") format("woff2");
    font-weight: 400; font-style: normal; font-display: swap;
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212;
}
@font-face {
    font-family: "Plex Sans";
    src: url("fonts/ibm-plex-sans-latin-600.woff2") format("woff2");
    font-weight: 600; font-style: normal; font-display: swap;
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212;
}
/* The Arabic cut also carries Latin, so mixed strings don't jump fonts mid-line. */
@font-face {
    font-family: "Plex Sans";
    src: url("fonts/ibm-plex-sans-arabic-arabic-400.woff2") format("woff2");
    font-weight: 400; font-style: normal; font-display: swap;
    unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
    font-family: "Plex Sans";
    src: url("fonts/ibm-plex-sans-arabic-arabic-600.woff2") format("woff2");
    font-weight: 600; font-style: normal; font-display: swap;
    unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
    font-family: "Plex Mono";
    src: url("fonts/ibm-plex-mono-latin-400.woff2") format("woff2");
    font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
    font-family: "Plex Mono";
    src: url("fonts/ibm-plex-mono-latin-600.woff2") format("woff2");
    font-weight: 600; font-style: normal; font-display: swap;
}

/* ------------------------------- surfaces -------------------------------- */
:root {
    --jfda-surface: #F7F5EF;
    --jfda-panel: #FFFDF8;
    --jfda-panel-2: #F1EEE5;
    --jfda-line: #E0DCD0;
    --jfda-ink: #1B2227;
    --jfda-ink-2: #4A555C;
    --jfda-ink-3: #77828A;
    --jfda-accent: #2563C7;
    --jfda-danger: #B83C10;
}

:root[data-theme="dark"] {
    --jfda-surface: #0F1A1F;
    --jfda-panel: #16232A;
    --jfda-panel-2: #1D2C34;
    --jfda-line: #263840;
    --jfda-ink: #E8EDEF;
    --jfda-ink-2: #A9B7BE;
    --jfda-ink-3: #7B8B93;
    --jfda-accent: #4E8AE6;
    --jfda-danger: #D9512A;
}

html, body {
    font-family: "Plex Sans", "Segoe UI", system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* Blazor's FocusOnNavigate targets h1 for screen readers; the visible ring it produces on
   every navigation is noise for pointer users. Keyboard focus elsewhere keeps its ring. */
h1:focus, h1:focus-visible { outline: none; }

/* ------------------------------- helpers --------------------------------- */
.jfda-mono {
    font-family: "Plex Mono", ui-monospace, Menlo, monospace;
    font-variant-numeric: tabular-nums;
    /* Numbers and identifiers stay LTR even inside the RTL document. */
    direction: ltr;
    display: inline-block;
    unicode-bidi: isolate;
}

.jfda-eyebrow {
    font-family: "Plex Mono", ui-monospace, monospace !important;
    text-transform: uppercase;
    letter-spacing: .1em;
    font-weight: 600;
    opacity: .72;
}

.jfda-muted { opacity: .7; }
.jfda-strong { font-weight: 600; }
.jfda-sub { font-size: .75rem; opacity: .65; margin-top: .125rem; }
.jfda-lead { max-width: 74ch; opacity: .8; }

.jfda-panel {
    background: var(--jfda-panel) !important;
    border: 1px solid var(--jfda-line) !important;
    border-radius: 10px !important;
}

.jfda-appbar { border-bottom: 1px solid var(--jfda-line) !important; }
.jfda-main { background: var(--jfda-surface); min-height: 100vh; }

.jfda-brand { gap: .625rem; align-items: center; border-bottom: 1px solid var(--jfda-line); }
/* The JFDA seal is a dark mark, so it needs a light backing to survive dark mode. */
.jfda-brand-mark {
    height: 34px; width: 34px; object-fit: contain;
    background: #FFFDF8; border-radius: 7px; padding: 3px; flex-shrink: 0;
}

.jfda-drawer-foot {
    margin-top: auto;
    padding: .75rem;
    border-top: 1px solid var(--jfda-line);
}

.jfda-tile-icon { opacity: .35; }
.jfda-stat-value {
    font-family: "Plex Mono", ui-monospace, monospace;
    font-variant-numeric: tabular-nums;
    font-size: 2rem; font-weight: 600; letter-spacing: -.02em;
    line-height: 1.15; margin: .375rem 0 .125rem;
    direction: ltr; text-align: start;
}

/* Row-level status spine — makes a long register scannable by colour edge alone.
   Uses the logical inline-start edge so it lands on the right in RTL. */
.jfda-spine {
    border-inline-start: 3px solid transparent;
    padding-inline-start: .625rem;
}

.jfda-status {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .15rem .55rem;
    border-radius: 100px;
    font-size: .6875rem; font-weight: 600;
    background: var(--jfda-panel-2);
    border: 1px solid var(--jfda-line);
    white-space: nowrap;
}
.jfda-status-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

/* Key/value grid on the service record. */
.jfda-kv {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: .5rem 1.25rem;
    font-size: .8125rem;
    align-items: baseline;
}
.jfda-kv > span:nth-child(odd) {
    font-family: "Plex Mono", ui-monospace, monospace;
    font-size: .6875rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    opacity: .6;
}

.jfda-suggestion { justify-content: flex-start !important; text-align: start !important; }

/* ------------------------------ assistant -------------------------------- */
/* Two panes inside the modal: conversation list beside the transcript. Height is pinned so
   only the transcript scrolls, never the dialog itself. */
.jfda-assistant-body {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 1rem;
    height: min(68vh, 640px);
    min-height: 380px;
}

.jfda-conv-list {
    display: flex; flex-direction: column;
    border-inline-end: 1px solid var(--jfda-line);
    padding-inline-end: 1rem;
    min-height: 0;
}

.jfda-conv-scroll { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; min-height: 0; }

.jfda-conv-item {
    display: flex; align-items: center; gap: .25rem;
    padding: .45rem .55rem;
    border-radius: 7px;
    cursor: pointer;
    border-inline-start: 2px solid transparent;
}
.jfda-conv-item:hover { background: var(--jfda-panel-2); }
.jfda-conv-item.active {
    background: var(--jfda-panel-2);
    border-inline-start-color: var(--jfda-accent);
}

.jfda-conv-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.jfda-conv-title {
    font-size: .8125rem; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.jfda-conv-meta {
    font-family: "Plex Mono", ui-monospace, monospace;
    font-size: .625rem; opacity: .55; margin-top: .1rem;
}

/* Delete stays out of the way until the row is hovered or is the active conversation. */
.jfda-conv-del { opacity: 0; transition: opacity .12s ease; }
.jfda-conv-item:hover .jfda-conv-del,
.jfda-conv-item.active .jfda-conv-del { opacity: .6; }
.jfda-conv-del:hover { opacity: 1 !important; }

.jfda-chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

.jfda-assistant-log {
    flex: 1;
    overflow-y: auto;
    padding: .25rem .5rem 1rem;
    display: flex; flex-direction: column; gap: 1.25rem;
}

@media (max-width: 800px) {
    .jfda-assistant-body { grid-template-columns: 1fr; height: min(76vh, 620px); }
    /* The list would eat the transcript on a phone; the newest conversation opens by default. */
    .jfda-conv-list { display: none; }
}

.jfda-msg { display: flex; flex-direction: column; gap: .25rem; }

.jfda-msg-user-body {
    background: var(--jfda-panel-2);
    border: 1px solid var(--jfda-line);
    border-radius: 8px;
    padding: .5rem .7rem;
    font-size: .8125rem;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.jfda-assistant-compose {
    flex-shrink: 0;
    border-top: 1px solid var(--jfda-line);
    padding: .75rem;
    display: flex; gap: .5rem; align-items: flex-end;
}

/* -------------------------- markdown rendering --------------------------- */
.jfda-md {
    font-size: .875rem;
    line-height: 1.7;
    overflow-wrap: anywhere;
}
.jfda-md-compact { font-size: .8125rem; }

.jfda-md > :first-child { margin-top: 0; }
.jfda-md > :last-child { margin-bottom: 0; }

.jfda-md h1, .jfda-md h2, .jfda-md h3, .jfda-md h4, .jfda-md h5, .jfda-md h6 {
    font-weight: 600;
    line-height: 1.35;
    margin: 1.4em 0 .5em;
}
.jfda-md h1 { font-size: 1.25em; }
.jfda-md h2 { font-size: 1.125em; }
.jfda-md h3 { font-size: 1em; }
.jfda-md h4, .jfda-md h5, .jfda-md h6 { font-size: .9375em; opacity: .85; }

.jfda-md p { margin: 0 0 .85em; }
.jfda-md ul, .jfda-md ol { margin: 0 0 .85em; padding-inline-start: 1.35em; }
.jfda-md li { margin-bottom: .3em; }
.jfda-md li::marker { color: var(--jfda-ink-3); }

.jfda-md a { color: var(--jfda-accent); text-decoration: underline; text-underline-offset: 2px; }

.jfda-md strong { font-weight: 600; }

.jfda-md code {
    font-family: "Plex Mono", ui-monospace, monospace;
    font-size: .875em;
    background: var(--jfda-panel-2);
    border: 1px solid var(--jfda-line);
    border-radius: 4px;
    padding: .08em .35em;
    direction: ltr;
    unicode-bidi: isolate;
}

.jfda-md pre {
    background: var(--jfda-panel-2);
    border: 1px solid var(--jfda-line);
    border-radius: 8px;
    padding: .75rem .875rem;
    overflow-x: auto;
    direction: ltr;
    text-align: left;
    margin: 0 0 .85em;
}
.jfda-md pre code { background: none; border: none; padding: 0; font-size: .8125em; }

.jfda-md blockquote {
    margin: 0 0 .85em;
    padding: .25rem 0 .25rem .875rem;
    border-inline-start: 3px solid var(--jfda-line);
    padding-inline-start: .875rem;
    opacity: .82;
}

/* Tables are the assistant's main output shape — they must scroll, never overflow the panel. */
.jfda-md .table-wrap, .jfda-md table { max-width: 100%; }
.jfda-md table {
    width: 100%;
    border-collapse: collapse;
    margin: 0 0 .85em;
    font-size: .9375em;
    display: block;
    overflow-x: auto;
    white-space: nowrap;
}
.jfda-md th, .jfda-md td {
    border: 1px solid var(--jfda-line);
    padding: .375rem .625rem;
    text-align: start;
}
.jfda-md th {
    background: var(--jfda-panel-2);
    font-weight: 600;
    font-size: .9em;
}

.jfda-md hr { border: none; border-top: 1px solid var(--jfda-line); margin: 1.25em 0; }

.jfda-md img { max-width: 100%; height: auto; }

/* --------------------------------- login --------------------------------- */
.jfda-login {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: var(--jfda-surface);
    color: var(--jfda-ink);
}

.jfda-login-card { width: 100%; max-width: 340px; }

.jfda-login-mark {
    height: 46px; width: 46px; object-fit: contain;
    background: #FFFDF8; border-radius: 9px; padding: 5px;
    border: 1px solid var(--jfda-line);
}

.jfda-login-card h1 {
    font-size: 1.125rem; font-weight: 600; letter-spacing: -.01em;
    margin: 1rem 0 .125rem;
}

.jfda-login-sub {
    font-family: "Plex Mono", ui-monospace, monospace;
    font-size: .6875rem; text-transform: uppercase; letter-spacing: .1em;
    font-weight: 600; opacity: .6; margin: 0 0 1.75rem;
}

.jfda-login-error {
    background: color-mix(in srgb, var(--jfda-danger) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--jfda-danger) 35%, transparent);
    color: var(--jfda-danger);
    border-radius: 6px; padding: .5rem .625rem;
    font-size: .8125rem; margin-bottom: 1rem;
}

.jfda-login form { display: flex; flex-direction: column; gap: .875rem; }

.jfda-login label {
    display: flex; flex-direction: column; gap: .375rem;
    font-family: "Plex Mono", ui-monospace, monospace;
    font-size: .6875rem; text-transform: uppercase; letter-spacing: .1em;
    font-weight: 600; opacity: .7;
}

.jfda-login input {
    font-family: "Plex Sans", sans-serif;
    font-size: .875rem; font-weight: 400;
    text-transform: none; letter-spacing: normal;
    color: var(--jfda-ink);
    background: var(--jfda-panel);
    border: 1px solid var(--jfda-line);
    border-radius: 6px;
    padding: .5rem .625rem;
}

.jfda-login input:focus {
    outline: none;
    border-color: var(--jfda-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--jfda-accent) 20%, transparent);
}

.jfda-login button {
    margin-top: .375rem;
    font-family: "Plex Sans", sans-serif;
    font-size: .8125rem; font-weight: 600;
    background: var(--jfda-accent); color: #fff;
    border: none; border-radius: 6px;
    padding: .55rem; cursor: pointer;
}
.jfda-login button:hover { filter: brightness(1.08); }

.jfda-login-foot {
    margin-top: 1.5rem; padding-top: 1rem;
    border-top: 1px solid var(--jfda-line);
    font-size: .6875rem; opacity: .55; line-height: 1.6;
}

/* ------------------------------ error strip ------------------------------ */
/* Blazor flips this to display:block when the circuit faults. */
#blazor-error-ui {
    display: none;
    position: fixed; bottom: 0; inset-inline: 0; z-index: 2000;
    background: var(--jfda-danger); color: #fff;
    padding: .75rem 1.25rem; font-size: .8125rem;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, .2);
}
#blazor-error-ui a { color: #fff; text-decoration: underline; }
#blazor-error-ui .dismiss { cursor: pointer; float: inline-end; }

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