/* =============================================================================
   app.css — support site layout.

   Colors come exclusively from the shared Nautech tokens (generated_primitives.css +
   generated_color-tokens.css, copied from the dashboard). No hard-coded colors here, so a
   token change carries over. The layout itself is deliberately plain: this is the skeleton
   a frontend developer is expected to dress up.
   ============================================================================= */

:root {
    color-scheme: light dark;
    /* Same stack as the dashboard (base-tokens.css), served from css/fonts.css. */
    --font-family: 'Open Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --radius: 10px;
    --gap: 16px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font-family);
    font-size: 15px;
    line-height: 1.5;
    background: var(--c-surface-page);
    color: var(--c-text-primary);
}

/* ── Header ─────────────────────────────────────────────────────────────── */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--gap);
    padding: 12px clamp(12px, 3vw, 32px);
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border-subtle);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--c-text-primary);
}

/* The logo is a mask, not an <img>: background-color drives the fill, so it takes the theme's text
   color in light and dark alike. Aspect ratio is the SVG's own viewBox (126 x 27). */
.brand-logo {
    width: 126px;
    aspect-ratio: 126 / 27;
    flex-shrink: 0;
    background-color: var(--c-text-primary);
    -webkit-mask: url("../images/nautech.svg") no-repeat center / contain;
    mask: url("../images/nautech.svg") no-repeat center / contain;
}

.brand-suffix {
    font-size: 18px;
    font-weight: 600;
    color: var(--c-primary);
    border-left: 1px solid var(--c-border-subtle);
    padding-left: 10px;
}

.app-header nav {
    display: flex;
    align-items: center;
    gap: var(--gap);
    flex-wrap: wrap;
}

.app-header nav a {
    text-decoration: none;
    color: var(--c-text-secondary);
    padding: 4px 0;
    border-bottom: 2px solid transparent;
}

.app-header nav a:hover { color: var(--c-text-primary); }
.app-header nav a.active { color: var(--c-primary); border-bottom-color: var(--c-primary); }

/* The staff entry sits among plain text links, so a solid filled button shouted. A tinted chip in
   the brand color marks it as the privileged destination without breaking the row. */
.app-header nav a.nav-staff {
    padding: 4px 12px;
    border: 1px solid rgba(var(--c-primary-rgb), 0.35);
    border-radius: 999px;
    background: rgba(var(--c-primary-rgb), 0.10);
    color: var(--c-primary);
    font-weight: 600;
}

.app-header nav a.nav-staff:hover {
    background: rgba(var(--c-primary-rgb), 0.18);
    color: var(--c-primary);
}

.app-header nav a.nav-staff.active {
    background: rgba(var(--c-primary-rgb), 0.18);
    border-color: var(--c-primary);
}

.app-header .user { color: var(--c-text-muted); font-size: 13px; }

main {
    max-width: 900px;
    margin: 0 auto;
    padding: clamp(12px, 3vw, 32px);
}

/* ── Common bits ────────────────────────────────────────────────────────── */

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--gap);
    flex-wrap: wrap;
    margin-bottom: var(--gap);
}

.page-head h1 { font-size: 22px; margin: 0; }
.page-head .meta { margin: 4px 0 0; color: var(--c-text-secondary); font-size: 13px; }
.head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.notice { color: var(--c-text-secondary); }
.hint { color: var(--c-text-muted); font-size: 13px; }
.error { color: var(--c-error); }

.button {
    display: inline-block;
    padding: 8px 14px;
    border: 1px solid var(--c-border-subtle);
    border-radius: var(--radius);
    background: var(--c-surface);
    color: var(--c-text-primary);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
}

.button:hover { background: var(--c-surface-hover); }

.button.primary {
    background: var(--c-primary);
    border-color: var(--c-primary);
    color: var(--c-on-primary);
}

.button:disabled { opacity: 0.5; cursor: default; }

.link-button {
    border: none;
    background: none;
    color: var(--c-text-secondary);
    font: inherit;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

.badge {
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    white-space: nowrap;
    color: var(--c-on-primary);
}

.badge.open { background: var(--c-success); }
.badge.closed { background: var(--c-text-muted); }
.badge.waiting { background: var(--c-notif-warning); }

.tag {
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 12px;
    background: var(--c-surface-elevated);
    color: var(--c-text-secondary);
}

.card {
    background: var(--c-surface);
    border: 1px solid var(--c-border-subtle);
    border-radius: var(--radius);
    padding: var(--gap);
}

/* ── Ticket list ────────────────────────────────────────────────────────── */

.ticket-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.ticket-list li {
    background: var(--c-surface);
    border: 1px solid var(--c-border-subtle);
    border-radius: var(--radius);
    padding: 12px 14px;
    cursor: pointer;
}

.ticket-list li:hover { background: var(--c-surface-elevated); }

/* "The customer wrote last" is the queue's work list: an amber wash plus a left bar so it is
   spottable at a glance, without turning the row into an alarm. There is no --c-notif-warning-rgb
   token, so the tint is mixed from the token itself rather than hard-coding the colour. */
.ticket-list li.waiting {
    background: color-mix(in srgb, var(--c-notif-warning) 12%, var(--c-surface));
    border-color: color-mix(in srgb, var(--c-notif-warning) 45%, var(--c-surface));
    border-left: 4px solid var(--c-notif-warning);
}

.ticket-list li.waiting:hover {
    background: color-mix(in srgb, var(--c-notif-warning) 20%, var(--c-surface));
}

/* ── Pager ──────────────────────────────────────────────────────────────── */

.pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: var(--gap);
}

/* ── Search box ─────────────────────────────────────────────────────────── */

.list-search { margin-bottom: 12px; }

.list-search input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--c-border-subtle);
    border-radius: var(--radius);
    background: var(--c-surface);
    color: var(--c-text-primary);
    font: inherit;
}

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

.ticket-list .subject { font-weight: 600; }

.ticket-list .meta {
    justify-content: flex-start;
    gap: 14px;
    margin-top: 4px;
    color: var(--c-text-secondary);
    font-size: 13px;
}

/* ── Conversation ───────────────────────────────────────────────────────── */

/* Messenger layout: the viewer's own messages on the right, the other party's on the left. The
   sides are viewer-relative, so the same thread mirrors between the customer and the staff page. */

.thread { list-style: none; margin: 0 0 var(--gap); padding: 0; display: grid; gap: 14px; }

.thread .from-them { display: flex; justify-content: flex-start; }
.thread .from-me { display: flex; justify-content: flex-end; }

/* Borderless and generously rounded, but with real body: fit-content alone made every short reply
   collapse to the width of its own header row. The min-width gives a one-liner presence, the
   max-width still keeps a long message from spanning the whole column. */
.thread .bubble {
    border-radius: 18px;
    padding: 9px 14px 11px;
    width: fit-content;
    min-width: min(420px, 100%);
    max-width: 88%;
}

/* Incoming: the neutral bubble. The squared corner points at the speaker, like a chat tail. */
.thread .from-them .bubble {
    background: var(--c-surface);
    box-shadow: 0 1px 2px var(--c-shadow-xs);
    border-bottom-left-radius: 6px;
}

/* Outgoing: brand fill, the way Messenger marks your own side. */
.thread .from-me .bubble {
    background: var(--c-primary);
    color: var(--c-on-primary);
    border-bottom-right-radius: 6px;
}

.bubble-head {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    font-size: 12px;
    color: var(--c-text-secondary);
    margin-bottom: 6px;
}

.bubble-head .author { font-weight: 600; color: var(--c-text-primary); }

/* On the filled bubble every shade of grey would drop out of contrast, so the header and links
   inherit the on-primary color at reduced opacity instead. */
.thread .from-me .bubble-head,
.thread .from-me .bubble-head .author { color: var(--c-on-primary); }
.thread .from-me .bubble-head .time { opacity: 0.75; }
.thread .from-me .body a { color: var(--c-on-primary); text-decoration: underline; }
.thread .from-me .body blockquote { border-left-color: var(--c-on-primary); color: var(--c-on-primary); opacity: 0.9; }

/* Server-sanitised HTML from the WYSIWYG composer, so the markup is rendered, not escaped. */
.bubble .body { overflow-wrap: anywhere; }
.bubble .body > :first-child { margin-top: 0; }
.bubble .body > :last-child { margin-bottom: 0; }
.bubble .body p { margin: 0 0 8px; }
.bubble .body ul, .bubble .body ol { margin: 0 0 8px; padding-left: 22px; }
.bubble .body a { color: var(--c-primary); }

.bubble .body blockquote {
    margin: 0 0 8px;
    padding-left: 10px;
    border-left: 3px solid var(--c-border-subtle);
    color: var(--c-text-secondary);
}

.bubble-media { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.bubble-media img {
    width: 140px;
    height: 140px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--c-border-subtle);
    flex-shrink: 0;
}

/* Internal note: full width and clearly not a chat bubble, so it can never be mistaken for
   something the customer saw. */
.thread .internal-note { display: block; }

.thread .note {
    background: color-mix(in srgb, var(--c-notif-warning) 10%, var(--c-surface));
    border: 1px dashed color-mix(in srgb, var(--c-notif-warning) 55%, var(--c-surface));
    border-radius: var(--radius);
    padding: 10px 14px 12px;
}

.thread .note .bubble-head .author { color: var(--c-notif-warning); }

.reply.is-note { border-color: color-mix(in srgb, var(--c-notif-warning) 55%, var(--c-surface)); }

.compose-mode {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.compose-mode .toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--c-text-primary);
}

.compose-mode .toggle input { margin: 0; }

.bubble-media video {
    width: 260px;
    max-width: 100%;
    border-radius: 8px;
    border: 1px solid var(--c-border-subtle);
    background: var(--c-media-bg);
}

/* ── Forms ──────────────────────────────────────────────────────────────── */

.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 6px; font-size: 13px; color: var(--c-text-secondary); }

.form input[type="text"],
.form textarea,
.form select {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--c-border-subtle);
    border-radius: var(--radius);
    background: var(--c-surface);
    color: var(--c-text-primary);
    font: inherit;
}

.form textarea { resize: vertical; }
.form .actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.attachments { display: grid; gap: 8px; }
.file-input { font-size: 13px; }

.attachment-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }

.attachment-chips li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border: 1px solid var(--c-border-subtle);
    border-radius: var(--radius);
    background: var(--c-surface-elevated);
    font-size: 12px;
}

.attachment-chips img {
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

.attachment-chips .chip-icon {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    background: var(--c-media-bg);
    color: var(--nt-white);
}

/* ── WYSIWYG composer ───────────────────────────────────────────────────── */

.editor {
    border: 1px solid var(--c-border-subtle);
    border-radius: var(--radius);
    background: var(--c-surface);
    overflow: hidden;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 2px;
    padding: 6px;
    background: var(--c-surface-elevated);
    border-bottom: 1px solid var(--c-border-subtle);
}

.editor-toolbar button {
    min-width: 30px;
    padding: 4px 8px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: none;
    color: var(--c-text-primary);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.editor-toolbar button:hover {
    background: var(--c-surface-hover);
    border-color: var(--c-border-subtle);
}

.editor-toolbar .sep {
    width: 1px;
    height: 18px;
    margin: 0 4px;
    background: var(--c-border-subtle);
}

.editor-surface {
    min-height: 140px;
    padding: 10px 12px;
    color: var(--c-text-primary);
    outline: none;
    overflow-wrap: anywhere;
}

.editor-surface:empty::before {
    content: attr(data-placeholder);
    color: var(--c-text-muted);
}

.editor-surface p { margin: 0 0 8px; }
.editor-surface ul, .editor-surface ol { margin: 0 0 8px; padding-left: 22px; }
.editor-surface a { color: var(--c-primary); }

.editor-surface blockquote {
    margin: 0 0 8px;
    padding-left: 10px;
    border-left: 3px solid var(--c-border-subtle);
    color: var(--c-text-secondary);
}

/* ── Account pages ──────────────────────────────────────────────────────── */

.account-section {
    display: grid;
    grid-template-columns: 200px minmax(0, 1fr);
    gap: var(--gap);
    align-items: start;
}

@media (max-width: 720px) {
    .account-section { grid-template-columns: minmax(0, 1fr); }
}

.account-nav h2 { font-size: 15px; margin: 0 0 10px; }
.account-nav nav { display: grid; gap: 2px; }

.account-nav a {
    padding: 7px 10px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--c-text-secondary);
}

.account-nav a:hover { background: var(--c-surface-hover); }
.account-nav a.active { background: var(--c-surface); color: var(--c-primary); font-weight: 600; }

.account-nav-group {
    margin-top: 12px;
    padding: 0 10px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--c-text-muted);
}

.account-header h1 { font-size: 22px; margin: 0; }
.account-subtitle { margin: 4px 0 0; color: var(--c-text-secondary); font-size: 13px; }
.account-body { display: grid; gap: 12px; margin-top: var(--gap); }

.account-card h3 { margin: 0 0 4px; font-size: 15px; }

.credential-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 0;
    border-top: 1px solid var(--c-border-subtle);
}

.credential-meta { display: grid; gap: 2px; }
.credential-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Boot screen (replaced by the app once WASM starts) ─────────────────── */

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 22px;
    height: 100dvh;
    color: var(--c-text-secondary);
}

/* Same masked SVG as the header, so the first frame is already branded. */
.loading-logo {
    width: 180px;
    aspect-ratio: 126 / 27;
    background-color: var(--c-text-primary);
    -webkit-mask: url("../images/nautech.svg") no-repeat center / contain;
    mask: url("../images/nautech.svg") no-repeat center / contain;
}

.loading-bar {
    width: min(260px, 60vw);
    height: 4px;
    border-radius: 999px;
    background: var(--c-divider);
    overflow: hidden;
}

/* --blazor-load-percentage is set by the runtime as it fetches the assets, so this is the real
   download progress, not an animation pretending to be one. */
.loading-bar-fill {
    width: var(--blazor-load-percentage, 0%);
    height: 100%;
    border-radius: 999px;
    background: var(--c-primary);
    transition: width 120ms linear;
}

.loading-text {
    font-size: 13px;
    min-height: 1.2em;
}

/* Empty until the runtime reports a number, so there is no flash of "0%" before the first asset
   lands. */
.loading-text::after { content: var(--blazor-load-percentage-text, ""); }

/* Blazor reveals this by setting an inline display, so the layout here stays display-agnostic. */
#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 16px;
    border-radius: 999px;
    background: var(--c-error);
    color: var(--c-on-error);
    box-shadow: 0 4px 12px var(--c-shadow-md);
    z-index: 1000;
}

#blazor-error-ui .reload { color: var(--c-on-error); font-weight: 600; margin-left: 12px; }
