/* =========================================================
   SMS Gateway — "Signal Feed" design system
   Ink navy base, dual-accent signal colors (indigo = incoming,
   coral = outgoing), Space Grotesk + Plus Jakarta Sans + JetBrains Mono.
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Plus+Jakarta+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
    /* Core palette */
    --ink: #0b0c17;
    --surface: #14162a;
    --surface-2: #1d2038;
    --surface-3: #262a4a;
    --text: #f1eefb;
    --muted: #8d90b3;
    --border: rgba(255, 255, 255, 0.08);

    /* Signal colors — meaningful, not decorative */
    --incoming: #6c5ce7;
    --incoming-soft: rgba(108, 92, 231, 0.16);
    --outgoing: #ff5c93;
    --outgoing-soft: rgba(255, 92, 147, 0.16);

    /* Status colors */
    --mint: #37e8b7;
    --amber: #ffc15e;
    --red: #ff5c5c;

    /* Type */
    --font-display: 'Space Grotesk', system-ui, sans-serif;
    --font-body: 'Plus Jakarta Sans', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, monospace;

    --radius: 16px;
    --radius-sm: 10px;
    --shadow-lift: 0 12px 32px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(1200px 600px at 100% -10%, rgba(108, 92, 231, 0.18), transparent 60%),
        radial-gradient(900px 500px at -10% 110%, rgba(255, 92, 147, 0.12), transparent 60%),
        var(--ink);
    color: var(--text);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

::selection { background: var(--incoming); color: white; }

:focus-visible {
    outline: 2px solid var(--incoming);
    outline-offset: 2px;
    border-radius: 6px;
}

/* ---------- entrance choreography ---------- */
@keyframes riseIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.topbar, .panel, .composer {
    animation: riseIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.topbar { animation-delay: 0s; }
.devices-panel { animation-delay: 0.06s; }
.feed-panel { animation-delay: 0.12s; }
.composer { animation-delay: 0.18s; }

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ---------- top bar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: rgba(11, 12, 23, 0.72);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
    width: 26px; height: 26px;
    border-radius: 50%;
    background: conic-gradient(from 180deg, var(--incoming), var(--outgoing), var(--incoming));
    position: relative;
    flex-shrink: 0;
}
.brand-mark::after {
    content: '';
    position: absolute; inset: 6px;
    border-radius: 50%;
    background: var(--ink);
}
.brand-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.01em;
}
.topbar-right { display: flex; align-items: center; gap: 14px; }
.session-user {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--muted);
}
.btn-ghost {
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    padding: 7px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    transition: all 0.18s ease;
}
.btn-ghost:hover { color: var(--text); border-color: rgba(255,255,255,0.2); background: var(--surface-2); }

/* ---------- shell / panels ---------- */
.shell {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px 16px 140px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}
.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.panel-head h2 {
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--muted);
    margin: 0;
}

/* ---------- devices ---------- */
.device-rail {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
}
.device-rail::-webkit-scrollbar { display: none; }

.device-chip {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.18s ease;
    user-select: none;
}
.device-chip:hover { border-color: rgba(255,255,255,0.18); transform: translateY(-1px); }
.device-chip.active { border-color: var(--incoming); background: var(--incoming-soft); }

.pulse-dot {
    position: relative;
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.pulse-online { background: var(--mint); }
.pulse-online::after {
    content: '';
    position: absolute; inset: -6px;
    border-radius: 50%;
    border: 1.5px solid var(--mint);
    animation: ping 2s cubic-bezier(0, 0, 0.2, 1) infinite;
}
.pulse-offline { background: var(--muted); opacity: 0.5; }

@keyframes ping {
    0% { transform: scale(0.6); opacity: 0.8; }
    100% { transform: scale(1.8); opacity: 0; }
}

.device-meta { display: flex; flex-direction: column; line-height: 1.3; }
.device-name { font-size: 13px; font-weight: 600; }
.device-seen { font-size: 11px; color: var(--muted); font-family: var(--font-mono); }

.btn-icon {
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 700;
    color: var(--ink);
    background: var(--text);
    border: none;
    padding: 7px 12px;
    border-radius: 999px;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
}
.btn-icon:hover { transform: translateY(-1px); opacity: 0.9; }

.empty-hint { color: var(--muted); font-size: 13px; margin: 4px 0; }

/* ---------- feed ---------- */
.feed-panel { display: flex; flex-direction: column; min-height: 320px; }
.live-indicator {
    display: flex; align-items: center; gap: 6px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--mint);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.ping-wrap { position: relative; width: 8px; height: 8px; }
.live-indicator .ping {
    position: relative;
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--mint);
}
.live-indicator .ping::after {
    content: '';
    position: absolute; inset: -5px;
    border-radius: 50%;
    border: 1.5px solid var(--mint);
    animation: ping 1.6s cubic-bezier(0, 0, 0.2, 1) infinite;
}

.feed {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    max-height: 55vh;
    padding-right: 2px;
}

.empty-feed {
    margin: auto;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    max-width: 240px;
    line-height: 1.5;
}

@keyframes feedIn {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.feed-item {
    display: flex;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border-left: 3px solid var(--incoming);
    animation: feedIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.feed-item.outgoing { border-left-color: var(--outgoing); }

.feed-arrow {
    flex-shrink: 0;
    width: 20px; height: 20px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px;
    background: var(--incoming-soft);
    color: var(--incoming);
    margin-top: 1px;
}
.feed-item.outgoing .feed-arrow { background: var(--outgoing-soft); color: var(--outgoing); }

.feed-content { flex: 1; min-width: 0; }
.feed-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 3px;
    flex-wrap: wrap;
}
.feed-number {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
}
.feed-time {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--muted);
}
.feed-body {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
    word-break: break-word;
    white-space: pre-wrap;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 8px;
    border-radius: 999px;
    margin-top: 6px;
}
.status-pill::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.status-received, .status-delivered { color: var(--mint); background: rgba(55, 232, 183, 0.12); }
.status-sent { color: var(--incoming); background: var(--incoming-soft); }
.status-pending, .status-sending { color: var(--amber); background: rgba(255, 193, 94, 0.12); }
.status-failed { color: var(--red); background: rgba(255, 92, 92, 0.12); }

/* ---------- composer (sticky bottom, chat-style) ---------- */
.composer {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 20;
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: rgba(11, 12, 23, 0.82);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    max-width: 720px;
    margin: 0 auto;
}
.composer-select, .composer-input {
    font-family: var(--font-body);
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 999px;
    padding: 10px 14px;
    font-size: 13px;
    transition: border-color 0.15s ease;
}
.composer-select:focus, .composer-input:focus { border-color: var(--incoming); }
.composer-select { flex: 0 0 auto; max-width: 92px; }
.composer-input.composer-number { flex: 0 0 118px; font-family: var(--font-mono); }
.composer-body { flex: 1; min-width: 0; }

.btn-send {
    flex-shrink: 0;
    width: 40px; height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--outgoing), var(--incoming));
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: 0 4px 14px rgba(255, 92, 147, 0.3);
}
.btn-send:hover { transform: translateY(-1px) scale(1.04); }
.btn-send:active { transform: scale(0.96); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ---------- dialog / sheet ---------- */
dialog.sheet {
    border: none;
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    padding: 20px;
    width: min(360px, calc(100vw - 32px));
    box-shadow: var(--shadow-lift);
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(2px); }
dialog.sheet h3 {
    font-family: var(--font-display);
    font-size: 16px;
    margin: 0 0 14px;
}
.sheet-form { display: flex; flex-direction: column; gap: 10px; }
.sheet-input {
    font-family: var(--font-body);
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 14px;
}
.sheet-input:focus { border-color: var(--incoming); }
.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.btn-primary {
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 13px;
    color: white;
    background: var(--incoming);
    border: none;
    padding: 9px 16px;
    border-radius: 999px;
    cursor: pointer;
    transition: opacity 0.15s ease;
}
.btn-primary:hover { opacity: 0.88; }
.btn-secondary {
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 13px;
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--border);
    padding: 9px 16px;
    border-radius: 999px;
    cursor: pointer;
}

.key-reveal {
    margin-top: 14px;
    padding: 12px;
    background: rgba(255, 193, 94, 0.1);
    border: 1px solid rgba(255, 193, 94, 0.35);
    border-radius: var(--radius-sm);
    font-size: 12px;
    line-height: 1.6;
}
.key-reveal .key-value {
    display: block;
    font-family: var(--font-mono);
    font-size: 12px;
    word-break: break-all;
    margin: 6px 0;
    color: var(--amber);
}
.key-reveal .key-copy {
    font-size: 11px;
    font-weight: 700;
    color: var(--ink);
    background: var(--amber);
    border: none;
    padding: 5px 10px;
    border-radius: 999px;
    cursor: pointer;
}
.hidden { display: none; }

/* ---------- toasts ---------- */
.toast-stack {
    position: fixed;
    top: 70px; left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    pointer-events: none;
}
@keyframes toastIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
.toast {
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    padding: 10px 16px;
    border-radius: 999px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lift);
    animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.toast.error { border-color: rgba(255, 92, 92, 0.4); color: #ffb3b3; }
.toast.success { border-color: rgba(55, 232, 183, 0.4); color: var(--mint); }

/* ---------- login page ---------- */
body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    position: relative;
    overflow: hidden;
}
.login-bg-ring {
    position: absolute;
    border-radius: 50%;
    border: 1px solid rgba(108, 92, 231, 0.25);
    animation: ringPulse 4s ease-out infinite;
}
@keyframes ringPulse {
    0% { transform: scale(0.8); opacity: 0.6; }
    100% { transform: scale(2.2); opacity: 0; }
}
.login-box {
    position: relative;
    z-index: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 32px 28px;
    border-radius: var(--radius);
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: var(--shadow-lift);
    animation: riseIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.login-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}
.login-box h1 {
    font-family: var(--font-display);
    font-size: 18px;
    margin: 0;
    font-weight: 700;
}
.login-box label {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    gap: 5px;
}
.login-box input {
    font-family: var(--font-body);
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
}
.login-box input:focus { border-color: var(--incoming); }
.login-box button {
    margin-top: 4px;
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 14px;
    color: white;
    background: linear-gradient(135deg, var(--outgoing), var(--incoming));
    border: none;
    padding: 11px;
    border-radius: 999px;
    cursor: pointer;
    transition: transform 0.15s ease;
}
.login-box button:hover { transform: translateY(-1px); }
.login-box .error {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #ffb3b3;
    background: rgba(255, 92, 92, 0.1);
    border: 1px solid rgba(255, 92, 92, 0.3);
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
}

@media (min-width: 640px) {
    .shell { padding-top: 24px; }
    .composer-input.composer-number { flex: 0 0 150px; }
}
