/* ---------------------------------------------------------------------------
   Assistant Studio - admin UI
   One handwritten stylesheet: no build step, no framework, nothing to install
   before the app runs. Layout is CSS grid + flex; colours are tokens so the
   whole console can be re-themed from the block below.
   --------------------------------------------------------------------------- */

:root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-2: #f1f2f8;
    --border: #e3e5ef;
    --border-strong: #ccd0e0;
    --text: #1b1d28;
    --muted: #6b7086;
    --brand: #6d5efc;
    --brand-dark: #5a4ae0;
    --brand-soft: #eeecff;
    --ok: #15925f;
    --ok-soft: #e6f6ee;
    --warn: #b7791f;
    --warn-soft: #fdf3e2;
    --err: #cf3050;
    --err-soft: #fdeaee;
    --radius: 12px;
    --radius-lg: 18px;
    --shadow: 0 1px 2px rgba(20, 22, 40, .06), 0 8px 24px rgba(20, 22, 40, .06);
    --shadow-lg: 0 12px 40px rgba(20, 22, 40, .14);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
small { font-size: .82rem; }

/* ------------------------------------------------------------------ topbar */

.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 24px;
    height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 40;
}

.topbar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.02em;
}
.topbar__brand:hover { text-decoration: none; }

.topbar__mark {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--brand), #26d0a5);
    color: #fff;
    font-size: 11px;
    letter-spacing: -1px;
}

.topbar__nav { display: flex; gap: 4px; margin-left: 8px; }
.topbar__nav a {
    padding: 7px 12px;
    border-radius: 8px;
    color: var(--muted);
    font-weight: 550;
    font-size: .92rem;
}
.topbar__nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.topbar__nav a.is-active { background: var(--brand-soft); color: var(--brand-dark); }

.topbar__user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: .85rem;
}
.topbar__org { font-weight: 600; }
.topbar__email { color: var(--muted); }

@media (max-width: 720px) {
    .topbar { gap: 12px; padding: 0 14px; }
    .topbar__email, .topbar__org { display: none; }
}

/* ------------------------------------------------------------------ layout */

.shell {
    max-width: 1180px;
    margin: 0 auto;
    padding: 28px 24px 80px;
}

.shell--wide { max-width: 1400px; }

.page-head {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}
.page-head__text { flex: 1 1 320px; }
.page-head__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page-head p { color: var(--muted); margin: 0; }

.grid { display: grid; gap: 16px; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.stack > * + * { margin-top: 16px; }

/* Main column + sidebar. `minmax(0, 1fr)` rather than `1fr` so a wide child -
   a code block or a long filename - cannot push the sidebar off screen. */
.split {
    display: grid;
    gap: 16px;
    align-items: start;
    grid-template-columns: minmax(0, 1fr) 340px;
}
.split--narrow { grid-template-columns: minmax(0, 1fr) 300px; }

@media (max-width: 980px) {
    .split,
    .split--narrow { grid-template-columns: minmax(0, 1fr); }
    .preview-pane { position: static; }
}

/* ------------------------------------------------------------------ cards */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
}
.card--flush { padding: 0; overflow: hidden; }
.card__head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}
.card__head h2, .card__head h3 { margin: 0; }
.card__head .btn { margin-left: auto; }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat__value { font-size: 1.9rem; font-weight: 700; letter-spacing: -.03em; }
.stat__label { color: var(--muted); font-size: .85rem; }

.meter {
    height: 6px;
    border-radius: 99px;
    background: var(--surface-2);
    overflow: hidden;
    margin-top: 8px;
}
.meter__fill { height: 100%; background: var(--brand); border-radius: 99px; }
.meter__fill--warn { background: var(--warn); }
.meter__fill--err { background: var(--err); }

/* ------------------------------------------------------------------ buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: var(--brand);
    color: #fff;
    font: inherit;
    font-weight: 600;
    font-size: .92rem;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-disabled { opacity: .5; pointer-events: none; }

.btn--ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }

.btn--soft { background: var(--brand-soft); color: var(--brand-dark); }
.btn--soft:hover { background: #e3e0ff; color: var(--brand-dark); }

.btn--danger { background: var(--err); }
.btn--danger:hover { background: #b02742; }

.btn--sm { padding: 6px 11px; font-size: .84rem; }
.btn--lg { padding: 12px 22px; font-size: 1rem; }
.btn--block { width: 100%; }

.linkish {
    background: none;
    border: 0;
    padding: 0;
    color: var(--brand);
    font: inherit;
    cursor: pointer;
    text-decoration: underline;
}

/* ------------------------------------------------------------------ forms */

.field { margin-bottom: 16px; }
.field label,
.field > legend {
    display: block;
    font-weight: 600;
    font-size: .88rem;
    margin-bottom: 6px;
}
.field .help, .help {
    display: block;
    color: var(--muted);
    font-size: .82rem;
    margin-top: 5px;
}

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=url], input[type=search], textarea, select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: .93rem;
}
input:focus, textarea:focus, select:focus {
    outline: 2px solid var(--brand);
    outline-offset: -1px;
    border-color: var(--brand);
}
textarea { resize: vertical; min-height: 70px; line-height: 1.5; }

input[type=color] {
    width: 54px;
    height: 38px;
    padding: 3px;
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    background: var(--surface);
    cursor: pointer;
}

input[type=range] { width: 100%; accent-color: var(--brand); }

.check {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
}
.check input[type=checkbox] {
    width: 18px;
    height: 18px;
    margin: 2px 0 0;
    accent-color: var(--brand);
    flex: none;
}
.check label { margin: 0; font-weight: 550; font-size: .92rem; }
.check .help { margin-top: 2px; }

.field-error, .form-error {
    color: var(--err);
    font-size: .84rem;
    margin-top: 5px;
}
ul.form-error-list { margin: 6px 0 0; padding-left: 18px; color: var(--err); font-size: .84rem; }

.inline-fields { display: flex; gap: 12px; flex-wrap: wrap; }
.inline-fields > * { flex: 1 1 150px; }

/* ------------------------------------------------------------------ tables */

.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th {
    text-align: left;
    font-size: .76rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: #fafbff; }
.table .right { text-align: right; }
.table .nowrap { white-space: nowrap; }

/* ------------------------------------------------------------------ badges */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: 99px;
    font-size: .76rem;
    font-weight: 650;
    background: var(--surface-2);
    color: var(--muted);
    white-space: nowrap;
}
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--err { background: var(--err-soft); color: var(--err); }
.badge--brand { background: var(--brand-soft); color: var(--brand-dark); }

.dot { width: 7px; height: 7px; border-radius: 99px; background: currentColor; }

/* ------------------------------------------------------------------ flashes */

.flash {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 14px;
    font-size: .92rem;
    border: 1px solid transparent;
}
.flash--success { background: var(--ok-soft); color: var(--ok); border-color: #bfe6d3; }
.flash--error { background: var(--err-soft); color: var(--err); border-color: #f4c5cf; }
.flash--warning { background: var(--warn-soft); color: var(--warn); border-color: #f0dcb6; }
.flash--info { background: var(--brand-soft); color: var(--brand-dark); border-color: #d8d3ff; }

/* ------------------------------------------------------------------ code */

.code {
    display: block;
    background: #14162a;
    color: #e6e8f5;
    border-radius: var(--radius);
    padding: 14px 16px;
    font-family: var(--mono);
    font-size: .82rem;
    line-height: 1.6;
    white-space: pre;
    overflow-x: auto;
    tab-size: 2;
}
.code--sm { font-size: .76rem; }
code.inline {
    font-family: var(--mono);
    font-size: .86em;
    background: var(--surface-2);
    padding: 1px 6px;
    border-radius: 5px;
}

.copy-wrap { position: relative; }
.copy-wrap .btn {
    position: absolute;
    top: 10px;
    right: 10px;
}

/* ------------------------------------------------------------------ empty */

.empty {
    text-align: center;
    padding: 48px 24px;
    color: var(--muted);
}
.empty h3 { color: var(--text); }
.empty__art { font-size: 2.6rem; margin-bottom: 10px; }

/* ------------------------------------------------------------------ auth */

.auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px 20px;
    background:
        radial-gradient(1000px 500px at 15% -10%, #ebe8ff 0%, transparent 60%),
        radial-gradient(900px 500px at 100% 0%, #ddf7ef 0%, transparent 55%),
        var(--bg);
}
.auth__card {
    width: 100%;
    max-width: 440px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 32px;
    box-shadow: var(--shadow-lg);
}
.auth__logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    margin-bottom: 22px;
}
.auth__foot { margin-top: 20px; text-align: center; color: var(--muted); font-size: .9rem; }

/* ------------------------------------------------------------------ tabs */

.tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 22px;
    overflow-x: auto;
}
.tabs button {
    appearance: none;
    background: none;
    border: 0;
    border-bottom: 2px solid transparent;
    padding: 11px 16px;
    font: inherit;
    font-weight: 600;
    font-size: .92rem;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.is-active { color: var(--brand-dark); border-bottom-color: var(--brand); }

.tabpanel { display: none; }
.tabpanel.is-active { display: block; }

/* ------------------------------------------------------------------ character picker */

.charpick {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
    gap: 12px;
}
.charpick input[type=radio] { position: absolute; opacity: 0; pointer-events: none; }
.charpick label {
    display: block;
    margin: 0;
    border: 2px solid var(--border);
    border-radius: 14px;
    padding: 10px 8px 12px;
    background: var(--surface);
    cursor: pointer;
    text-align: center;
    transition: border-color .15s, box-shadow .15s, transform .15s;
}
.charpick label:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.charpick input:checked + label {
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--brand-soft);
}
.charpick input:focus-visible + label { outline: 2px solid var(--brand); outline-offset: 2px; }
.charpick svg { width: 100%; height: 86px; display: block; }
.charpick__name { font-weight: 650; font-size: .88rem; margin-top: 4px; }
.charpick__tag { color: var(--muted); font-size: .74rem; line-height: 1.3; }

.preview-pane {
    position: sticky;
    top: 84px;
    background: linear-gradient(180deg, #ffffff, #f4f5fb);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
    text-align: center;
}
.preview-pane svg { width: 170px; height: 170px; }

/* ------------------------------------------------------------------ dropzone */

/* The dropzone is a <label>, which is display:inline by default. Without an
   explicit display its dashed border fragments into slivers down the side of
   the card while the block children escape the inline box - so this line is
   load-bearing, not cosmetic. */
.dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 26px 18px;
    text-align: center;
    background: var(--surface-2);
    transition: border-color .15s, background .15s;
    cursor: pointer;
}
.dropzone:hover { border-color: var(--brand); background: var(--brand-soft); }
.dropzone.is-over { border-color: var(--brand); background: var(--brand-soft); }
.dropzone:focus-within { outline: 2px solid var(--brand); outline-offset: 2px; }

.dropzone__icon {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    margin-bottom: 3px;
    border-radius: 50%;
    background: var(--brand-soft);
    color: var(--brand);
    transition: transform .15s, background .15s;
}
.dropzone__icon svg { width: 21px; height: 21px; display: block; }
.dropzone:hover .dropzone__icon,
.dropzone.is-over .dropzone__icon { transform: translateY(-2px); background: var(--surface); }

.dropzone__title { font-weight: 600; font-size: .94rem; }
.dropzone__hint { color: var(--muted); font-size: .81rem; line-height: 1.4; }

.dropzone input[type=file] {
    /* Hidden from view but still focusable, so the control stays keyboard
       reachable and :focus-within can outline the whole zone. */
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.dropzone__list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 5px;
    width: 100%;
}
.dropzone__list:not(:empty) { margin-top: 12px; }

.dropzone__file {
    max-width: 100%;
    padding: 3px 10px;
    border: 1px solid var(--border);
    border-radius: 99px;
    background: var(--surface);
    color: var(--text);
    font-size: .76rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ------------------------------------------------------------------ formats */

.formats { margin-top: 18px; }
.formats__label {
    display: block;
    margin-bottom: 8px;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}
.formats__list { display: flex; flex-wrap: wrap; gap: 4px; }
.formats__chip {
    padding: 2px 7px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--muted);
    font-family: var(--mono);
    font-size: .71rem;
    line-height: 1.6;
}

/* ------------------------------------------------------------------ transcript */

.bubble-row { display: flex; margin-bottom: 12px; }
.bubble-row--visitor { justify-content: flex-end; }
.bubble {
    max-width: 74%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: .93rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}
.bubble--visitor { background: var(--brand); color: #fff; border-bottom-right-radius: 5px; }
.bubble--assistant { background: var(--surface-2); border-bottom-left-radius: 5px; }
.bubble__meta { font-size: .74rem; color: var(--muted); margin-top: 4px; }
.bubble-row--visitor .bubble__meta { text-align: right; }

/* ------------------------------------------------------------------ misc */

.muted { color: var(--muted); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mt-2 { margin-top: 18px; }
.divider { height: 1px; background: var(--border); margin: 22px 0; border: 0; }

.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
