:root {
  --bg: #f5f1ec;
  --surface: #ffffff;
  --surface-2: #efe9e2;
  --text: #1f1a17;
  --muted: #7a6f66;
  --line: #e2d9cf;
  --accent: #1f1a17;
  --accent-text: #ffffff;
  --u3: #c4382f;      /* срочно */
  --u3-bg: #fbe5e2;
  --u2: #b7791f;      /* средне */
  --u2-bg: #fbefd9;
  --u1: #4a7a5c;      /* не срочно */
  --u1-bg: #e3efe6;
  --info: #3d5a80;
  --info-bg: #e3eaf3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 26, 23, .06), 0 2px 8px rgba(31, 26, 23, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161311;
    --surface: #211d1a;
    --surface-2: #2b2622;
    --text: #f1ebe4;
    --muted: #a69a8f;
    --line: #3a332e;
    --accent: #f1ebe4;
    --accent-text: #161311;
    --u3: #ff7b70; --u3-bg: #3d1f1c;
    --u2: #f0b552; --u2-bg: #3a2c15;
    --u1: #85c39b; --u1-bg: #1c3024;
    --info: #9bb8e0; --info-bg: #1d2735;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }

.wrap { max-width: 680px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }

/* ----- шапка ----- */
.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: calc(10px + env(safe-area-inset-top)) 16px 0;
}
.top-in { max-width: 680px; margin: 0 auto; }
.top-row { display: flex; align-items: center; gap: 12px; min-height: 44px; }
.brand { font-weight: 700; letter-spacing: .14em; font-size: 15px; }
.brand small { font-weight: 500; letter-spacing: 0; color: var(--muted); margin-left: 6px; font-size: 14px; }
.spacer { flex: 1; }
.icon-btn {
  border: 0; background: transparent; width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

.tabs { display: flex; gap: 4px; padding: 8px 0 10px; }
.tab {
  border: 0; background: transparent; padding: 8px 14px; border-radius: 999px; cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: 15px;
}
.tab.on { background: var(--accent); color: var(--accent-text); }
.tab .n { opacity: .7; font-weight: 500; margin-left: 4px; }

/* ----- список ----- */
.group-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 4px 8px; font-weight: 600; }
.list { display: grid; gap: 10px; }
.card {
  display: block; text-decoration: none; background: var(--surface); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); border: 1px solid var(--line);
  border-left: 5px solid var(--line);
}
.card:active { transform: scale(.995); }
.card.u3 { border-left-color: var(--u3); }
.card.u2 { border-left-color: var(--u2); }
.card.u1 { border-left-color: var(--u1); }
.card-title { font-weight: 600; font-size: 17px; margin: 6px 0 4px; word-wrap: break-word; }
.card-meta { color: var(--muted); font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.chip.u3 { background: var(--u3-bg); color: var(--u3); }
.chip.u2 { background: var(--u2-bg); color: var(--u2); }
.chip.u1 { background: var(--u1-bg); color: var(--u1); }
.chip.info { background: var(--info-bg); color: var(--info); }
.chip.late { background: var(--u3); color: #fff; }
.chip.ok { background: var(--u1-bg); color: var(--u1); }

.empty { text-align: center; color: var(--muted); padding: 56px 16px; }
.empty b { display: block; color: var(--text); font-size: 18px; margin-bottom: 4px; }

/* ----- кнопки и формы ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); padding: 12px 18px; min-height: 48px;
  border-radius: 12px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.green { background: var(--u1); border-color: var(--u1); color: #fff; }
.btn.danger { color: var(--u3); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

.fab {
  position: fixed; right: max(16px, calc(50vw - 324px)); bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 20;
  border-radius: 999px; padding: 0 22px; height: 56px; box-shadow: 0 6px 20px rgba(0,0,0,.18);
}

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > span { font-size: 14px; font-weight: 600; color: var(--muted); }
.input, textarea.input, select.input {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 12px 14px; min-height: 48px; outline: none; font-size: 16px;
}
.input:focus { border-color: var(--text); }
textarea.input { min-height: 96px; resize: vertical; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: grid; place-items: center; text-align: center; min-height: 56px; padding: 6px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--surface); font-weight: 600; cursor: pointer; font-size: 15px;
}
.seg input:checked + span.u3 { border-color: var(--u3); background: var(--u3-bg); color: var(--u3); }
.seg input:checked + span.u2 { border-color: var(--u2); background: var(--u2-bg); color: var(--u2); }
.seg input:checked + span.u1 { border-color: var(--u1); background: var(--u1-bg); color: var(--u1); }

.photo-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.thumb { position: relative; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 16px; line-height: 1;
}
.add-photo {
  width: 84px; height: 84px; border-radius: 10px; border: 2px dashed var(--line); display: grid; place-items: center;
  color: var(--muted); cursor: pointer; font-size: 13px; text-align: center; background: transparent;
}
.add-photo svg { width: 24px; height: 24px; }

/* ----- карточка задачи ----- */
.page-head { display: flex; align-items: center; gap: 4px; margin: 8px 0 12px; }
.page-head h1 { font-size: 20px; margin: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.task-title { font-size: 22px; font-weight: 700; margin: 10px 0 6px; line-height: 1.25; word-wrap: break-word; }
.task-desc { white-space: pre-wrap; word-wrap: break-word; margin: 8px 0 0; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 14px; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; cursor: zoom-in; display: block; background: var(--surface-2); }
.facts { display: grid; gap: 10px; margin: 0; }
.facts div { display: flex; justify-content: space-between; gap: 12px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; font-weight: 500; }
.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.history li { border-left: 3px solid var(--line); padding-left: 12px; }
.history .dates { font-weight: 600; }
.history .dates s { color: var(--muted); font-weight: 400; }
.history .who { color: var(--muted); font-size: 14px; }
.actions { display: grid; gap: 10px; }
.note { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.h2 { font-size: 15px; font-weight: 700; margin: 0 0 12px; }

/* ----- просмотр фото ----- */
.viewer { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.92); display: grid; place-items: center; padding: 16px; }
.viewer img { max-width: 100%; max-height: 100%; border-radius: 6px; }
.viewer button { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.15); color: #fff; font-size: 24px; cursor: pointer; }

/* ----- меню ----- */
.menu-back { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.3); }
.menu {
  position: fixed; z-index: 41; right: 12px; top: calc(56px + env(safe-area-inset-top)); min-width: 240px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.menu .who { padding: 10px 12px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu .who small { display: block; color: var(--muted); }
.menu a, .menu button { display: block; width: 100%; text-align: left; padding: 12px; border: 0; background: none; border-radius: 10px; text-decoration: none; cursor: pointer; }
.menu a:active, .menu button:active { background: var(--surface-2); }

/* ----- вход ----- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-box { width: 100%; max-width: 360px; }
.login-box .brand { font-size: 22px; text-align: center; margin-bottom: 4px; }
.login-box p { text-align: center; color: var(--muted); margin: 0 0 28px; }

/* ----- пользователи ----- */
.user-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.user-row:last-child { border-bottom: 0; }
.user-row .grow { flex: 1; min-width: 0; }
.user-row .name { font-weight: 600; }
.user-row .sub { color: var(--muted); font-size: 14px; }
.user-row.off .name { color: var(--muted); text-decoration: line-through; }

.err { color: var(--u3); font-size: 14px; margin: -6px 0 12px; min-height: 0; }
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--accent); color: var(--accent-text); padding: 12px 18px; border-radius: 12px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.loading { text-align: center; color: var(--muted); padding: 40px; }
