/* ─── Relay App — Dark Mode CSS ─── */

:root {
    --bg:        oklch(16% 0.010 170);
    --surface:   oklch(20% 0.012 170);
    --surface2:  oklch(24% 0.014 170);
    --text:      oklch(97% 0.005 170);
    --text2:     oklch(80% 0.010 170);
    --subtle:    oklch(62% 0.012 170);
    --hairline:  oklch(28% 0.010 170);
    --primary:   oklch(72% 0.13 165);
    --primaryBg: oklch(26% 0.04 165);
    --onPrimary: oklch(16% 0.01 170);
    --success:   oklch(75% 0.15 145);
    --warning:   oklch(78% 0.15 75);
    --danger:    oklch(72% 0.17 25);
    --ai:        oklch(75% 0.14 275);
    --aiBg:      oklch(26% 0.05 275);
    --incoming:  oklch(24% 0.012 170);
    --outgoing:  oklch(36% 0.08 165);

    --font: 'Geist', 'Inter', system-ui, -apple-system, sans-serif;
    --radius: 14px;
    --radius-sm: 10px;
    --radius-xs: 6px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%; width: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;
}

/* Scrollbar hide */
* { scrollbar-width: none; }
*::-webkit-scrollbar { display: none; }

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* ─── Layout ─── */
.app-shell {
    display: flex;
    height: 100%;
    width: 100%;
}

/* Desktop sidebar (chat list on left) */
.sidebar {
    width: 380px;
    min-width: 380px;
    height: 100%;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--hairline);
    background: var(--bg);
}

.main-panel {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    min-width: 0;
}

/* Mobile: full width, no sidebar split */
@media (max-width: 768px) {
    .sidebar { width: 100%; min-width: 100%; }
    .main-panel { display: none; }
    .app-shell.chat-open .sidebar { display: none; }
    .app-shell.chat-open .main-panel { display: flex; width: 100%; }
}

/* ─── Top bar ─── */
.top-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 8px;
    background: var(--bg);
    border-bottom: 1px solid var(--hairline);
    min-height: 60px;
    flex-shrink: 0;
}
.top-bar .title {
    flex: 1;
    min-width: 0;
    padding-left: 8px;
}
.top-bar .title h2 {
    font-size: 21px;
    font-weight: 600;
    letter-spacing: -0.2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.top-bar .title .subtitle {
    font-size: 12px;
    color: var(--subtle);
    margin-top: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.top-bar.compact { min-height: 48px; padding: 6px 8px; }
.top-bar.compact .title h2 { font-size: 17px; }

/* ─── Icon button ─── */
.icon-btn {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    background: transparent;
    border: none;
    color: var(--text);
    cursor: pointer;
    border-radius: 22px;
    flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface); }

/* ─── Avatar ─── */
.avatar {
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 600;
    border-radius: 50%;
    flex-shrink: 0;
    position: relative;
}
.avatar.sm { width: 36px; height: 36px; font-size: 13px; }
.avatar.md { width: 44px; height: 44px; font-size: 15px; }
.avatar.lg { width: 48px; height: 48px; font-size: 16px; }
.avatar.xl { width: 60px; height: 60px; font-size: 22px; }

.avatar .badge {
    position: absolute;
    right: -3px;
    bottom: -3px;
    width: 18px;
    height: 18px;
    border-radius: 9px;
    border: 2px solid var(--bg);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    display: grid;
    place-items: center;
}

/* ─── Filter chips ─── */
.chips-bar {
    display: flex;
    gap: 8px;
    padding: 10px 14px;
    overflow-x: auto;
    background: var(--bg);
    border-bottom: 1px solid var(--hairline);
    flex-shrink: 0;
}
.chip {
    height: 32px;
    padding: 0 12px;
    border-radius: 16px;
    background: var(--surface);
    color: var(--text2);
    border: 1px solid var(--hairline);
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    cursor: pointer;
    white-space: nowrap;
}
.chip:hover { background: var(--surface2); }
.chip.active {
    background: var(--primary);
    color: var(--onPrimary);
    border-color: var(--primary);
}
.chip .count {
    font-size: 11px;
    opacity: 0.8;
    font-weight: 600;
    background: rgba(255,255,255,0.15);
    padding: 1px 6px;
    border-radius: 8px;
}
.chip.active .count { background: rgba(255,255,255,0.2); }

/* ─── Chat row ─── */
.chat-row {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    align-items: center;
    border-bottom: 1px solid var(--hairline);
    cursor: pointer;
    transition: background 80ms;
}
.chat-row:hover { background: var(--surface); }
.chat-row.active { background: var(--primaryBg); }
.chat-row .info { flex: 1; min-width: 0; }
.chat-row .info .top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}
.chat-row .info .name {
    font-size: 15px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-row .info .time {
    font-size: 11px;
    color: var(--subtle);
    flex-shrink: 0;
}
.chat-row .info .time.unread { color: var(--primary); font-weight: 600; }
.chat-row .info .bottom {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
    font-size: 13px;
    color: var(--subtle);
}
.chat-row .info .preview {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.unread-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--primary);
    color: var(--onPrimary);
    font-size: 10px;
    font-weight: 700;
    display: grid;
    place-items: center;
}
.tag-badge {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.3px;
    padding: 2px 6px;
    border-radius: 4px;
}
.tag-badge.order { color: var(--success); background: color-mix(in oklch, var(--success) 18%, transparent); }
.tag-badge.spam { color: var(--danger); background: color-mix(in oklch, var(--danger) 18%, transparent); }
.tag-badge.support { color: var(--warning); background: color-mix(in oklch, var(--warning) 18%, transparent); }

/* ─── Timer badge (sequence view) ─── */
.timer-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-variant-numeric: tabular-nums;
}
.timer-badge.critical { color: var(--danger); background: color-mix(in oklch, var(--danger) 14%, transparent); }
.timer-badge.warn { color: #e09932; background: color-mix(in oklch, #e09932 14%, transparent); }
.timer-badge.ok { color: var(--primary); background: color-mix(in oklch, var(--primary) 14%, transparent); }

/* ─── Messages area ─── */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--bg);
    background-image: radial-gradient(var(--surface) 1px, transparent 1px);
    background-size: 16px 16px;
}
.msg-bubble {
    max-width: 78%;
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.4;
    word-break: break-word;
}
.msg-bubble.incoming {
    align-self: flex-start;
    background: var(--incoming);
    border: 1px solid var(--hairline);
    border-top-left-radius: 4px;
}
.msg-bubble.outgoing {
    align-self: flex-end;
    background: var(--outgoing);
    border-top-right-radius: 4px;
}
.msg-bubble .msg-time {
    font-size: 10px;
    color: var(--subtle);
    text-align: right;
    margin-top: 2px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
}
.msg-system {
    align-self: center;
    font-size: 11px;
    color: var(--primary);
    background: var(--primaryBg);
    padding: 6px 12px;
    border-radius: 10px;
    font-weight: 500;
    display: flex;
    gap: 6px;
    align-items: center;
    margin: 4px 0;
}
.msg-date-divider {
    align-self: center;
    font-size: 11px;
    color: var(--subtle);
    background: var(--surface2);
    padding: 4px 10px;
    border-radius: 10px;
    margin-bottom: 4px;
}

/* ─── Composer ─── */
.composer {
    background: var(--bg);
    padding: 8px 10px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.composer-input {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    border-radius: 20px;
    background: var(--surface);
    border: 1px solid var(--hairline);
    display: flex;
    align-items: center;
    padding: 0 14px;
    gap: 8px;
}
.composer-input input, .composer-input textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    outline: none;
    resize: none;
    min-height: 36px;
}
.composer-input input::placeholder, .composer-input textarea::placeholder {
    color: var(--subtle);
}
.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 22px;
    border: none;
    background: var(--primary);
    color: var(--onPrimary);
    display: grid;
    place-items: center;
    cursor: pointer;
    flex-shrink: 0;
}
.send-btn:disabled { background: var(--surface2); color: var(--subtle); cursor: not-allowed; }

/* ─── Tab bar (mobile) ─── */
.tab-bar {
    display: flex;
    border-top: 1px solid var(--hairline);
    background: var(--bg);
    padding: 6px 4px 10px;
    flex-shrink: 0;
}
.tab-bar .tab {
    flex: 1;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--subtle);
    padding: 6px 0;
    position: relative;
}
.tab-bar .tab.active { color: var(--primary); }
.tab-bar .tab .tab-icon {
    position: relative;
    background: transparent;
    border-radius: 14px;
    padding: 4px 16px;
    transition: background 150ms;
}
.tab-bar .tab.active .tab-icon { background: var(--primaryBg); }
.tab-bar .tab .tab-label { font-size: 11px; font-weight: 500; letter-spacing: 0.1px; }
.tab-bar .tab.active .tab-label { font-weight: 600; }
.tab-bar .tab .tab-badge {
    position: absolute;
    top: 0;
    right: 8px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: grid;
    place-items: center;
}

/* ─── FAB ─── */
.fab {
    position: fixed;
    right: 18px;
    bottom: 90px;
    width: 56px;
    height: 56px;
    border-radius: 18px;
    border: none;
    background: var(--primary);
    color: var(--onPrimary);
    box-shadow: 0 8px 20px -4px rgba(0,0,0,0.25);
    cursor: pointer;
    display: grid;
    place-items: center;
    z-index: 10;
}
@media (min-width: 769px) {
    .fab { bottom: 24px; right: 24px; }
}

/* ─── Bottom sheet ─── */
.sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 50;
    display: flex;
    align-items: flex-end;
    animation: fadeIn 150ms;
}
.sheet {
    background: var(--bg);
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    border-radius: 20px 20px 0 0;
    padding: 16px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 200ms cubic-bezier(0.2,0.8,0.2,1);
}
@media (min-width: 769px) {
    .sheet-overlay { align-items: center; justify-content: center; }
    .sheet { border-radius: 20px; max-height: 80vh; }
}
.sheet .handle {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--hairline);
    margin: 0 auto 14px;
}
.sheet-title { font-size: 20px; font-weight: 600; letter-spacing: -0.3px; margin-bottom: 4px; }
.sheet-subtitle { font-size: 13px; color: var(--subtle); margin-bottom: 16px; line-height: 1.5; }

/* ─── Form elements ─── */
.form-label {
    font-size: 11px;
    color: var(--subtle);
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin: 14px 2px 6px;
}
.form-input {
    width: 100%;
    height: 46px;
    padding: 0 14px;
    border-radius: 12px;
    border: 1px solid var(--hairline);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    outline: none;
}
.form-input:focus { border-color: var(--primary); }
.form-input::placeholder { color: var(--subtle); }

.form-textarea {
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--hairline);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    outline: none;
    resize: none;
    line-height: 1.45;
}
.form-textarea:focus { border-color: var(--primary); }

/* ─── Buttons ─── */
.btn {
    height: 46px;
    padding: 0 20px;
    border-radius: 12px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.btn-primary { background: var(--primary); color: var(--onPrimary); }
.btn-primary:disabled { background: var(--surface2); color: var(--subtle); cursor: not-allowed; }
.btn-outline { background: transparent; border: 1px solid var(--hairline); color: var(--text); }
.btn-danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn-sm { height: 32px; padding: 0 12px; border-radius: 10px; font-size: 12px; }

/* ─── Toggle ─── */
.toggle {
    width: 44px;
    height: 24px;
    border-radius: 12px;
    background: var(--surface2);
    border: none;
    cursor: pointer;
    position: relative;
    transition: background 200ms;
    flex-shrink: 0;
}
.toggle.on { background: var(--primary); }
.toggle::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #fff;
    top: 2px;
    left: 2px;
    transition: transform 200ms;
}
.toggle.on::after { transform: translateX(20px); }

/* ─── Toast ─── */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    z-index: 100;
    box-shadow: 0 6px 18px rgba(0,0,0,0.2);
    white-space: nowrap;
    animation: fadeIn 150ms;
}

/* ─── Card ─── */
.card {
    padding: 16px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--hairline);
}

/* ─── Section title ─── */
.section-title {
    font-size: 11px;
    color: var(--subtle);
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin: 0 4px 8px;
}

/* ─── Empty state ─── */
.empty-state {
    padding: 40px;
    text-align: center;
    color: var(--subtle);
    font-size: 13px;
}

/* ─── Scrollable content ─── */
.scroll-y {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ─── Stat card ─── */
.stat-card {
    padding: 16px;
    border-radius: var(--radius);
    background: var(--primary);
    color: var(--onPrimary);
    margin-bottom: 12px;
}
.stat-card .stat-label {
    font-size: 11px;
    opacity: 0.85;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.stat-card .stat-row {
    display: flex;
    align-items: baseline;
    gap: 18px;
    margin-top: 6px;
}
.stat-card .stat-num { font-size: 28px; font-weight: 700; letter-spacing: -1px; }
.stat-card .stat-sub { font-size: 12px; opacity: 0.85; }

/* ─── Login page ─── */
.login-page {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 28px;
    max-width: 420px;
    margin: 0 auto;
    width: 100%;
}
.login-logo {
    width: 60px;
    height: 60px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--primary), var(--ai));
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 700;
    font-size: 26px;
    margin-top: 60px;
}
.login-title {
    font-size: 34px;
    font-weight: 600;
    letter-spacing: -1px;
    margin-top: 24px;
}
.login-sub {
    font-size: 14px;
    color: var(--subtle);
    margin-top: 6px;
    line-height: 1.5;
}

/* ─── Quick action bar (above composer) ─── */
.quick-bar {
    padding: 8px 12px 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* ─── Animations ─── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes slideFromRight { from { transform: translateX(100%); } to { transform: translateX(0); } }

/* ─── Utility ─── */
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.p-14 { padding: 14px; }
.mt-4 { margin-top: 4px; }
.w-full { width: 100%; }
.text-center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
