/* ============================================================
   Mini CRM — design system
   Inspired by Linear / Notion / Vercel: clean, light, indigo accent.
   ============================================================ */

:root {
    --color-bg: #f7f8fc;
    --color-surface: #ffffff;
    --color-surface-2: #f1f3f9;
    --color-border: #e4e7ee;
    --color-border-strong: #d4d8e2;

    --color-text: #0f172a;
    --color-text-muted: #64748b;
    --color-text-soft: #94a3b8;

    --color-primary: #6366f1;
    --color-primary-hover: #4f46e5;
    --color-primary-soft: #eef0ff;
    --color-primary-text: #ffffff;

    --color-success: #16a34a;
    --color-success-soft: #dcfce7;
    --color-warning: #d97706;
    --color-warning-soft: #fef3c7;
    --color-danger: #dc2626;
    --color-danger-soft: #fee2e2;
    --color-info: #0891b2;
    --color-info-soft: #cffafe;

    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
    --shadow-pop: 0 0 0 1px rgba(99, 102, 241, 0.4), 0 8px 24px rgba(99, 102, 241, 0.18);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-pill: 9999px;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
    --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;

    --header-h: 60px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--color-primary); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--color-primary-hover); }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.95rem; }
p { margin: 0; }

code { font-family: var(--font-mono); font-size: 0.85em; }

/* ------------------ Layout shells ------------------ */
.container {
    max-width: 1480px;
    margin: 0 auto;
    padding: 24px 28px;
}

/* ------------------ Topbar ------------------ */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--color-border);
    height: var(--header-h);
}
.topbar-inner {
    max-width: 1480px;
    margin: 0 auto;
    height: 100%;
    padding: 0 28px;
    display: flex;
    align-items: center;
    gap: 28px;
}
.topbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.01em;
    color: var(--color-text);
}
.topbar-brand:hover { color: var(--color-text); }
.topbar-brand::before {
    content: "";
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: linear-gradient(135deg, var(--color-primary) 0%, #8b5cf6 100%);
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.4);
}
.topbar nav { flex: 1; }
.topbar nav ul {
    display: flex;
    gap: 4px;
    list-style: none;
    margin: 0;
    padding: 0;
}
.topbar nav a {
    display: inline-flex;
    align-items: center;
    padding: 7px 14px;
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-weight: 500;
    font-size: 0.9rem;
    transition: background 0.12s, color 0.12s;
}
.topbar nav a:hover {
    background: var(--color-surface-2);
    color: var(--color-text);
}
.topbar-user {
    display: flex;
    gap: 8px;
    align-items: center;
}
.topbar-user span {
    padding: 6px 12px;
    border-radius: var(--radius-pill);
    background: var(--color-primary-soft);
    color: var(--color-primary-hover);
    font-weight: 500;
    font-size: 0.85rem;
}

/* ------------------ Buttons ------------------ */
button,
.btn,
input[type=submit] {
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 0.875rem;
    line-height: 1;
    padding: 9px 16px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    background: var(--color-primary);
    color: var(--color-primary-text);
    cursor: pointer;
    transition: background 0.15s, transform 0.05s, box-shadow 0.15s;
    white-space: nowrap;
}
button:hover,
.btn:hover {
    background: var(--color-primary-hover);
}
button:active { transform: translateY(1px); }
button.secondary,
.btn.secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border);
}
button.secondary:hover,
.btn.secondary:hover {
    background: var(--color-surface-2);
    color: var(--color-text);
}
button.outline,
.btn.outline {
    background: transparent;
    border-color: var(--color-border-strong);
    color: var(--color-text-muted);
}
button.outline:hover,
.btn.outline:hover {
    background: var(--color-surface-2);
    color: var(--color-text);
}
button.danger { background: var(--color-danger); }
button.danger:hover { background: #b91c1c; }

a.btn { display: inline-flex; align-items: center; text-decoration: none; }

/* ------------------ Forms ------------------ */
input[type=text],
input[type=password],
input[type=email],
input[type=url],
input[type=search],
input[type=number],
select,
textarea {
    width: 100%;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 9px 12px;
    transition: border 0.15s, box-shadow 0.15s;
    appearance: none;
}
textarea { resize: vertical; min-height: 64px; }
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 12px;
    padding-right: 32px;
}
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

label {
    display: block;
    color: var(--color-text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 4px;
    letter-spacing: 0.01em;
}
form > label,
.card-form > label {
    display: block;
    color: var(--color-text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 10px;
}
form > label > input,
form > label > select,
form > label > textarea,
.card-form > label > input,
.card-form > label > select,
.card-form > label > textarea {
    margin-top: 4px;
    color: var(--color-text);
    font-weight: 400;
    font-size: 0.9rem;
}

/* ------------------ Login ------------------ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background:
        radial-gradient(1200px 600px at 10% 0%, rgba(99, 102, 241, 0.18), transparent 60%),
        radial-gradient(800px 600px at 90% 100%, rgba(139, 92, 246, 0.18), transparent 60%),
        var(--color-bg);
}
.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: 32px;
    box-shadow: var(--shadow-lg);
}
.login-card h1 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.4rem;
}
.login-card h1::before {
    content: "";
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--color-primary) 0%, #8b5cf6 100%);
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.4);
}
.login-card .subtitle {
    color: var(--color-text-muted);
    margin-top: 6px;
    margin-bottom: 24px;
    font-size: 0.9rem;
}
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card button { width: 100%; padding: 11px 16px; margin-top: 6px; }

.alert {
    padding: 10px 14px;
    border-radius: var(--radius-md);
    margin-bottom: 14px;
    font-size: 0.875rem;
    border: 1px solid transparent;
}
.alert-error {
    background: var(--color-danger-soft);
    color: var(--color-danger);
    border-color: rgba(220, 38, 38, 0.2);
}

/* ------------------ Inbox ------------------ */
.inbox h1.page-title { margin-bottom: 18px; }

.inbox-counters {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
    margin-bottom: 22px;
}
.counter {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: transform 0.12s, box-shadow 0.12s;
}
.counter:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.counter-label {
    color: var(--color-text-muted);
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.counter-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.02em;
}

.inbox-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    background: var(--color-surface);
    padding: 12px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    margin-bottom: 14px;
}
.inbox-filters select,
.inbox-filters input {
    width: auto;
    flex: 0 1 180px;
    min-width: 120px;
}
.inbox-filters input[type=search] { flex: 1 1 220px; }
.inbox-filters .spacer { flex: 1; }
.inbox-filters > a { display: inline-flex; align-items: center; }

/* ------------------ Dialog list ------------------ */
.inbox-list {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.dialog-list {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.dialog-list thead {
    background: var(--color-surface-2);
}
.dialog-list th {
    text-align: left;
    padding: 10px 14px;
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border);
}
.dialog-list td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}
.dialog-list tbody tr {
    cursor: pointer;
    transition: background 0.12s;
}
.dialog-list tbody tr:hover {
    background: var(--color-primary-soft);
}
.dialog-list tbody tr:last-child td { border-bottom: none; }
.dialog-list .id-col { color: var(--color-text-soft); font-variant-numeric: tabular-nums; }

/* Avatar circle for counterparty */
.counterparty {
    display: flex;
    align-items: center;
    gap: 10px;
}
.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary) 0%, #8b5cf6 100%);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.78rem;
    flex-shrink: 0;
    text-transform: uppercase;
}
.avatar.avatar-customer { background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%); }

/* ------------------ Badges ------------------ */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.5;
    letter-spacing: 0.01em;
    border: 1px solid transparent;
}
.badge-new {
    background: var(--color-primary-soft);
    color: var(--color-primary-hover);
    border-color: rgba(99, 102, 241, 0.2);
}
.badge-info {
    background: var(--color-info-soft);
    color: var(--color-info);
    border-color: rgba(8, 145, 178, 0.2);
}
.badge-warning {
    background: var(--color-warning-soft);
    color: var(--color-warning);
    border-color: rgba(217, 119, 6, 0.2);
}
.badge-success {
    background: var(--color-success-soft);
    color: var(--color-success);
    border-color: rgba(22, 163, 74, 0.2);
}
.badge-danger {
    background: var(--color-danger-soft);
    color: var(--color-danger);
    border-color: rgba(220, 38, 38, 0.2);
}
.badge-muted {
    background: var(--color-surface-2);
    color: var(--color-text-muted);
    border-color: var(--color-border);
}
.bot-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.78rem;
    color: var(--color-text-muted);
    font-weight: 500;
}
.bot-tag::before {
    content: "";
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-primary);
}
.bot-tag.bot-seller::before { background: #f59e0b; }

/* ------------------ Empty / muted ------------------ */
.empty {
    padding: 56px 24px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.95rem;
}
.muted { color: var(--color-text-muted); font-size: 0.85rem; margin: 0.2rem 0; }
.text-soft { color: var(--color-text-soft); }

/* ------------------ Chat ------------------ */
.chat-container { max-width: 1480px; }
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 14px;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}
.back-link:hover { color: var(--color-text); }

.chat-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 18px;
    height: calc(100vh - var(--header-h) - 80px);
    min-height: 560px;
}
@media (max-width: 1024px) {
    .chat-layout {
        grid-template-columns: 1fr;
        height: auto;
    }
}

.chat-thread {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--color-surface);
}
.chat-header .avatar { width: 40px; height: 40px; font-size: 0.9rem; }
.chat-header h2 { font-size: 1.05rem; }
.chat-header small {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--color-text-muted);
    font-size: 0.78rem;
    margin-top: 2px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 22px 24px;
    background:
        radial-gradient(1200px 700px at 50% 100%, rgba(99, 102, 241, 0.04), transparent 60%),
        var(--color-bg);
}
.chat-messages::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
    background: var(--color-border-strong);
    border-radius: 4px;
}

.messages {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.message {
    max-width: 70%;
    border-radius: 16px;
    padding: 10px 14px;
    box-shadow: var(--shadow-xs);
    line-height: 1.45;
}
.message header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
    font-size: 0.72rem;
    opacity: 0.7;
    font-weight: 500;
}
.message-text {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.92rem;
}
.message-in {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.message-out {
    background: linear-gradient(135deg, var(--color-primary) 0%, #8b5cf6 100%);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.25);
}
.message-out a { color: #ddd6fe; }
.message-out header { opacity: 0.85; }

.attachments {
    list-style: none;
    margin: 6px 0 0;
    padding: 0;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.attachments img {
    max-width: 240px;
    max-height: 240px;
    border-radius: 10px;
    display: block;
    border: 1px solid rgba(255, 255, 255, 0.4);
}
.message-in .attachments img { border-color: var(--color-border); }
.attachments a {
    display: inline-block;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    font-size: 0.82rem;
    text-decoration: none;
}
.message-in .attachments a {
    background: var(--color-surface-2);
    color: var(--color-primary-hover);
}

/* ------------------ Reply form ------------------ */
.reply-form {
    border-top: 1px solid var(--color-border);
    padding: 12px 14px;
    background: var(--color-surface);
    display: flex;
    gap: 10px;
    align-items: flex-end;
}
.reply-form textarea {
    flex: 1;
    border-radius: var(--radius-md);
    min-height: 44px;
    max-height: 200px;
    padding: 11px 14px;
}
.reply-form button { padding: 11px 18px; }

/* ------------------ Sidebar (chat right pane) ------------------ */
.chat-sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    padding-right: 2px;
}
.chat-sidebar::-webkit-scrollbar { width: 8px; }
.chat-sidebar::-webkit-scrollbar-thumb {
    background: var(--color-border-strong);
    border-radius: 4px;
}

.request-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin: 0;
}
.request-card > header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--color-border);
}
.request-card > header h3 { margin: 0; }
.request-card dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 6px 14px;
    margin: 0 0 14px;
    font-size: 0.85rem;
}
.request-card dt { color: var(--color-text-muted); font-weight: 500; }
.request-card dd { margin: 0; word-break: break-word; }

.card-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid var(--color-border);
    padding-top: 14px;
    margin-top: 14px;
}
.card-form > label { margin-bottom: 0; }
.card-form button { align-self: flex-start; padding: 7px 14px; font-size: 0.82rem; }

/* ------------------ Notes ------------------ */
.notes-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 16px;
}
.notes-section > h4 {
    margin: 0 0 12px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}
.notes-section > h4::before {
    content: "";
    display: inline-block;
    width: 4px;
    height: 14px;
    background: var(--color-warning);
    border-radius: 2px;
}
#notes-block .card-form {
    border-top: none;
    padding-top: 0;
    margin-top: 0;
}
.notes-list {
    list-style: none;
    margin: 14px 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.notes-list li {
    background: var(--color-warning-soft);
    border-left: 3px solid var(--color-warning);
    padding: 8px 12px;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}
.notes-list header {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    margin-bottom: 4px;
    color: var(--color-warning);
    font-weight: 500;
}
.notes-list p {
    margin: 0;
    white-space: pre-wrap;
    color: var(--color-text);
    font-size: 0.9rem;
}

/* ------------------ Status history ------------------ */
.status-history {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
}
.status-history > summary {
    cursor: pointer;
    font-weight: 500;
    color: var(--color-text-muted);
    list-style: none;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 6px;
}
.status-history > summary::before {
    content: "›";
    font-size: 1.1rem;
    transition: transform 0.15s;
    color: var(--color-text-soft);
}
.status-history[open] > summary::before { transform: rotate(90deg); }
.status-history > summary::-webkit-details-marker { display: none; }
.status-history ul {
    list-style: none;
    margin: 12px 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.status-history li {
    border-left: 2px solid var(--color-border-strong);
    padding-left: 12px;
}
.status-history li small {
    display: block;
    color: var(--color-text-soft);
    font-size: 0.76rem;
    margin-top: 2px;
}

/* ------------------ Operators page ------------------ */
.operators-page table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-top: 16px;
    font-size: 0.88rem;
}
.operators-page thead { background: var(--color-surface-2); }
.operators-page th {
    text-align: left;
    padding: 10px 14px;
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border);
}
.operators-page td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}
.operators-page tbody tr:last-child td { border-bottom: none; }
.operators-page code.token {
    background: var(--color-warning-soft);
    color: var(--color-warning);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.78rem;
    word-break: break-all;
}
.row-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
}
.row-actions form, .row-actions details { margin: 0; }
.row-actions button {
    margin: 0;
    padding: 5px 10px;
    font-size: 0.75rem;
}
.row-actions details summary {
    cursor: pointer;
    font-size: 0.78rem;
    color: var(--color-text-muted);
    list-style: none;
    user-select: none;
    padding: 5px 10px;
    border-radius: 6px;
}
.row-actions details summary:hover { background: var(--color-surface-2); }
.row-actions details summary::-webkit-details-marker { display: none; }
.inline-form {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}
.inline-form input { flex: 1; padding: 6px 10px; font-size: 0.85rem; }
.inline-form button { padding: 6px 12px; font-size: 0.8rem; }

.add-operator {
    margin-top: 24px;
    padding: 16px 20px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}
.add-operator > summary {
    cursor: pointer;
    list-style: none;
    user-select: none;
    color: var(--color-primary);
    font-weight: 500;
}
.add-operator > summary::-webkit-details-marker { display: none; }
.add-operator form {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.add-operator .grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}
.add-operator button { align-self: flex-start; }

/* ------------------ Page title block ------------------ */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    gap: 14px;
}
.page-header h1 { margin: 0; }
.page-header .subtitle {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    margin-top: 4px;
}

/* ------------------ Auto-replies page ------------------ */
.auto-replies-page .muted {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    margin: -4px 0 18px;
}
.auto-reply-empty {
    background: var(--color-surface);
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius-lg);
    padding: 28px;
    text-align: center;
    color: var(--color-text-muted);
}
.auto-reply-group { margin-top: 24px; }
.auto-reply-group h2 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    font-weight: 600;
    margin: 0 0 12px;
}
.auto-reply-list {
    display: grid;
    gap: 14px;
}
.auto-reply-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-xs);
    transition: box-shadow 0.15s ease;
}
.auto-reply-card:hover { box-shadow: var(--shadow-sm); }
.auto-reply-card.is-disabled {
    opacity: 0.65;
    background: var(--color-surface-2);
}
.auto-reply-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 10px;
}
.auto-reply-card-head h3 {
    margin: 0 0 6px;
    font-size: 1rem;
    font-weight: 600;
}
.auto-reply-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 0.82rem;
}
.auto-reply-card .row-actions {
    flex-direction: row;
    gap: 6px;
}
.auto-reply-card details > summary {
    cursor: pointer;
    list-style: none;
    user-select: none;
    color: var(--color-primary);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 4px 0;
}
.auto-reply-card details > summary::-webkit-details-marker { display: none; }
.auto-reply-text {
    margin: 12px 0 0;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    font-family: var(--font-sans);
    font-size: 0.88rem;
    color: var(--color-text);
    white-space: pre-wrap;
    word-wrap: break-word;
}
.auto-reply-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 14px;
}
.auto-reply-form .grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}
.auto-reply-form textarea {
    font-family: var(--font-sans);
    width: 100%;
    resize: vertical;
}
.auto-reply-form .form-row {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}
.auto-reply-form .checkbox-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
}
.auto-reply-form .checkbox-row input { width: auto; }
.add-auto-reply {
    margin-top: 24px;
    padding: 16px 20px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}
.add-auto-reply > summary {
    cursor: pointer;
    list-style: none;
    user-select: none;
    color: var(--color-primary);
    font-weight: 500;
}
.add-auto-reply > summary::-webkit-details-marker { display: none; }

/* ------------------ Tasks page ------------------ */
.tasks-page .page-header { margin-bottom: 16px; }
.tasks-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-top: 16px;
    font-size: 0.88rem;
}
.tasks-table thead { background: var(--color-surface-2); }
.tasks-table th {
    text-align: left;
    padding: 10px 14px;
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border);
}
.tasks-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
}
.tasks-table tbody tr:last-child td { border-bottom: none; }
.tasks-table tbody tr:hover { background: var(--color-surface-2); }

.task-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
}
.task-form .grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}
.task-form textarea { font-family: var(--font-sans); width: 100%; resize: vertical; }
.task-form .form-row {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 6px;
}

.task-detail .task-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
    gap: 24px;
    margin-top: 16px;
}
.task-detail .task-column h2 {
    margin: 0 0 12px;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    font-weight: 600;
}
.task-detail .task-column h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    font-weight: 600;
    margin: 0 0 10px;
}
.task-detail .task-code {
    background: var(--color-primary-soft);
    color: var(--color-primary-hover);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-right: 8px;
}
.task-detail .row-actions form select {
    width: 100%;
    margin-bottom: 4px;
}
.task-detail .row-actions form input[type="text"] {
    width: 100%;
    margin-bottom: 4px;
    font-size: 0.8rem;
}
.task-detail .row-actions form button {
    padding: 5px 12px;
    font-size: 0.78rem;
}

@media (max-width: 980px) {
    .task-detail .task-grid { grid-template-columns: 1fr; }
}

/* ------------------ Alerts / Auth ------------------ */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin: 12px 0;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    font-size: 0.92rem;
}
.alert-success {
    background: rgba(16, 185, 129, 0.08);
    border-color: rgba(16, 185, 129, 0.3);
    color: #047857;
}
.alert-danger,
.alert-error {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.3);
    color: #b91c1c;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}
.auth-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 28px 32px;
    max-width: 420px;
    width: 100%;
    box-shadow: var(--shadow-sm);
}
.auth-card header h1 { margin-top: 0; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }

.account-page .auto-reply-card { margin-bottom: 16px; }

/* ------------------ Settings: bots ------------------ */
.settings-bots-page .cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 18px;
    margin-top: 18px;
}
.settings-bots-page .card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: var(--shadow-xs);
}
.settings-bots-page .card header h2 {
    margin: 0 0 4px;
    font-size: 1.05rem;
}
.settings-bots-page .card header .muted { font-size: 0.86rem; margin: 0; }
.settings-bots-page .card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--color-surface-2);
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    flex-wrap: wrap;
    min-width: 0;
}
.settings-bots-page .card-row code {
    overflow-wrap: anywhere;
    word-break: break-all;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
    font-size: 0.85rem;
}
.settings-bots-page .card form input[type="text"] {
    width: 100%;
    box-sizing: border-box;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
    font-size: 0.88rem;
}
.settings-bots-page .card form.stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.settings-bots-page .card form.inline-form {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    border-top: 1px dashed var(--color-border);
    padding-top: 12px;
}
.settings-bots-page .card .actions { display: flex; gap: 8px; }
.settings-bots-page .settings-help {
    margin-top: 28px;
    padding: 18px 20px;
    background: var(--color-primary-soft);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(99, 102, 241, 0.2);
}
.settings-bots-page .settings-help h3 { margin-top: 0; }
.settings-bots-page .settings-help ol { padding-left: 22px; line-height: 1.6; }

/* ------------------ Mobile tweaks ------------------ */
@media (max-width: 720px) {
    .container { padding: 16px; }
    .topbar-inner { padding: 0 16px; gap: 14px; }
    .topbar nav { display: none; }
    .inbox-counters { grid-template-columns: repeat(2, 1fr); }
    .message { max-width: 90%; }
}
