:root {
    --bg: #0b0d10;
    --surface: #11151a;
    --surface-raised: #171c22;
    --border: #242b33;
    --border-strong: #343e49;
    --text: #f2f4f7;
    --muted: #8f9aa7;
    --accent: #d8e4f0;
    --positive: #66c68c;
    --warning: #d8b56a;
    --danger: #dc7373;
    --radius: 14px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    min-width: 320px;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

input, select, textarea {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #0e1216;
    color: var(--text);
    padding: 0 12px;
    outline: none;
}

textarea {
    min-height: 54px;
    padding-top: 11px;
    padding-bottom: 11px;
    resize: vertical;
    line-height: 1.4;
}

input:focus, select:focus, textarea:focus, button:focus-visible {
    border-color: var(--border-strong);
    box-shadow: 0 0 0 3px rgba(216, 228, 240, .1);
    outline: none;
}

label { color: var(--muted); font-size: 12px; }
label input, label select { margin-top: 7px; }

.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;
}

.auth-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(100%, 360px);
    padding: 30px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
}

.wordmark, .brand-mark {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--text);
    color: var(--bg);
    font-weight: 800;
    letter-spacing: -.04em;
}

.auth-card h1 { margin: 24px 0 8px; font-size: 24px; }
.auth-card p { margin: 0 0 22px; color: var(--muted); line-height: 1.5; }
.auth-card label { display: block; margin-bottom: 14px; }
.auth-card .form-error { min-height: 20px; margin: 0 0 8px; color: var(--danger); font-size: 12px; }

.topbar {
    height: 68px;
    padding: 0 max(20px, calc((100vw - 1320px) / 2));
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(11, 13, 16, .92);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand, .topbar-actions, .connection-state, .section-heading, .panel-header,
.header-meta, .metric-row, .call-summary, .button-row {
    display: flex;
    align-items: center;
}

.brand { gap: 12px; }
.brand > div { display: grid; gap: 3px; }
.brand strong { font-size: 15px; }
.brand span:last-child { color: var(--muted); font-size: 11px; }
.topbar-actions { gap: 14px; }
.connection-state { gap: 7px; color: var(--muted); font-size: 12px; }

.status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4b5560;
}

.connected .status-dot, .status-dot.connected { background: var(--positive); }
.busy .status-dot { background: var(--warning); }
.version { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }

.app-content { min-height: calc(100vh - 68px); }

.view-tabs {
    width: min(1320px, 100%);
    margin: 0 auto;
    padding: 14px 20px 0;
    display: flex;
    gap: 5px;
}

.view-tab {
    position: relative;
    min-height: 36px;
    padding: 0 14px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--muted);
    font-weight: 600;
}

.view-tab:hover { color: var(--text); }
.view-tab.active { background: var(--surface-raised); color: var(--text); }
.tab-badge {
    min-width: 18px;
    height: 18px;
    margin-left: 6px;
    padding: 0 5px;
    display: inline-grid;
    place-items: center;
    border-radius: 9px;
    background: var(--accent);
    color: var(--bg);
    font-size: 10px;
}

.workspace {
    width: min(1320px, 100%);
    margin: 0 auto;
    padding: 14px 20px 32px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 18px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.conversation {
    min-height: calc(100vh - 124px);
    display: grid;
    grid-template-rows: auto minmax(300px, 1fr) auto auto;
}

.panel-header { justify-content: space-between; padding: 22px 24px; border-bottom: 1px solid var(--border); }
.panel-header h1 { margin: 4px 0 0; font-size: 19px; letter-spacing: -.02em; }
.eyebrow { margin: 0; color: var(--muted); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; }
.header-meta { gap: 14px; color: var(--muted); font-size: 12px; }

.messages { overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 12px; }
.empty-state { margin: auto; display: grid; gap: 7px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--text); font-weight: 600; }

.message {
    max-width: 82%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #0e1216;
}

.message.tx { align-self: flex-end; background: var(--surface-raised); }
.message-head { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 7px; color: var(--muted); font-size: 10px; }
.message-head strong { color: var(--accent); font-weight: 600; }
.message p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }

.composer { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 16px 24px 8px; border-top: 1px solid var(--border); }
.composer-status { margin: 0; min-height: 28px; padding: 0 24px 12px; color: var(--muted); font-size: 11px; }

.sidebar { display: flex; flex-direction: column; gap: 12px; }
.call-card { padding: 20px; }
.call-summary { justify-content: space-between; margin-bottom: 20px; }
.call-summary strong { display: block; margin-top: 5px; font-size: 18px; }
.call-contact { display: block; max-width: 220px; margin-top: 4px; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.call-contact[hidden] { display: none; }
.call-summary time { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 19px; }
.call-card > label { display: block; margin-bottom: 12px; }
.button-row { gap: 8px; flex-wrap: wrap; }

.button {
    min-height: 40px;
    padding: 0 14px;
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    background: var(--surface-raised);
    color: var(--text);
    font-weight: 600;
}

.button:hover { border-color: #52606e; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #11151a; }
.button.danger { color: #f0a2a2; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button.full { width: 100%; }
.text-button, .icon-button { border: 0; background: transparent; color: var(--muted); padding: 4px; }
.text-button:hover, .icon-button:hover { color: var(--text); }
.icon-button { font-size: 18px; }

.compact { padding: 18px 20px; }
.section-heading { justify-content: space-between; margin-bottom: 16px; }
.section-heading strong { display: block; margin-top: 5px; }
.sim-account .section-heading strong { max-width: 235px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sim-resource-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.sim-resource-grid > div {
    min-width: 0;
    padding: 10px;
    display: grid;
    gap: 5px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #0e1216;
}
.sim-resource-grid span { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .07em; }
.sim-resource-grid strong { overflow: hidden; font-size: 11px; line-height: 1.35; text-overflow: ellipsis; }
.sim-account-status { margin: 10px 0 0; overflow: hidden; color: var(--muted); font-size: 10px; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
.sim-account-status.error { color: var(--warning); }
.meter { height: 5px; overflow: hidden; border-radius: 10px; background: #080a0d; }
.meter span { display: block; width: 0; height: 100%; background: var(--positive); transition: width 100ms linear; }
.metric-row { justify-content: space-between; margin-top: 10px; color: var(--muted); font-size: 10px; }
#tx-state { display: inline-flex; align-items: center; gap: 6px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.quick-phrases { display: grid; gap: 6px; }
.quick-phrases button {
    min-height: 34px;
    padding: 0;
    border: 0;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    text-align: left;
}
.quick-phrases button:hover { color: var(--text); }


.sms-workspace {
    width: min(1280px, calc(100% - 40px));
    height: calc(100dvh - 142px);
    min-height: 0;
    margin: 14px auto 32px;
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    overflow: hidden;
}

.sms-threads {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    border-right: 1px solid var(--border);
    background: #0e1216;
}

.sms-section-header, .sms-chat-header {
    min-height: 82px;
    padding: 18px 20px;
    display: flex;
    align-items: center;
}

.sms-section-header { justify-content: space-between; }
.sms-section-header h1, .sms-chat-header h2 {
    margin: 4px 0 0;
    overflow: hidden;
    color: var(--text);
    font-size: 18px;
    letter-spacing: -.02em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.new-sms-button {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-raised);
    color: var(--text);
}

.sms-sync-row {
    min-height: 38px;
    padding: 0 20px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: 10px;
}

.sms-sync-row .text-button { font-size: 10px; }
.sms-sync-row .text-button:disabled { opacity: .45; cursor: default; }
.thread-list { min-height: 0; overflow-y: auto; padding: 8px; }

.sms-list-empty {
    min-height: 190px;
    padding: 24px;
    display: grid;
    place-content: center;
    gap: 7px;
    color: var(--muted);
    text-align: center;
    font-size: 12px;
}

.sms-list-empty strong { color: var(--text); font-size: 13px; }
.sms-thread {
    width: 100%;
    min-height: 70px;
    padding: 10px 11px;
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 11px;
    align-items: center;
    border: 1px solid transparent;
    border-radius: 11px;
    background: transparent;
    color: var(--text);
    text-align: left;
}

.sms-thread:hover { background: var(--surface); }
.sms-thread.active { border-color: var(--border); background: var(--surface-raised); }
.sms-avatar {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--border-strong);
    border-radius: 13px;
    background: linear-gradient(145deg, #232b34, #151a20);
    color: var(--accent);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .04em;
}

.sms-thread-content { min-width: 0; display: grid; gap: 5px; }
.sms-thread-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sms-thread-heading strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.sms-thread-heading time { flex: none; color: var(--muted); font-size: 9px; }
.sms-thread-preview { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }

.sms-chat {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    overflow: hidden;
    background:
        radial-gradient(circle at 80% 0%, rgba(216, 228, 240, .035), transparent 28%),
        var(--surface);
}

.sms-chat-header { gap: 13px; border-bottom: 1px solid var(--border); }
.sms-chat-header > div:last-child { min-width: 0; }
.sms-messages {
    min-height: 0;
    overflow-y: auto;
    padding: 24px clamp(18px, 5vw, 70px);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sms-chat-empty {
    max-width: 330px;
    margin: auto;
    display: grid;
    gap: 8px;
    color: var(--muted);
    text-align: center;
    line-height: 1.5;
}

.sms-chat-empty strong { color: var(--text); font-size: 15px; }
.empty-glyph {
    width: 46px;
    height: 46px;
    margin: 0 auto 8px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border-strong);
    border-radius: 15px;
    background: var(--surface-raised);
    color: var(--accent);
    font-size: 18px;
}

.sms-day {
    align-self: center;
    margin: 10px 0 6px;
    padding: 4px 9px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(11, 13, 16, .72);
    color: var(--muted);
    font-size: 9px;
}

.sms-bubble {
    max-width: min(72%, 620px);
    padding: 10px 12px 8px;
    align-self: flex-start;
    border: 1px solid var(--border);
    border-radius: 14px 14px 14px 4px;
    background: #0d1115;
}

.sms-bubble.outgoing {
    align-self: flex-end;
    border-color: #39434e;
    border-radius: 14px 14px 4px;
    background: #202831;
}

.sms-bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
.sms-bubble footer {
    margin-top: 6px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    color: var(--muted);
    font-size: 9px;
}

.sms-delivery.failed { color: var(--danger); }
.sms-delivery.sending { color: var(--warning); }
.sms-composer { padding: 14px 18px 16px; border-top: 1px solid var(--border); background: rgba(14, 18, 22, .94); }
.sms-recipient-field { display: grid; grid-template-columns: 80px 1fr; align-items: center; gap: 10px; margin-bottom: 10px; }
.sms-recipient-field input { min-height: 36px; background: var(--surface); }
.sms-compose-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: end; }
.sms-compose-row textarea { max-height: 150px; background: var(--surface); }
.sms-send-button { min-height: 54px; }
.sms-composer-meta { margin-top: 7px; display: flex; justify-content: space-between; gap: 14px; color: var(--muted); font-size: 9px; }

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translate(-50%, 16px);
    max-width: min(520px, calc(100vw - 32px));
    padding: 10px 14px;
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    background: var(--surface-raised);
    color: var(--text);
    opacity: 0;
    pointer-events: none;
    transition: .2s ease;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: var(--danger); }

@media (max-width: 900px) {
    .workspace { grid-template-columns: 1fr; }
    .conversation { min-height: 68vh; }
    .sidebar { display: grid; grid-template-columns: 1fr 1fr; }
    .call-card { grid-column: 1 / -1; }
    .sms-workspace { grid-template-columns: 290px minmax(0, 1fr); }
}

@media (max-width: 620px) {
    .topbar { height: auto; min-height: 64px; padding: 12px 16px; }
    .connection-state { font-size: 0; }
    .topbar-actions { gap: 10px; }
    .view-tabs { padding-left: 12px; padding-right: 12px; }
    .workspace { padding: 14px 12px 24px; }
    .sidebar { display: flex; }
    .panel-header, .messages { padding-left: 16px; padding-right: 16px; }
    .composer { padding-left: 16px; padding-right: 16px; }
    .message { max-width: 95%; }
    .button-row .button { flex: 1; }
    .field-grid { grid-template-columns: 1fr; }
    .sms-workspace {
        width: calc(100% - 24px);
        height: auto;
        min-height: 0;
        grid-template-columns: 1fr;
        grid-template-rows: 250px minmax(570px, calc(100vh - 120px));
    }
    .sms-threads { border-right: 0; border-bottom: 1px solid var(--border); }
    .sms-section-header { min-height: 70px; padding: 14px 16px; }
    .sms-sync-row { padding-left: 16px; padding-right: 16px; }
    .sms-chat-header { min-height: 70px; padding: 14px 16px; }
    .sms-messages { padding: 18px 14px; }
    .sms-bubble { max-width: 88%; }
    .sms-composer { padding: 12px; }
    .sms-recipient-field { grid-template-columns: 68px 1fr; }
    .sms-compose-row { grid-template-columns: 1fr; }
    .sms-send-button { min-height: 42px; }
    .sms-composer-meta { align-items: flex-start; }
    #sms-compose-hint { max-width: 240px; }
}

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