:root {
  --bg-a: #d4f3b7;
  --bg-b: #a9c191;
  --bg: #bfdaa4;
  --surface: #f6fbef;
  --surface-2: #e7f2d9;
  --text: #2b3320;
  --muted: #6b7a5a;
  --line: #cfe3b8;
  --primary: #667558;
  --primary-ink: #ffffff;
  --danger: #b8503a;
  --warn: #c0792a;
  --ok: #505c45;
  --info: #5c7a96;
  --shadow-color: 40, 55, 25;
  --radius: 20px;
  --tabbar-h: 60px;
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-a: #232c1b;
    --bg-b: #141910;
    --bg: #1c2416;
    --surface: #2a3322;
    --surface-2: #34402a;
    --text: #eaf3dc;
    --muted: #a9c191;
    --line: #3e4a33;
    --primary: #bfdaa4;
    --primary-ink: #1d2716;
    --danger: #e2846a;
    --warn: #e0a94f;
    --ok: #93bb80;
    --info: #89abcb;
    --shadow-color: 0, 0, 0;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  background: linear-gradient(165deg, var(--bg-a) 0%, var(--bg) 45%, var(--bg-b) 100%);
  background-attachment: fixed;
  min-height: 100dvh;
}

button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 680; letter-spacing: -.01em; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ */
/* Вход                                                                */
/* ------------------------------------------------------------------ */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login__box {
  width: 100%;
  max-width: 360px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: 28px;
  padding: 32px 24px;
  display: grid;
  gap: 14px;
  box-shadow: 0 24px 60px rgba(var(--shadow-color), .18), 0 2px 8px rgba(var(--shadow-color), .08);
}

.login__logo { font-size: 46px; text-align: center; line-height: 1; }
.login__box h1 { text-align: center; font-size: 23px; }
.login__hint { margin: -8px 0 6px; text-align: center; color: var(--muted); font-size: 14px; }
.login__error { margin: 0; color: var(--danger); font-size: 14px; text-align: center; }

.login label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }

.pw-field { position: relative; }
.pw-field input { padding-right: 42px; }
.pw-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border: 0;
  background: none;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

input, select, textarea {
  width: 100%;
  padding: 12px 13px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 13px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { min-height: 74px; resize: vertical; }

/* ------------------------------------------------------------------ */
/* Каркас                                                              */
/* ------------------------------------------------------------------ */

.app { min-height: 100dvh; padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.topbar h1 { font-size: 19px; }
.topbar__actions { display: flex; gap: 6px; }

.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  font-size: 16px;
  cursor: pointer;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn.is-recording { background: var(--danger); border-color: var(--danger); color: #fff; }

.view { padding: 14px 16px 90px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 8px 2px;
  height: var(--tabbar-h);
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 10.5px;
  cursor: pointer;
}
.tabbar button span { font-size: 19px; line-height: 1.1; }
.tabbar button.is-active { color: var(--primary); font-weight: 600; }

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  z-index: 25;
  width: 56px; height: 56px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(155deg, var(--primary), color-mix(in srgb, var(--primary) 65%, #2f3a22));
  color: var(--primary-ink);
  font-size: 30px;
  line-height: 1;
  box-shadow: 0 12px 28px rgba(var(--shadow-color), .32);
  cursor: pointer;
}
.fab:active { transform: scale(.93); }

/* ------------------------------------------------------------------ */
/* Блоки                                                               */
/* ------------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 1px 2px rgba(var(--shadow-color), .04);
}

.section { display: grid; grid-template-columns: minmax(0, 1fr); gap: 9px; }
.section__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.section__head h2 { font-size: 15px; }
.section__count { color: var(--muted); font-size: 13px; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 8px;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(var(--shadow-color), .04);
}
.tile__value { font-size: 21px; font-weight: 700; line-height: 1.1; }
.tile__label { font-size: 10.5px; color: var(--muted); margin-top: 3px; }
.tile--danger .tile__value { color: var(--danger); }
.tile--warn .tile__value { color: var(--warn); }
.tile--info .tile__value { color: var(--info); }

/* Карточка работы */
.work {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 13px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(var(--shadow-color), .04);
}
.work:active { background: var(--surface-2); }
.work--overdue { border-left-color: var(--danger); }
.work--risk    { border-left-color: var(--warn); }
.work--soon    { border-left-color: var(--info); }
.work--stuck   { border-left-color: var(--muted); }
.work--ok      { border-left-color: var(--ok); }

.work__top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.work__doctor {
  font-weight: 640;
  font-size: 15px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.work__due { font-size: 12px; color: var(--muted); white-space: nowrap; flex: 0 0 auto; }
.work__due--overdue { color: var(--danger); font-weight: 600; }
.work__due--soon { color: var(--warn); font-weight: 600; }
.work__body { font-size: 13.5px; color: var(--text); }
.work__meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}
.chip--stage { background: color-mix(in srgb, var(--primary) 18%, transparent); color: color-mix(in srgb, var(--primary) 80%, var(--text)); border-color: transparent; font-weight: 600; }
.chip--rework { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); border-color: transparent; }
.chip--number { font-variant-numeric: tabular-nums; }

.filters { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.filters::-webkit-scrollbar { display: none; }
.filters button {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.filters button.is-active { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }

.empty { text-align: center; color: var(--muted); font-size: 14px; padding: 22px 10px; }

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(var(--shadow-color), .04);
}
.list-row__title { font-weight: 600; font-size: 14.5px; }
.list-row__sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* Маршрут */
.point { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.point__addr { font-size: 13px; color: var(--muted); }
.point__addr a { color: var(--info); text-decoration: none; }
.point__works { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.point__work { display: flex; gap: 8px; font-size: 13.5px; align-items: baseline; }

/* Фотографии в карточке заказа */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.photo-tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--line);
  cursor: pointer;
}
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile__pdf { width: 100%; height: 100%; display: grid; place-items: center; font-size: 28px; }
.photo-tile__badge {
  position: absolute;
  left: 4px;
  bottom: 4px;
  font-size: 13px;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .5));
}
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, .85);
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; display: block; }

.photo-tile__del {
  position: absolute;
  right: 3px;
  top: 3px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .45);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}

/* ------------------------------------------------------------------ */
/* Кнопки                                                              */
/* ------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 14.5px;
  font-weight: 550;
  cursor: pointer;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .45; cursor: default; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 650; }
.btn--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.btn--block { width: 100%; }
.btn--sm { padding: 8px 14px; font-size: 13px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ------------------------------------------------------------------ */
/* Выдвижная панель                                                    */
/* ------------------------------------------------------------------ */

.sheet { position: fixed; inset: 0; z-index: 60; }
.sheet__backdrop { position: absolute; inset: 0; background: rgba(20, 14, 6, .5); }
.sheet__panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  background: linear-gradient(180deg, var(--bg-a) 0%, var(--bg) 60%);
  border-radius: 26px 26px 0 0;
  border-top: 1px solid var(--line);
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(18px); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet__grip { width: 40px; height: 4px; border-radius: 99px; background: var(--line); margin: 9px auto 2px; }
.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.sheet__head h2 { font-size: 16px; }
.sheet__body {
  overflow-y: auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  display: grid;
  gap: 13px;
}

.field { position: relative; display: grid; gap: 6px; }
.field > span { font-size: 12.5px; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Автодополнение — замена нативному <datalist>, у которого на телефоне
   всплывающий список рисуется не рядом с полем, острыми углами и без
   гарантии порядка. Свой список — с теми же скруглениями и тенью, что
   у карточек и панелей. */
.autocomplete {
  position: absolute;
  z-index: 45;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 220px;
  overflow-y: auto;
  display: grid;
  gap: 2px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 12px 28px rgba(var(--shadow-color), .18), 0 2px 8px rgba(var(--shadow-color), .08);
}
.autocomplete__item {
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
}
.autocomplete__item:hover { background: var(--surface-2); }

.kv { display: grid; grid-template-columns: 96px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); font-size: 12.5px; align-self: center; }
.kv dd { margin: 0; font-weight: 550; }

.timeline { display: grid; gap: 8px; font-size: 12.5px; color: var(--muted); }
.timeline div { display: flex; gap: 8px; }
.timeline b { color: var(--text); font-weight: 600; }

.confirm { display: grid; gap: 10px; }
.confirm__transcript {
  font-style: italic;
  color: var(--muted);
  font-size: 13px;
  background: var(--surface-2);
  border-radius: 14px;
  padding: 10px 12px;
}
.confirm__warn { color: var(--warn); font-size: 13px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 78px);
  transform: translateX(-50%);
  z-index: 90;
  max-width: min(90vw, 420px);
  padding: 11px 18px;
  border-radius: 999px;
  background: #232c1b;
  color: #eaf3dc;
  font-size: 13.5px;
  box-shadow: 0 10px 30px rgba(var(--shadow-color), .35);
}
.toast--error { background: var(--danger); color: #fff; }

@media (min-width: 720px) {
  .view { max-width: 760px; margin: 0 auto; }
  .sheet__panel { max-width: 620px; margin: 0 auto; border-radius: 26px; bottom: 3dvh; max-height: 88dvh; }
}
