/* ==========================================================================
   Admin panel - iOS-26 minimal B&W
   Светлая / тёмная тема через prefers-color-scheme. Никаких декораций,
   только типография, расстояния и тонкие линии.
   ========================================================================== */

:root {
    --bg: #ffffff;
    --bg-elev: #ffffff;
    --bg-soft: #f5f5f7;
    --fg: #000000;
    --fg-muted: #6e6e73;
    --fg-faint: #aeaeb2;
    --border: #d2d2d7;
    --border-soft: #e5e5ea;
    --accent: #000000;
    --bubble-me: #000000;
    --bubble-me-fg: #ffffff;
    --bubble-her: #f0f0f3;
    --bubble-her-fg: #000000;
    --danger: #ff3b30;
    --success: #34c759;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
    --radius: 14px;
    --radius-sm: 10px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #000000;
        --bg-elev: #1c1c1e;
        --bg-soft: #1c1c1e;
        --fg: #ffffff;
        --fg-muted: #98989d;
        --fg-faint: #636366;
        --border: #2c2c2e;
        --border-soft: #1c1c1e;
        --accent: #ffffff;
        --bubble-me: #ffffff;
        --bubble-me-fg: #000000;
        --bubble-her: #1c1c1e;
        --bubble-her-fg: #ffffff;
        --shadow: 0 0 0 1px rgba(255, 255, 255, 0.04);
    }
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--fg);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter",
                 "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

a {
    color: inherit;
    text-decoration: none;
}

a:hover {
    opacity: 0.7;
}

button, input, textarea, select {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    background: transparent;
    border: 0;
    padding: 0;
    margin: 0;
}

input:focus, textarea:focus, button:focus, select:focus {
    outline: none;
}

/* ===== Layout ===== */

.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 220px;
    border-right: 1px solid var(--border);
    background: var(--bg);
    display: flex;
    flex-direction: column;
    padding: 28px 16px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    font-weight: 700;
    font-size: 17px;
    letter-spacing: -0.01em;
    margin-bottom: 32px;
    padding: 0 8px;
}

.brand-sub {
    font-size: 11px;
    font-weight: 500;
    color: var(--fg-faint);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-top: 2px;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    color: var(--fg-muted);
    cursor: pointer;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.nav-item:hover {
    background: var(--bg-soft);
    color: var(--fg);
    opacity: 1;
}

.nav-item.active {
    background: var(--bg-soft);
    color: var(--fg);
    font-weight: 600;
}

.sidebar-footer {
    padding: 10px 8px;
    font-size: 12px;
    color: var(--fg-faint);
    border-top: 1px solid var(--border-soft);
    margin-top: 12px;
}

.status-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    margin-right: 6px;
    vertical-align: middle;
}

.status-dot.off {
    background: var(--danger);
}

/* ===== Main content ===== */

.content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 56px;
    padding: 0 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-soft);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 5;
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
}

.topbar h1 {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin: 0;
}

.topbar-right {
    font-size: 13px;
    color: var(--fg-muted);
    display: flex;
    align-items: center;
    gap: 16px;
}

.page {
    padding: 28px 32px;
    flex: 1;
    min-height: 0;
}

/* ===== Flashes ===== */

.flashes {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.flash {
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    background: var(--bg-elev);
    border: 1px solid var(--border);
    font-size: 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    animation: flash-in 0.3s ease;
}

.flash-error {
    border-color: var(--danger);
    color: var(--danger);
}

@keyframes flash-in {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ===== Chats list ===== */

.chats-grid {
    display: grid;
    gap: 1px;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--border-soft);
}

.chat-row {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    gap: 16px;
    align-items: center;
    padding: 14px 18px;
    background: var(--bg);
    cursor: pointer;
    transition: background-color 0.12s;
}

.chat-row:hover {
    background: var(--bg-soft);
}

.chat-row-main {
    min-width: 0;
}

.chat-row-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-row-id {
    font-size: 11px;
    color: var(--fg-faint);
    font-weight: 500;
    letter-spacing: 0.01em;
    font-family: "SF Mono", "Menlo", monospace;
}

.chat-row-meta {
    font-size: 12px;
    color: var(--fg-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--bg-soft);
    color: var(--fg-muted);
    border: 1px solid var(--border-soft);
}

/* Стейдж-чипсы: визуальный градиент от «мягко» к «приоритет». */
.chip.tone-muted   { color: var(--fg-muted); }
.chip.tone-soft    { color: var(--fg); }
.chip.tone-warm    { color: var(--fg); border-color: var(--fg-muted); }
.chip.tone-hot     { color: var(--fg); border-color: var(--fg); font-weight: 700; }
.chip.tone-primary { background: var(--fg); color: var(--bg); border-color: var(--fg); font-weight: 700; }
.chip.tone-done    { color: var(--fg); border-color: var(--fg); }
.chip.tone-faint   { color: var(--fg-faint); }

/* Бэккомпат для старых стейджей если где-то ещё упомянутся */
.chip.stage-rapport     { color: var(--fg); }
.chip.stage-escalate    { color: var(--fg); border-color: var(--fg); }
.chip.stage-date_set    { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.chip.stage-rejected    { color: var(--fg-faint); }
.chip.stage-dropped     { color: var(--fg-faint); }
.chip.stage-ghosted     { color: var(--fg-muted); }

/* Tabs в стиле iOS-26: segmented control. */
.tabs {
    display: inline-flex;
    background: var(--bg-soft);
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
    margin-bottom: 20px;
}

.tab {
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--fg-muted);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.tab:hover {
    color: var(--fg);
    opacity: 1;
}

.tab.active {
    background: var(--bg);
    color: var(--fg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    font-weight: 600;
}

.tab-count {
    font-size: 11px;
    opacity: 0.6;
    font-variant-numeric: tabular-nums;
}

.tab.active .tab-count {
    opacity: 0.7;
}

/* Шкала теплоты: длинный bar в 100 единиц + полоски-отметки 20/40/60/80 */
.warmth {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-variant-numeric: tabular-nums;
}

.warmth-num {
    font-size: 13px;
    font-weight: 600;
    min-width: 30px;
    text-align: right;
}

.warmth-bar {
    width: 80px;
    height: 5px;
    background: var(--bg-soft);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.warmth-bar::before,
.warmth-bar::after {
    content: "";
    position: absolute;
    top: 0; bottom: 0;
    width: 1px;
    background: var(--border);
    opacity: 0.5;
    pointer-events: none;
}
.warmth-bar::before { left: 50%; }
.warmth-bar::after { left: 75%; }

.warmth-fill {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    background: var(--fg);
    transition: width 0.3s ease;
    border-radius: 3px;
}

.warmth-label {
    font-size: 10px;
    color: var(--fg-faint);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    min-width: 70px;
}

/* Цветовые акценты для теплоты в B&W: контрастность через opacity */
.warmth.tone-cold    .warmth-fill { opacity: 0.35; }
.warmth.tone-cool    .warmth-fill { opacity: 0.5; }
.warmth.tone-neutral .warmth-fill { opacity: 0.7; }
.warmth.tone-warm    .warmth-fill { opacity: 0.9; }
.warmth.tone-hot     .warmth-fill { opacity: 1; }

/* Поиск-инпут */
.toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.search-input {
    background: var(--bg-soft);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 7px 14px;
    font-size: 13px;
    width: 240px;
    transition: border-color 0.12s;
}
.search-input:focus { border-color: var(--fg); }

.thermometer {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 11px;
    font-weight: 600;
    color: var(--fg-muted);
}

.thermometer-bar {
    width: 36px;
    height: 4px;
    background: var(--bg-soft);
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.thermometer-fill {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    background: var(--fg);
    transition: width 0.3s ease;
}

/* ===== Conversation view ===== */

.chat-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    max-width: 880px;
    margin: 0 auto;
}

@media (min-width: 1100px) {
    .chat-layout {
        grid-template-columns: 1fr 280px;
    }
}

.chat-header {
    padding: 18px 0;
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: 8px;
}

.chat-header h2 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 4px 0;
}

.chat-header-meta {
    font-size: 13px;
    color: var(--fg-muted);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 16px 0;
    max-height: calc(100vh - 220px);
    overflow-y: auto;
    scroll-behavior: smooth;
}

.msg {
    max-width: 70%;
    padding: 8px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.35;
    word-wrap: break-word;
    white-space: pre-wrap;
    animation: msg-in 0.18s ease;
}

@keyframes msg-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg.role-user {
    background: var(--bubble-her);
    color: var(--bubble-her-fg);
    align-self: flex-start;
    border-bottom-left-radius: 6px;
}

.msg.role-assistant {
    background: var(--bubble-me);
    color: var(--bubble-me-fg);
    align-self: flex-end;
    border-bottom-right-radius: 6px;
}

.msg-meta {
    font-size: 10px;
    color: var(--fg-faint);
    margin: 2px 14px 8px;
    align-self: inherit;
}

.msg.role-user + .msg-meta { align-self: flex-start; }
.msg.role-assistant + .msg-meta { align-self: flex-end; }

.msg-media-tag {
    display: inline-block;
    margin-right: 6px;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    background: rgba(0, 0, 0, 0.08);
}

.msg.role-assistant .msg-media-tag {
    background: rgba(255, 255, 255, 0.16);
}

.pending-box {
    margin: 12px 0;
    padding: 10px 14px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--fg-muted);
}

.pending-box-title {
    font-size: 10px;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--fg-faint);
    margin-bottom: 6px;
}

.sidebar-card {
    background: var(--bg-soft);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 16px 18px;
}

.sidebar-card h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--fg-faint);
    margin: 0 0 12px;
    font-weight: 700;
}

.facts-grid {
    display: grid;
    gap: 8px;
    font-size: 13px;
}

.facts-grid dt {
    color: var(--fg-faint);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.facts-grid dd {
    margin: 0 0 8px;
    word-break: break-word;
}

/* ===== Settings ===== */

.settings-form {
    max-width: 720px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 20px 0;
    border-bottom: 1px solid var(--border-soft);
}

.field-label {
    font-size: 14px;
    font-weight: 600;
}

.field-desc {
    font-size: 12px;
    color: var(--fg-muted);
}

.field-input,
.field-textarea {
    background: var(--bg-soft);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 14px;
    width: 100%;
    transition: border-color 0.12s;
}

.field-textarea {
    min-height: 60px;
    resize: vertical;
    font-family: inherit;
}

.field-input:focus,
.field-textarea:focus {
    border-color: var(--fg);
}

.toggle {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toggle input[type="checkbox"] {
    appearance: none;
    width: 44px;
    height: 26px;
    background: var(--border);
    border-radius: 999px;
    position: relative;
    cursor: pointer;
    transition: background-color 0.2s;
}

.toggle input[type="checkbox"]:checked {
    background: var(--fg);
}

.toggle input[type="checkbox"]::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 22px;
    height: 22px;
    background: var(--bg);
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle input[type="checkbox"]:checked::after {
    transform: translateX(18px);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    background: var(--fg);
    color: var(--bg);
    cursor: pointer;
    transition: opacity 0.12s;
}

.btn:hover {
    opacity: 0.85;
}

.btn-ghost {
    background: transparent;
    color: var(--fg);
    border: 1px solid var(--border);
}

.actions {
    padding: 24px 0;
    display: flex;
    gap: 12px;
}

/* ===== Login ===== */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.login-card {
    width: 100%;
    max-width: 360px;
    padding: 40px 32px;
}

.login-card h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 4px;
}

.login-card .login-sub {
    font-size: 13px;
    color: var(--fg-muted);
    margin-bottom: 28px;
}

.login-card .field {
    border: 0;
    padding: 8px 0;
}

/* ===== Empty states ===== */

.empty {
    padding: 60px 0;
    text-align: center;
    color: var(--fg-faint);
    font-size: 14px;
}

/* ===== Mobile ===== */

@media (max-width: 720px) {
    .sidebar {
        position: fixed;
        left: -240px;
        transition: left 0.2s;
        z-index: 20;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.1);
    }
    .sidebar.open {
        left: 0;
    }
    .topbar {
        padding: 0 16px;
    }
    .page {
        padding: 20px 16px;
    }
    .chat-row {
        grid-template-columns: 1fr;
        gap: 4px;
    }
    .msg {
        max-width: 88%;
    }
}
