/* Щабът 2 — стилове. Мобилно първо, тъмна тема по подразбиране, светла по системата. */

:root {
  --bg: #0f1218;
  --surface: #171b23;
  --surface-2: #1f2430;
  --line: #2a3140;
  --text: #e9ecf1;
  --muted: #8d96a8;
  --accent: #f0b45a;
  --accent-ink: #1a1306;
  --ok: #3ecf8e;
  --bad: #ff5d5d;
  --warn: #f0b45a;
  --info: #6aa8ff;
  --radius: 14px;
  --radius-sm: 10px;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f3ef;
    --surface: #ffffff;
    --surface-2: #f0ede7;
    --line: #e2ddd3;
    --text: #1b1d22;
    --muted: #6b7180;
    --accent: #c9831f;
    --accent-ink: #ffffff;
    --ok: #18a065;
    --bad: #d93636;
    --warn: #c9831f;
    --info: #2f6fd6;
    color-scheme: light;
  }
}

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.35rem; font-weight: 700; }
h3 { font-size: 1.02rem; font-weight: 650; margin-bottom: .6rem; }
p { margin: 0; }
a { color: var(--accent); }

/* ---------- Горна лента ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + var(--safe-t)) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  max-width: 640px;
  margin: 0 auto;
}
.top-text { min-width: 0; }
.greeting {
  font-size: 1.25rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.date { color: var(--muted); font-size: .92rem; }
.top-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.clock {
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  line-height: 1;
}
.offline-badge {
  font-size: .72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--line);
}

/* ---------- Основна част ---------- */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabs-h) + var(--safe-b) + 96px);
}
.view { display: flex; flex-direction: column; gap: 14px; }
.view > h2 { margin-top: 2px; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}
.count { color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
}
.form-card { display: flex; flex-direction: column; gap: 10px; }
.hint { color: var(--muted); font-size: .9rem; margin-bottom: .6rem; }
.version { color: var(--muted); font-size: .82rem; text-align: center; }

/* ---------- Мисъл за деня ---------- */
.thought {
  margin: 0;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 16%, var(--surface)), var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
}
.thought figcaption {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
  margin-bottom: 4px;
}
.thought blockquote {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 550;
  overflow-wrap: anywhere;
}

/* ---------- Полета и бутони ---------- */
input[type="text"],
input[type="url"],
select,
textarea {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 16px; /* без авто-зуум на iPhone */
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 80px; }
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 52%, calc(100% - 12px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
::placeholder { color: var(--muted); opacity: .8; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; flex: 1; }
.field > span { font-size: .82rem; color: var(--muted); font-weight: 600; }
#site-form { display: flex; flex-direction: column; gap: 10px; }

.form-row { display: flex; gap: 10px; align-items: flex-end; }
.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  font: inherit;
  font-weight: 650;
  font-size: .95rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: transform .08s, background .15s, border-color .15s;
}
.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover, .icon-btn:focus-visible { background: var(--surface-2); color: var(--text); outline: none; }
.icon-btn.danger:hover, .icon-btn.danger:focus-visible { color: var(--bad); }

/* ---------- Чипове / филтри ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font: inherit;
  font-size: .86rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .n { opacity: .7; margin-left: 4px; font-variant-numeric: tabular-nums; }

/* ---------- Сегментиран избор ---------- */
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: block;
  text-align: center;
  padding: 8px;
  border-radius: 9px;
  font-weight: 650;
  font-size: .92rem;
  color: var(--muted);
}
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

/* ---------- Списъци ---------- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.empty { color: var(--muted); text-align: center; padding: 18px 8px; font-size: .95rem; }

/* Днес */
.todo {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px 4px 4px 12px;
  min-width: 0;
}
.todo label { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; padding: 8px 0; cursor: pointer; }
.todo input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 24px; height: 24px;
  flex-shrink: 0;
  margin: 0;
  border: 2px solid var(--muted);
  border-radius: 7px;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.todo input[type="checkbox"]::after {
  content: "";
  width: 6px; height: 11px;
  border: solid var(--accent-ink);
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg) translate(-1px, -1px);
  opacity: 0;
}
.todo input[type="checkbox"]:checked { background: var(--ok); border-color: var(--ok); }
.todo input[type="checkbox"]:checked::after { opacity: 1; border-color: #08130d; }
.todo input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.todo .text { overflow-wrap: anywhere; }
.todo.done .text { color: var(--muted); text-decoration: line-through; }

.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--ok); border-radius: 99px; transition: width .3s; }

/* Проекти */
.project { display: flex; flex-direction: column; gap: 8px; }
.project .row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.project .name { font-size: 1.02rem; font-weight: 650; flex: 1; min-width: 0; overflow-wrap: anywhere; margin: 0; }
.project .note { color: var(--muted); font-size: .92rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.project .link { font-size: .9rem; overflow-wrap: anywhere; }
.project .actions { display: flex; justify-content: flex-end; gap: 2px; margin: -4px -6px -6px 0; }
.project .meta { color: var(--muted); font-size: .78rem; margin-right: auto; align-self: center; }
.project { border-left: 4px solid var(--st, var(--line)); }
.project[data-status="idea"] { --st: var(--info); }
.project[data-status="active"] { --st: var(--accent); }
.project[data-status="paused"] { --st: var(--muted); }
.project[data-status="done"] { --st: var(--ok); }
.project[data-status="done"] .name { color: var(--muted); }

.status-select {
  width: auto;
  flex-shrink: 0;
  font-size: .84rem;
  font-weight: 700;
  padding: 6px 30px 6px 10px;
  border-radius: 99px;
  border-color: color-mix(in srgb, var(--st, var(--line)) 60%, var(--line));
  color: var(--st, var(--text));
  background-color: color-mix(in srgb, var(--st, var(--line)) 12%, var(--surface));
}

/* Бележки */
.note-card { display: flex; flex-direction: column; gap: 6px; }
.note-card .head { display: flex; align-items: center; gap: 8px; }
.tag {
  font-size: .74rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--muted);
}
.tag.idea { background: color-mix(in srgb, var(--accent) 18%, var(--surface)); color: var(--accent); }
.note-card .when { color: var(--muted); font-size: .78rem; margin-right: auto; }
.note-card .body { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Сайтове */
.site-list { margin-top: 12px; }
.site {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-width: 0;
}
.site .info { flex: 1; min-width: 0; }
.site .s-name { font-weight: 650; overflow-wrap: anywhere; }
.site .s-url { color: var(--muted); font-size: .82rem; overflow-wrap: anywhere; }
.site .s-state { font-size: .8rem; font-weight: 600; }

.dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--muted);
}
[data-state="up"] .dot { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 20%, transparent); }
[data-state="down"] .dot { background: var(--bad); box-shadow: 0 0 0 4px color-mix(in srgb, var(--bad) 20%, transparent); }
[data-state="checking"] .dot { background: var(--warn); animation: pulse 1s infinite; }
[data-state="up"] .s-state { color: var(--ok); }
[data-state="down"] .s-state { color: var(--bad); }
[data-state="checking"] .s-state,
[data-state="unknown"] .s-state,
[data-state="offline"] .s-state { color: var(--muted); }

@keyframes pulse { 50% { opacity: .35; } }

.site-strip { display: flex; flex-wrap: wrap; gap: 6px; }
.site-strip:empty { display: none; }
.site-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  font: inherit;
  font-size: .86rem;
  font-weight: 600;
  padding: 7px 12px 7px 10px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.site-pill .dot { width: 10px; height: 10px; }
.site-pill span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-pill.add { color: var(--muted); border-style: dashed; }

/* ---------- Долни табове ---------- */
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabs a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  text-decoration: none;
  font-size: .74rem;
  font-weight: 650;
  min-width: 0;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current="page"] { color: var(--accent); }
.tabs a:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; border-radius: 12px; }

/* ---------- Тост с „Върни“ ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabs-h) + var(--safe-b) + 12px);
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 10px 10px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: .92rem;
  font-weight: 550;
  box-shadow: 0 8px 28px rgba(0,0,0,.35);
  animation: rise .2s ease-out;
}
.toast span { overflow-wrap: anywhere; }
.toast button {
  font: inherit;
  font-weight: 750;
  color: var(--accent);
  background: transparent;
  border: 0;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}
@media (prefers-color-scheme: light) { .toast button { color: #f0b45a; } }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- Диалог ---------- */
dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 40px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgba(5, 7, 10, .6); }
dialog form { display: flex; flex-direction: column; gap: 12px; }

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

@media (min-width: 700px) {
  .tabs { left: 50%; right: auto; width: 640px; transform: translateX(-50%); border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0; }
}
