:root {
  --bg: #eef0f2;
  --surface: #ffffff;
  --text: #16191d;
  --muted: #5f6873;
  --line: #d9dde2;
  --accent: #d9480f;
  --accent-text: #ffffff;
  --ok: #1b7f4b;
  --ok-bg: #e1f4ea;
  --wait: #3f4954;
  --wait-bg: #e6e9ed;
  --warn: #9a5b00;
  --warn-bg: #fdf0d5;
  --late: #c0162c;
  --late-bg: #fde5e8;
  --tabbar-height: 60px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417;
    --surface: #1c2024;
    --text: #eef0f2;
    --muted: #9aa4af;
    --line: #2e343a;
    --accent: #f76b2d;
    --accent-text: #16191d;
    --ok: #57d08f;
    --ok-bg: #173526;
    --wait: #c2cad2;
    --wait-bg: #2a3036;
    --warn: #f2b84b;
    --warn-bg: #3a2c10;
    --late: #ff7b8a;
    --late-bg: #41181e;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* Вход */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%;
  max-width: 360px;
  display: grid;
  gap: 14px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }

/* Шапка */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
}
.top-actions { flex: none; display: flex; align-items: center; gap: 8px; }
.menu-wrap { position: relative; }
.menu-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: none;
  color: var(--text);
  cursor: pointer;
}
.menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: max-content;
  max-width: calc(100vw - 32px);
  display: grid;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgb(0 0 0 / .25);
}
.view {
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.view:hover { background: var(--bg); }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: grid; min-width: 0; }
.brand strong { font-size: 18px; line-height: 1.2; }
.whoami { font-size: 13px; color: var(--muted); }
.link { padding: 0; border: 0; background: none; color: inherit; text-decoration: underline; cursor: pointer; }
.add {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}

.offline {
  margin: 0;
  padding: 8px 16px;
  background: var(--late-bg);
  color: var(--late);
  font-size: 14px;
  text-align: center;
}

/* Лента */
.feed-wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 12px 16px calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 16px);
}
.feed { display: grid; gap: 10px; }
.empty { margin: 48px 0; text-align: center; color: var(--muted); }
#sentinel { height: 1px; }

.card {
  display: grid;
  gap: 8px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.card.is-late { border-color: var(--late); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-title { font-size: 18px; font-weight: 650; line-height: 1.25; }
.card-id { display: block; font-size: 13px; font-weight: 400; color: var(--muted); }
.address, .comment { margin: 0; overflow-wrap: anywhere; }
.comment { color: var(--muted); font-size: 15px; white-space: pre-wrap; }
.phone { justify-self: start; color: inherit; font-weight: 600; font-variant-numeric: tabular-nums; }

.pill {
  flex: none;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  background: var(--wait-bg);
  color: var(--wait);
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.late { background: var(--late-bg); color: var(--late); }

.times { margin: 0; padding-top: 8px; border-top: 1px solid var(--line); display: grid; gap: 2px; font-size: 14px; }
.times div { display: flex; justify-content: space-between; gap: 12px; }
.times dt { color: var(--muted); }
.times dd { margin: 0; font-variant-numeric: tabular-nums; }

.log-row {
  display: grid;
  gap: 2px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.log-title { font-size: 15px; font-weight: 600; }
.log-detail { font-size: 14px; overflow-wrap: anywhere; }
.log-meta { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Кнопки и формы */
.btn {
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-link { display: flex; align-items: center; justify-content: center; color: inherit; text-decoration: none; }
.card .btn { width: 100%; }
.card-cancel {
  justify-self: end;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 11px;
  text-decoration: underline;
  cursor: pointer;
}

.field { display: grid; gap: 5px; min-width: 0; }
.field > span { font-size: 14px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-size: 16px;
}
.field textarea { resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { margin: 0; color: var(--late); font-size: 14px; }

/* Окно создания заявки */
.sheet {
  width: calc(100% - 32px);
  max-width: 480px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
}
.sheet::backdrop { background: rgb(0 0 0 / .5); }
.sheet form { display: grid; gap: 14px; }
.sheet h2 { margin: 0; font-size: 20px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Нижняя панель */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  height: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tab {
  border: 0;
  border-top: 3px solid transparent;
  background: none;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.tab.is-current { color: var(--accent); border-top-color: var(--accent); }
.count { font-weight: 400; font-variant-numeric: tabular-nums; }
.tabbar.is-wide .tab { padding: 0 2px; font-size: 12px; }
.tabbar.is-wide .count { display: block; }
