/* =========================================================
   Aviz AI Assistant — brand palette taken from the Aviz logo
   navy #28338a (cloud + wordmark) · orange #f7931e (arrow) · sky #3a8ed8
   ========================================================= */
:root {
    --navy: #28338a;
    --navy-deep: #1b2366;
    --orange: #f7931e;
    --orange-deep: #ec6f00;
    --sky: #3a8ed8;
    --green: #12a37f;

    --bg: #f5f6fb;
    --surface: #ffffff;
    --surface-2: #f0f2f9;
    --sidebar-bg: #fbfbfe;
    --border: #e3e6f0;
    --text: #151a35;
    --text-2: #3d4466;
    --muted: #6b7395;
    --user-bubble: linear-gradient(135deg, #28338a 0%, #3442a8 100%);
    --user-text: #ffffff;
    --code-bg: #12162e;
    --code-head: #1b2042;
    --blocked-bg: #fff6ea;
    --blocked-border: #f7c27a;
    --error-bg: #fdeeee;
    --error-border: #f3b4b4;
    --error-text: #b42318;
    --shadow-sm: 0 1px 2px rgba(21, 26, 53, .06);
    --shadow-md: 0 8px 24px -8px rgba(21, 26, 53, .14);
    --shadow-lg: 0 18px 48px -16px rgba(40, 51, 138, .28);
    --logo-chip: transparent;
    --ring: 0 0 0 4px rgba(58, 142, 216, .18);

    --font: "Plus Jakarta Sans", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    --sidebar-w: 288px;
    --thread-w: 800px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0b0e1c;
        --surface: #131833;
        --surface-2: #1a2043;
        --sidebar-bg: #0f1329;
        --border: #252c55;
        --text: #e9ebf7;
        --text-2: #c3c8e4;
        --muted: #8c93ba;
        --user-bubble: linear-gradient(135deg, #3442a8 0%, #4552c4 100%);
        --code-bg: #080b18;
        --code-head: #111633;
        --blocked-bg: #2a1d0b;
        --blocked-border: #8a5a1c;
        --error-bg: #2b1215;
        --error-border: #7a2a2f;
        --error-text: #ff9b94;
        --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, .5);
        --shadow-lg: 0 18px 48px -16px rgba(0, 0, 0, .6);
        --logo-chip: #ffffff;
    }
}
:root[data-theme="dark"] {
    --bg: #0b0e1c;
    --surface: #131833;
    --surface-2: #1a2043;
    --sidebar-bg: #0f1329;
    --border: #252c55;
    --text: #e9ebf7;
    --text-2: #c3c8e4;
    --muted: #8c93ba;
    --user-bubble: linear-gradient(135deg, #3442a8 0%, #4552c4 100%);
    --code-bg: #080b18;
    --code-head: #111633;
    --blocked-bg: #2a1d0b;
    --blocked-border: #8a5a1c;
    --error-bg: #2b1215;
    --error-border: #7a2a2f;
    --error-text: #ff9b94;
    --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, .5);
    --shadow-lg: 0 18px 48px -16px rgba(0, 0, 0, .6);
    --logo-chip: #ffffff;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
svg .fill { fill: currentColor; stroke: none; }
kbd {
    font-family: var(--font); font-size: 11px; font-weight: 600;
    padding: 1px 6px; border-radius: 5px;
    background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}

.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ================= Sidebar ================= */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px 14px 14px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; }
.brand-logo {
    height: 46px; width: auto;
    background: var(--logo-chip);
    border-radius: 10px;
    padding: 4px 6px;
}
.brand .sidebar-close { display: none; }

.btn-new {
    display: flex; align-items: center; gap: 10px;
    width: 100%; padding: 12px 14px;
    border: none; border-radius: 12px;
    background: linear-gradient(135deg, var(--orange) 0%, var(--orange-deep) 100%);
    color: #fff; font-weight: 700; font-size: 14px;
    cursor: pointer;
    box-shadow: 0 8px 20px -8px rgba(236, 111, 0, .6);
    transition: transform .15s, box-shadow .15s;
}
.btn-new:hover { transform: translateY(-1px); box-shadow: 0 12px 24px -8px rgba(236, 111, 0, .7); }
.btn-new span { flex: 1; text-align: left; }
.btn-new kbd { background: rgba(255, 255, 255, .22); border-color: transparent; color: #fff; }

.search {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 12px; border-radius: 10px;
    background: var(--surface); border: 1px solid var(--border);
    color: var(--muted);
}
.search:focus-within { border-color: var(--sky); box-shadow: var(--ring); }
.search svg { width: 16px; height: 16px; }
.search input { flex: 1; border: none; outline: none; background: none; color: var(--text); font: inherit; font-size: 13.5px; }

.conversations { flex: 1; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
.conv-group { font-size: 11px; font-weight: 700; letter-spacing: .7px; text-transform: uppercase; color: var(--muted); padding: 12px 8px 6px; }
.conv {
    display: flex; align-items: center; gap: 8px;
    width: 100%; padding: 9px 10px; margin-bottom: 2px;
    border: none; border-radius: 10px; background: none;
    font-size: 13.5px; color: var(--text-2); text-align: left;
    cursor: pointer; position: relative;
}
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm), inset 3px 0 0 var(--orange); }
.conv svg { width: 15px; height: 15px; color: var(--muted); }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-del {
    display: grid; place-items: center;
    width: 26px; height: 26px; border-radius: 7px;
    color: var(--muted); opacity: 0;
    transition: opacity .15s, background .15s;
}
.conv:hover .conv-del, .conv.active .conv-del, .conv-del.confirm { opacity: 1; }
.conv-del:hover { background: var(--border); color: var(--error-text); }
.conv-del.confirm { width: auto; padding: 0 8px; background: var(--error-bg); color: var(--error-text); font-size: 11.5px; font-weight: 700; }
.conv-empty { padding: 26px 10px; text-align: center; font-size: 13px; color: var(--muted); }

.sidebar-foot { display: flex; flex-direction: column; gap: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.powered-label { display: block; font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); margin-bottom: 7px; }
.stack { display: flex; flex-wrap: wrap; gap: 5px; }
.stack span { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.guest { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); }
.guest-avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, var(--sky), var(--navy)); color: #fff; font-weight: 700; font-size: 13px; }
.guest-text { flex: 1; display: flex; flex-direction: column; line-height: 1.3; }
.guest-text strong { font-size: 13px; }
.guest-text span { font-size: 11.5px; color: var(--muted); }
.yt { color: #ff0033; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; }
.yt:hover { background: var(--surface-2); }
.yt svg { width: 22px; height: 22px; }

/* ================= Main ================= */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

.topbar {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 22px;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--border);
    z-index: 5;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 15.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badges { display: flex; gap: 6px; margin-top: 2px; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.badge + .badge::before { content: "·"; margin-right: 4px; }
.badge svg { width: 12px; height: 12px; }
.badge-guard { color: var(--green); }
.spark { color: var(--orange); }

.status {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 6px 12px; border-radius: 999px;
    font-size: 12px; font-weight: 700;
    background: var(--surface); border: 1px solid var(--border); color: var(--muted);
}
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.online { color: var(--green); }
.status.online .dot { background: var(--green); box-shadow: 0 0 0 0 rgba(18, 163, 127, .5); animation: pulse 2s infinite; }
.status.offline { color: var(--error-text); }
.status.offline .dot { background: var(--error-text); }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(18, 163, 127, 0); } 100% { box-shadow: 0 0 0 0 rgba(18, 163, 127, 0); } }

.icon-btn {
    display: grid; place-items: center;
    width: 38px; height: 38px; border-radius: 10px;
    border: 1px solid transparent; background: none; color: var(--text-2);
    cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border); }
.menu-btn { display: none; }
.i-sun { display: none; }
:root[data-theme="dark"] .i-sun { display: block; }
:root[data-theme="dark"] .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .i-sun { display: block; }
    :root:not([data-theme="light"]) .i-moon { display: none; }
}

/* ================= Thread ================= */
.scroller { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.thread { max-width: var(--thread-w); margin: 0 auto; padding: 28px 24px 24px; }

/* Welcome */
.welcome { text-align: center; padding: 6vh 0 10px; animation: rise .5s ease-out; }
.welcome-logo { height: 76px; width: auto; margin-bottom: 26px; background: var(--logo-chip); border-radius: 16px; padding: 6px 10px; }
.welcome h2 { font-size: clamp(24px, 3.4vw, 34px); font-weight: 800; line-height: 1.25; letter-spacing: -.02em; }
.grad { background: linear-gradient(90deg, var(--navy) 0%, var(--sky) 55%, var(--orange) 100%); -webkit-background-clip: text; background-clip: text; color: transparent; }
:root[data-theme="dark"] .grad { background-image: linear-gradient(90deg, #8f9cff 0%, var(--sky) 50%, var(--orange) 100%); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .grad { background-image: linear-gradient(90deg, #8f9cff 0%, var(--sky) 50%, var(--orange) 100%); } }
.welcome > p { max-width: 520px; margin: 12px auto 30px; color: var(--muted); font-size: 15px; }

.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; text-align: left; }
.card {
    display: grid; grid-template-columns: 40px 1fr; grid-template-rows: auto auto; column-gap: 12px;
    padding: 15px 16px; border-radius: 16px; text-align: left;
    background: var(--surface); border: 1px solid var(--border);
    cursor: pointer; box-shadow: var(--shadow-sm);
    transition: transform .18s, box-shadow .18s, border-color .18s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: color-mix(in srgb, var(--sky) 45%, var(--border)); }
.card-icon { grid-row: span 2; width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; font-size: 18px; font-weight: 800; }
.c-orange { background: rgba(247, 147, 30, .14); color: var(--orange-deep); }
.c-navy { background: rgba(40, 51, 138, .12); color: var(--navy); }
.c-sky { background: rgba(58, 142, 216, .14); color: var(--sky); }
.c-green { background: rgba(18, 163, 127, .13); color: var(--green); }
:root[data-theme="dark"] .c-navy { color: #9aa6ff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .c-navy { color: #9aa6ff; } }
.card-title { font-size: 14px; font-weight: 700; color: var(--text); }
.card-sub { font-size: 12.5px; color: var(--muted); }

.features { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px 18px; margin-top: 26px; font-size: 12.5px; font-weight: 600; color: var(--muted); }

/* Messages */
.msg { display: flex; gap: 14px; margin: 0 0 26px; animation: rise .28s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.msg.user { justify-content: flex-end; }
.msg.user .bubble {
    max-width: min(78%, 620px);
    padding: 11px 16px;
    border-radius: 20px 20px 6px 20px;
    background: var(--user-bubble); color: var(--user-text);
    white-space: pre-wrap; overflow-wrap: anywhere;
    box-shadow: var(--shadow-lg);
    font-size: 15px;
}

.avatar {
    width: 36px; height: 36px; flex-shrink: 0; border-radius: 12px;
    background: #fff url("assets/aviz-logo.png") no-repeat 3px center / 64px auto;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.msg-body { flex: 1; min-width: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.msg-head strong { font-size: 13.5px; }
.msg-head time { font-size: 11.5px; color: var(--muted); }

.content { font-size: 15px; color: var(--text); overflow-wrap: anywhere; }
.content > :first-child { margin-top: 0; }
.content p { margin: 0 0 10px; }
.content h2, .content h3, .content h4 { margin: 18px 0 8px; line-height: 1.35; font-weight: 700; letter-spacing: -.01em; }
.content h2 { font-size: 19px; } .content h3 { font-size: 17px; } .content h4 { font-size: 15.5px; }
.content ul, .content ol { margin: 0 0 12px 22px; }
.content li { margin: 4px 0; padding-left: 2px; }
.content li::marker { color: var(--orange); font-weight: 700; }
.content strong { font-weight: 700; color: var(--text); }
.content a { color: var(--sky); text-decoration: underline; text-underline-offset: 2px; }
.content :not(pre) > code {
    font-family: var(--mono); font-size: 13px;
    padding: 2px 6px; border-radius: 6px;
    background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
}
.content blockquote { margin: 0 0 12px; padding: 6px 14px; border-left: 3px solid var(--orange); color: var(--text-2); background: var(--surface-2); border-radius: 0 10px 10px 0; }

.code-block { margin: 6px 0 14px; border-radius: 14px; overflow: hidden; background: var(--code-bg); border: 1px solid var(--border); }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 7px 10px 7px 14px; background: var(--code-head); color: #a7afd8; font-size: 12px; font-weight: 600; }
.code-copy { display: inline-flex; align-items: center; gap: 5px; border: none; background: none; color: #a7afd8; cursor: pointer; font-size: 12px; padding: 3px 8px; border-radius: 6px; }
.code-copy:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.code-copy svg { width: 14px; height: 14px; }
.code-block pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.code-block code { font-family: var(--mono); font-size: 13px; line-height: 1.65; color: #e6e9fb; }

.table-wrap { overflow-x: auto; margin: 6px 0 14px; border: 1px solid var(--border); border-radius: 12px; }
.content table { border-collapse: collapse; width: 100%; font-size: 13.5px; overflow-wrap: normal; word-break: normal; }
.content th, .content td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; min-width: 120px; }
.content td:first-child { font-weight: 600; white-space: nowrap; min-width: 0; }
.content th { background: var(--surface-2); font-weight: 700; }
.content tr:last-child td { border-bottom: none; }

.msg-actions { display: flex; align-items: center; gap: 4px; margin-top: 6px; color: var(--muted); font-size: 12px; }
.act {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 8px; border-radius: 8px; border: none; background: none;
    color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer;
}
.act:hover { background: var(--surface-2); color: var(--text); }
.act svg { width: 14px; height: 14px; }
.meta-info { margin-left: 6px; }

.msg.blocked .content, .msg.error .content {
    padding: 12px 14px; border-radius: 14px;
    background: var(--blocked-bg); border: 1px solid var(--blocked-border);
}
.msg.error .content { background: var(--error-bg); border-color: var(--error-border); color: var(--error-text); }
.guard-tag { display: inline-flex; align-items: center; gap: 5px; margin-bottom: 6px; font-size: 12px; font-weight: 700; color: var(--orange-deep); }
.guard-tag svg { width: 14px; height: 14px; }
.msg.user.blocked .bubble { background: var(--surface-2); color: var(--muted); box-shadow: none; border: 1px dashed var(--border); font-style: italic; }

.typing { display: inline-flex; gap: 5px; padding: 10px 0; }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--orange); animation: dots 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; background: var(--sky); }
.typing i:nth-child(3) { animation-delay: .3s; background: var(--navy); }
@keyframes dots { 0%, 70%, 100% { transform: scale(.6); opacity: .5; } 35% { transform: scale(1); opacity: 1; } }

/* ================= Composer ================= */
.dock { padding: 0 24px 14px; background: linear-gradient(to top, var(--bg) 70%, transparent); }
.composer {
    max-width: var(--thread-w); margin: 0 auto;
    padding: 12px 12px 10px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: var(--shadow-md);
    transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: color-mix(in srgb, var(--sky) 60%, var(--border)); box-shadow: var(--shadow-md), var(--ring); }
.composer textarea {
    display: block; width: 100%;
    border: none; outline: none; resize: none; background: none;
    color: var(--text); font: inherit; font-size: 15px; line-height: 1.55;
    max-height: 200px; padding: 4px 0;
}
.composer textarea::placeholder { color: var(--muted); }
.composer-bar { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.hint { flex: 1; font-size: 11.5px; color: var(--muted); }
.counter { font-size: 11.5px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.counter.warn { color: var(--orange-deep); }
.btn-send {
    display: grid; place-items: center;
    width: 38px; height: 38px; border-radius: 12px; border: none;
    background: linear-gradient(135deg, var(--orange) 0%, var(--orange-deep) 100%);
    color: #fff; cursor: pointer;
    box-shadow: 0 6px 16px -6px rgba(236, 111, 0, .7);
    transition: transform .15s, opacity .15s;
}
.btn-send:hover:not(:disabled) { transform: translateY(-1px); }
.btn-send:disabled { background: var(--surface-2); color: var(--muted); box-shadow: none; cursor: not-allowed; }
.btn-send svg { stroke-width: 2.4; }
.disclaimer { max-width: var(--thread-w); margin: 8px auto 0; text-align: center; font-size: 11.5px; color: var(--muted); }

.to-bottom {
    position: absolute; left: 50%; bottom: 150px; transform: translate(-50%, 10px);
    display: grid; place-items: center;
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--surface); border: 1px solid var(--border); color: var(--text-2);
    box-shadow: var(--shadow-md); cursor: pointer;
    opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
    z-index: 4;
}
.to-bottom.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }

.toast {
    position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
    padding: 10px 16px; border-radius: 12px;
    background: var(--text); color: var(--bg);
    font-size: 13px; font-weight: 600;
    box-shadow: var(--shadow-lg);
    opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
    z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.scrim { display: none; }

/* scrollbars */
.scroller::-webkit-scrollbar, .conversations::-webkit-scrollbar { width: 10px; }
.scroller::-webkit-scrollbar-thumb, .conversations::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; border: 3px solid var(--bg); }

/* ================= Responsive ================= */
@media (max-width: 900px) {
    .sidebar {
        position: fixed; inset: 0 auto 0 0; z-index: 30;
        width: min(86vw, var(--sidebar-w));
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: none; }
    .brand .sidebar-close { display: grid; }
    .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(8, 10, 25, .45); opacity: 0; pointer-events: none; transition: opacity .25s; }
    .scrim.show { opacity: 1; pointer-events: auto; }
    .menu-btn { display: grid; }
    .btn-new kbd { display: none; }
}
@media (max-width: 640px) {
    .topbar { padding: 10px 12px; gap: 8px; }
    .badges { display: none; }
    .status { padding: 6px 9px; }
    .status #statusText { display: none; }
    .thread { padding: 20px 16px 16px; }
    .welcome { padding-top: 3vh; }
    .welcome-logo { height: 60px; }
    .cards { grid-template-columns: 1fr; }
    .card-sub { display: none; }
    .msg { gap: 10px; }
    .avatar { width: 30px; height: 30px; border-radius: 10px; background-size: 54px auto; background-position: 2px center; }
    .msg.user .bubble { max-width: 88%; }
    .dock { padding: 0 12px calc(10px + env(safe-area-inset-bottom)); }
    .hint { display: none; }
    .composer-bar { justify-content: flex-end; }
    .to-bottom { bottom: 130px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
