/* Colors generated from shared/design-tokens.json — keep in sync via shared/brand/export_tokens.py. */
:root {
    --background: #f8fafd;
    --foreground: #151d2b;
    --card: #ffffff;
    --card-foreground: #151d2b;
    --primary: #2759d6;
    --primary-foreground: #fafcff;
    --secondary: #ecf0f8;
    --secondary-foreground: #1e2d4c;
    --muted: #f1f3f8;
    --muted-foreground: #5c6472;
    --accent: #e6efff;
    --accent-foreground: #1a3b8b;
    --destructive: #db2c2b;
    --success: #02985f;
    --warning: #df911a;
    --border: rgba(21, 29, 43, 0.1);
    --input: rgba(21, 29, 43, 0.18);
    --brand: #6e56e7;
    --sim-1: #008f90;
    --sim-1-foreground: #fcfcfc;
    --sim-2: #e06d00;
    --sim-2-foreground: #241004;
    --radius: 14px;
    --radius-control: 12px;
    --radius-surface: 20px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --background: #0c0f16;
        --foreground: #f0f2f5;
        --card: #13171f;
        --card-foreground: #f0f2f5;
        --primary: #6e9bfb;
        --primary-foreground: #090f1c;
        --secondary: #1f242e;
        --secondary-foreground: #e8ebf2;
        --muted: #1a1e26;
        --muted-foreground: #989fab;
        --accent: #212d47;
        --accent-foreground: #d7e5ff;
        --destructive: #f75d59;
        --success: #4dc588;
        --warning: #f2af48;
        --border: rgba(255, 255, 255, 0.09);
        --input: rgba(255, 255, 255, 0.14);
        --brand: #9c93ff;
        --sim-1: #16bbbc;
        --sim-1-foreground: #001313;
        --sim-2: #f59740;
        --sim-2-foreground: #231103;
    }
}

/* Messages-app look. The iOS system colours live here; brand tokens above stay for accents. */
:root {
    --ios-bg: #ffffff;
    --ios-grouped: #f2f2f7;
    --ios-label: #000000;
    --ios-secondary: rgba(60, 60, 67, 0.6);
    --ios-tertiary: rgba(60, 60, 67, 0.3);
    --ios-separator: rgba(60, 60, 67, 0.18);
    --ios-fill: rgba(118, 118, 128, 0.12);
    --ios-blue: #007aff;
    --ios-red: #ff3b30;
    --bubble-in: #e9e9eb;
    --bubble-in-text: #000000;
    /* SMS bubbles are green in Messages; blue is for iMessage. */
    --bubble-out: #34c759;
    --bubble-out-text: #ffffff;
    --bar: rgba(249, 249, 249, 0.86);
}
@media (prefers-color-scheme: dark) {
    :root {
        --ios-bg: #000000;
        --ios-grouped: #000000;
        --ios-label: #ffffff;
        --ios-secondary: rgba(235, 235, 245, 0.6);
        --ios-tertiary: rgba(235, 235, 245, 0.3);
        --ios-separator: rgba(84, 84, 88, 0.6);
        --ios-fill: rgba(118, 118, 128, 0.24);
        --ios-blue: #0a84ff;
        --ios-red: #ff453a;
        --bubble-in: #262629;
        --bubble-in-text: #ffffff;
        --bubble-out: #30d158;
        --bar: rgba(22, 22, 24, 0.86);
    }
}

/*
 * Persian text (message bodies, sender names) uses Vazirmatn; the unicode-range keeps
 * every Latin letter and digit on the system font (SF on iPhone).
 */
@font-face {
    font-family: "Galardo Persian";
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    src: url(fonts/vazirmatn-arabic.woff2) format("woff2");
    unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+200C-200E, U+FB50-FDFF, U+FE70-FEFC;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { direction: ltr; }
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--ios-bg);
    color: var(--ios-label);
    font-family: "Galardo Persian", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
    font-size: 17px;
    line-height: 1.35;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
}
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
bdi.num { unicode-bidi: isolate; direction: ltr; font-variant-numeric: tabular-nums; }

.app { max-width: 640px; margin: 0 auto; min-height: 100dvh; }
.view { min-height: 100dvh; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }

/* ---- List header ---- */
.list-head {
    position: sticky; top: 0; z-index: 5;
    padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
    background: var(--ios-bg);
}
.nav-row { display: flex; align-items: center; justify-content: space-between; min-height: 32px; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ios-secondary); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ios-tertiary); flex-shrink: 0; }
.dot.ok { background: #34c759; }
.dot.warn { background: #ff9f0a; }
.dot.bad { background: var(--ios-red); }
.icon-btn { color: var(--ios-blue); width: 36px; height: 36px; display: grid; place-items: center; }
.icon-btn svg { width: 24px; height: 24px; }
.large-title { font-size: 34px; font-weight: 700; margin: 2px 0 8px; letter-spacing: 0; }
.search { display: flex; align-items: center; gap: 6px; background: var(--ios-fill); border-radius: 10px; padding: 0 8px; height: 36px; color: var(--ios-secondary); }
.search svg { width: 18px; height: 18px; }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; font-size: 17px; color: var(--ios-label); height: 100%; -webkit-appearance: none; appearance: none; }
.search input::placeholder { color: var(--ios-secondary); }

.banner:empty { display: none; }
.banner { margin: 4px 16px 8px; padding: 10px 12px; border-radius: 12px; background: var(--ios-fill); font-size: 14px; color: var(--ios-secondary); }

/* ---- Pinned one-time code ---- */
#otp-box:empty { display: none; }
.otp-card { margin: 6px 16px 10px; padding: 12px 14px; border-radius: 16px; background: color-mix(in srgb, var(--primary) 10%, var(--ios-bg)); }
.otp-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--ios-secondary); }
.otp-top b { color: var(--ios-label); font-weight: 600; }
.otp-row { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.otp-code { font-size: 30px; font-weight: 700; letter-spacing: 0.12em; direction: ltr; font-variant-numeric: tabular-nums; }
.copy-btn { background: var(--ios-blue); color: #fff; border-radius: 999px; padding: 6px 14px; font-size: 15px; font-weight: 600; }

/* ---- Conversation rows ---- */
.conv-list { list-style: none; margin: 0; padding: 0; }
.conv { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0 0 0; padding-inline-start: 6px; width: 100%; text-align: start; }
.conv .unread { width: 10px; height: 10px; border-radius: 50%; margin-top: 21px; flex-shrink: 0; }
.conv .unread.on { background: var(--ios-blue); }
.conv-main { flex: 1; min-width: 0; padding-bottom: 10px; padding-inline-end: 14px; border-bottom: 0.5px solid var(--ios-separator); }
.conv:last-child .conv-main { border-bottom: 0; }
.conv-top { display: flex; align-items: baseline; gap: 6px; }
.conv-name { font-size: 17px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: 15px; color: var(--ios-secondary); white-space: nowrap; }
.conv-chev { width: 14px; height: 14px; color: var(--ios-tertiary); stroke-width: 2.6; }
.conv-preview { font-size: 15px; color: var(--ios-secondary); margin-top: 1px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.3; }
.empty { text-align: center; color: var(--ios-secondary); padding: 64px 24px; font-size: 15px; }
.empty b { display: block; color: var(--ios-label); font-size: 20px; margin-bottom: 6px; }

.avatar {
    width: 45px; height: 45px; border-radius: 50%; flex-shrink: 0;
    display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 18px;
    background: linear-gradient(180deg, #a5abb8, #858994);
}
.avatar svg { width: 26px; height: 26px; stroke: none; fill: currentColor; }
.avatar.small { width: 40px; height: 40px; font-size: 16px; }

/* Line badge: a small rounded square with the SIM number, as on dual-SIM iPhones. */
.line { display: inline-grid; place-items: center; min-width: 17px; height: 17px; padding: 0 3px; border-radius: 4px; font-size: 11px; font-weight: 700; color: #fff; flex-shrink: 0; }
.line.l1 { background: var(--sim-1); }
.line.l2 { background: var(--sim-2); }

/* ---- Chat ---- */
.view.chat { display: flex; flex-direction: column; height: 100dvh; min-height: 0; padding-bottom: 0; }
.chat-head {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
    padding: calc(env(safe-area-inset-top) + 6px) 8px 8px;
    background: var(--bar); border-bottom: 0.5px solid var(--ios-separator);
    -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
}
.back { display: inline-flex; align-items: center; color: var(--ios-blue); justify-self: start; width: 36px; height: 36px; }
.back svg { width: 28px; height: 28px; stroke-width: 2.4; }
.chat-peer { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.chat-name { font-size: 12px; font-weight: 500; display: flex; align-items: center; gap: 4px; max-width: 60vw; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.head-spacer { justify-self: end; }

.to-row { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 0.5px solid var(--ios-separator); }
.to-row label { color: var(--ios-secondary); }
.to-row input { flex: 1; border: 0; outline: none; background: none; font-size: 17px; }

.chat-body { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 12px 12px; -webkit-overflow-scrolling: touch; }
.stamp { text-align: center; font-size: 12px; color: var(--ios-secondary); margin: 14px 0 6px; }
.stamp b { font-weight: 600; }
.msg { display: flex; margin-top: 2px; }
.msg.gap { margin-top: 8px; }
/* As in Messages: received on the left, sent on the right. */
.msg.out { justify-content: flex-end; }
.bubble {
    position: relative; max-width: 75%; padding: 7px 12px 8px; border-radius: 18px;
    font-size: 17px; line-height: 1.35; white-space: pre-wrap; overflow-wrap: anywhere;
    background: var(--bubble-in); color: var(--bubble-in-text);
}
.msg.out .bubble { background: var(--bubble-out); color: var(--bubble-out-text); }
.msg.tail.in .bubble { border-start-start-radius: 18px; border-end-start-radius: 4px; }
.msg.tail.out .bubble { border-end-end-radius: 4px; }
.bubble .text:dir(rtl) { text-align: right; }
.bubble .code { display: inline-block; margin-top: 6px; padding: 3px 10px; border-radius: 10px; background: rgba(0, 0, 0, 0.08); font-weight: 700; letter-spacing: 0.08em; direction: ltr; font-variant-numeric: tabular-nums; }
.bubble .code::after { content: " · Copy"; font-weight: 500; letter-spacing: 0; font-size: 14px; }
.bubble .code.copied::after { content: " · Copied"; }
.delivery { text-align: right; font-size: 11px; color: var(--ios-secondary); margin: 3px 4px 0; }
.delivery.failed { color: var(--ios-red); }
.msg-line { font-size: 11px; color: var(--ios-secondary); margin: 0 6px 2px; display: flex; gap: 4px; align-items: center; }

.composer { padding: 6px 10px calc(env(safe-area-inset-bottom) + 8px); background: var(--bar); border-top: 0.5px solid var(--ios-separator); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); }
.composer-row { display: flex; align-items: center; gap: 8px; }
.send-status:empty { display: none; }
.send-status { font-size: 12px; color: var(--ios-secondary); text-align: center; padding: 2px 0 6px; }
.sim-chip { display: inline-flex; align-items: center; gap: 4px; height: 34px; padding: 0 10px; border-radius: 17px; background: var(--ios-fill); font-size: 13px; font-weight: 600; white-space: nowrap; }
.chat-input { flex: 1; min-width: 0; height: 36px; border-radius: 18px; border: 1px solid var(--ios-separator); background: var(--ios-bg); padding: 0 14px; font-size: 17px; outline: none; }
.send-btn { width: 32px; height: 32px; border-radius: 50%; background: var(--bubble-out); color: #fff; display: grid; place-items: center; flex-shrink: 0; }
.send-btn:disabled { background: var(--ios-tertiary); }
.send-btn svg { width: 20px; height: 20px; stroke-width: 2.6; }

/* ---- Gateway ---- */
.group { margin: 8px 16px 16px; background: var(--ios-grouped); border-radius: 12px; overflow: hidden; }
@media (prefers-color-scheme: dark) { .group { background: #1c1c1e; } }
#view-gateway { background: var(--ios-bg); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 0.5px solid var(--ios-separator); font-size: 17px; }
.row:last-child { border-bottom: 0; }
.row .k { flex: 1; }
.row .v { color: var(--ios-secondary); }
.bars { display: inline-flex; align-items: flex-end; gap: 2px; }
.bars i { width: 4px; border-radius: 1px; background: var(--ios-tertiary); }
.bars i.on { background: var(--ios-label); }
.bars i:nth-child(1) { height: 5px; } .bars i:nth-child(2) { height: 8px; } .bars i:nth-child(3) { height: 11px; } .bars i:nth-child(4) { height: 14px; }
.section-label { margin: 18px 32px 6px; font-size: 13px; color: var(--ios-secondary); }
.home-screen-help summary { padding: 12px 16px; cursor: pointer; font-size: 17px; }
.home-screen-help p { margin: 0 16px 12px; font-size: 14px; color: var(--ios-secondary); line-height: 1.6; }

/* ---- Calls ---- */
.segmented { display: inline-flex; background: var(--ios-fill); border-radius: 9px; padding: 2px; margin-inline: auto; }
.segmented button { padding: 4px 18px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--ios-label); }
.segmented button.on { background: var(--ios-bg); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.calls .conv-name.missed { color: var(--ios-red); }
.call-kind { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; color: var(--ios-secondary); }
.call-kind svg { width: 14px; height: 14px; }
.calls-note { margin: 16px 24px; font-size: 13px; color: var(--ios-secondary); text-align: center; }

.incoming {
    position: fixed; z-index: 30; top: calc(env(safe-area-inset-top) + 8px); left: 8px; right: 8px;
    max-width: 480px; margin: 0 auto; padding: 14px; border-radius: 26px;
    background: rgba(30, 30, 32, 0.92); color: #fff;
    -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.incoming-top { display: flex; align-items: center; gap: 12px; }
.incoming-text { flex: 1; min-width: 0; }
.incoming-name { font-size: 20px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.incoming-line { font-size: 13px; color: rgba(235, 235, 245, 0.6); display: flex; align-items: center; gap: 6px; }
.incoming-actions { display: flex; justify-content: space-around; margin-top: 14px; }
.round { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: #fff; }
.round svg { width: 54px; height: 54px; padding: 14px; border-radius: 50%; stroke-width: 2; }
.round.red svg { background: #ff3b30; fill: #fff; stroke: #fff; }
.round.gray svg { background: rgba(118, 118, 128, 0.45); }

/* ---- Tab bar ---- */
.tabbar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
    display: flex; justify-content: space-around;
    padding: 6px 0 calc(env(safe-area-inset-bottom) + 4px);
    background: var(--bar); border-top: 0.5px solid var(--ios-separator);
    -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
}
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; font-weight: 500; color: var(--ios-secondary); min-width: 64px; }
.tabbar button.active { color: var(--ios-blue); }
.tabbar svg { width: 26px; height: 26px; }
.tabbar button.active svg path:first-child { fill: currentColor; }

/* Online pairing from inside the Home Screen app. */
.scan-btn { display: block; margin: 0 auto 12px; background: var(--ios-blue); color: #fff; border-radius: 999px; padding: 10px 20px; font-size: 16px; font-weight: 600; }
.scanner { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); }
.scanner video { width: 100%; max-width: 480px; aspect-ratio: 1; object-fit: cover; border-radius: 20px; background: #111; }
.scanner-hint { color: #fff; text-align: center; font-size: 15px; max-width: 420px; }
.scanner-cancel { color: #fff; font-size: 17px; font-weight: 600; padding: 10px 24px; border-radius: 999px; background: rgba(255, 255, 255, 0.18); }

/* Contacts, like the iOS Contacts app. */
.contact-numbers { list-style: none; padding: 0; }
.contact-list { list-style: none; margin: 0; padding: 0 0 96px; }
.contact-section { position: sticky; top: 0; z-index: 1; padding: 4px 16px; font-size: 15px; font-weight: 600; color: var(--ios-secondary); background: var(--ios-grouped); }
.contact-row { display: block; width: 100%; text-align: start; padding: 11px 16px; font-size: 17px; color: var(--ios-label); border-bottom: 0.5px solid var(--ios-separator); }
.contact-head { display: flex; align-items: center; }
.contact-head .back { width: auto; gap: 2px; font-size: 17px; }
.contact-hero { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 16px 16px 8px; }
.contact-hero h2 { margin: 0; font-size: 26px; font-weight: 600; text-align: center; }
.avatar.large { width: 96px; height: 96px; font-size: 40px; }
.contact-number { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; width: 100%; text-align: start; padding: 10px 16px; border-bottom: 0.5px solid var(--ios-separator); }
.contact-numbers li:last-child .contact-number { border-bottom: 0; }
.contact-number .k { font-size: 13px; color: var(--ios-secondary); }
.contact-number .v { grid-row: 2; font-size: 17px; color: var(--ios-blue); }
.contact-action { grid-row: 1 / 3; grid-column: 2; align-self: center; color: var(--ios-blue); width: 28px; height: 28px; }
.contact-action svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; }
