* { box-sizing: border-box; }
body {
  --bg: #0d1117; --card: #161b22; --line: #30363d; --text: #e6edf3; --dim: #8b949e;
  --accent: #2f81f7; --good: #2ea043; --bad: #da3633; --warn: #d29922;
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.light { --bg: #f6f8fa; --card: #fff; --line: #d0d7de; --text: #1f2328; --dim: #656d76; }
.hidden { display: none !important; }
button, select, input { font: inherit; color: inherit; }
button { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer; }
button:hover { filter: brightness(1.1); }
button.small { padding: 4px 10px; font-size: 13px; background: var(--line); color: var(--text); }
button.link { background: none; color: var(--accent); padding: 2px 6px; font-size: 13px; }
button.link.danger { color: var(--bad); }
select, input[type=text], input[type=search], input[type=number] {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px;
}
input[type=number] { width: 4.5em; }
.note { color: var(--dim); font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }

/* top bar */
#bar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--card); position: sticky; top: 0; z-index: 5; }
#bar h1 { font-size: 20px; margin: 0; flex: 1; }
#clock { color: var(--dim); font-variant-numeric: tabular-nums; }
#chips { display: flex; gap: 6px; }
.chip { background: var(--line); border-radius: 99px; padding: 2px 10px; font-size: 13px; }
.icon-btn { position: relative; background: none; color: var(--text); font-size: 20px; padding: 4px 8px; }
.badge { position: absolute; top: -4px; right: -6px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 99px; min-width: 18px; padding: 1px 5px; text-align: center; }
.banner { display: flex; justify-content: space-between; align-items: center; margin: 12px 20px 0; padding: 10px 14px;
  border-radius: 10px; background: var(--accent); color: #fff; }
.banner .link { color: #fff; }

/* dashboard */
#dash { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; padding: 20px; max-width: 1200px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.card.wide { grid-column: 1 / -1; }
.card h2 { font-size: 16px; margin: 0 0 10px; }
.field { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 8px; }
.stat-grid b { display: block; font-size: 26px; }
.stat-grid span { color: var(--dim); font-size: 12px; }
#cat-counts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.pill { background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; font-size: 13px; }
.pill.hot { border-color: var(--accent); }
.pick-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pick-head h2 { margin: 0; flex: 1; }
#on-count { color: var(--dim); font-size: 13px; }
#kinds { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.cat { border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.cat-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-weight: 600; }
.urgent { color: var(--bad); font-size: 11px; font-style: normal; margin-left: 6px; text-transform: uppercase; }

/* switches */
.switch { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch input + span { flex: none; width: 34px; height: 20px; border-radius: 99px; background: var(--line); position: relative; transition: background .15s; }
.switch input + span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { left: 16px; }
.switch input:focus-visible + span { outline: 2px solid var(--accent); }
.kind { font-size: 14px; }

/* toasts */
#toasts { position: fixed; z-index: 20; display: flex; flex-direction: column; gap: 10px; width: min(360px, calc(100vw - 24px)); }
#toasts.top-right { top: 70px; right: 12px; }
#toasts.top-left { top: 70px; left: 12px; }
#toasts.bottom-right { bottom: max(12px, env(safe-area-inset-bottom)); right: 12px; flex-direction: column-reverse; }
#toasts.bottom-left { bottom: max(12px, env(safe-area-inset-bottom)); left: 12px; flex-direction: column-reverse; }
.toast, .item { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 12px;
  padding: 10px 12px; box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.toast { animation: slide-in .25s ease-out; }
.toast.leaving { animation: slide-out .25s ease-in forwards; }
.p1 { border-left-color: var(--accent); }
.p2 { border-left-color: var(--warn); }
.p3 { border-left-color: var(--bad); }
.toast-head, .item-head { display: flex; gap: 8px; align-items: center; }
.toast-title { font-weight: 600; flex: 1; }
.toast-time { color: var(--dim); font-size: 12px; }
.toast-x { background: none; color: var(--dim); padding: 0 4px; }
.toast-body { margin: 4px 0 6px; overflow-wrap: anywhere; }
.count { background: var(--accent); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 6px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.act { padding: 4px 10px; font-size: 13px; }
.act-decline, .act-secure { background: var(--bad); }
.act-answer, .act-accept, .act-join { background: var(--good); }
.act-snooze { background: var(--line); color: var(--text); }
.handled { color: var(--dim); font-size: 13px; }
.reply-input { flex: 1; min-width: 0; }
.note-toast { font-size: 13px; }
@keyframes slide-in { from { opacity: 0; transform: translateY(-10px) scale(.97); } }
@keyframes slide-out { to { opacity: 0; transform: translateX(30px); } }

/* incoming call */
#call { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.55); display: grid; place-items: center; }
.call-card { background: var(--card); border-radius: 22px; padding: 28px; width: min(340px, 92vw); text-align: center; }
.call-icon { font-size: 54px; animation: shake .5s infinite; }
.call-name { font-size: 24px; font-weight: 700; margin-top: 8px; }
.call-text, .call-timer { color: var(--dim); }
.call-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }
.call-buttons button { border-radius: 99px; padding: 12px 18px; }
.call-buttons .answer { background: var(--good); }
.call-buttons .decline { background: var(--bad); }
.call-buttons .mid { background: var(--line); color: var(--text); }
@keyframes shake { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }

/* drawers */
#drawer, #settings { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100vw); z-index: 25; background: var(--card);
  border-left: 1px solid var(--line); display: flex; flex-direction: column; box-shadow: -10px 0 30px rgba(0,0,0,.3); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 18px; }
.drawer-tools { display: flex; gap: 8px; padding: 8px 16px 0; flex-wrap: wrap; }
.drawer-tools input { flex: 1; min-width: 120px; }
#list { list-style: none; margin: 0; padding: 12px 16px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 10px; }
.item { box-shadow: none; }
.item.unread { background: color-mix(in srgb, var(--accent) 10%, var(--card)); }
.item.missed .toast-body { color: var(--bad); }
.item-tools { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 6px; border-top: 1px solid var(--line); padding-top: 4px; }
#empty { padding: 0 16px; }
.settings-body { padding: 0 16px 24px; overflow-y: auto; }
.settings-body h3 { font-size: 14px; color: var(--dim); text-transform: uppercase; letter-spacing: .05em; margin: 18px 0 6px; }
#set-autoreply-text { width: 100%; }
.names { list-style: none; padding: 0; margin: 0 0 8px; }
.names li { display: flex; justify-content: space-between; padding: 2px 0; }

@media (max-width: 720px) {
  #bar { padding: 10px 12px; gap: 6px; }
  #bar h1 { font-size: 16px; }
  #chips, #clock { display: none; }
  #dash { padding: 12px; gap: 12px; }
  .stat-grid b { font-size: 20px; }
  #toasts.top-right, #toasts.top-left { top: 60px; left: 12px; right: 12px; width: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .toast, .toast.leaving, .call-icon { animation: none; }
}
