:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1a1d21;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2481cc;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --chip: #e9edf2;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --radius: 14px;
}
[data-theme="dark"] {
  --bg: #14181d;
  --card: #1e242b;
  --text: #e8eaed;
  --muted: #9aa4af;
  --border: #2c343d;
  --accent: #3d9ae0;
  --accent-text: #ffffff;
  --chip: #28303a;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }

#app { max-width: 760px; margin: 0 auto; padding: 0 12px calc(76px + env(safe-area-inset-bottom)); }

.center-screen { display:flex; flex-direction:column; gap:16px; align-items:center; justify-content:center; min-height:80vh; text-align:center; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 2px 10px;
  background: var(--bg);
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  border: none; background: var(--card); color: var(--text);
  width: 38px; height: 38px; border-radius: 50%;
  font-size: 17px; cursor: pointer; box-shadow: var(--shadow);
  display: inline-flex; align-items: center; justify-content: center;
  flex: none;
}
.icon-btn:active { transform: scale(.94); }

/* Tabs (bottom nav) */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabs button {
  border: none; background: none; color: var(--muted);
  font-size: 11px; cursor: pointer; padding: 4px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border-radius: 10px; min-width: 62px;
}
.tabs button .ti { font-size: 20px; }
.tabs button.active { color: var(--accent); }

/* Cards / list */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.order-card { cursor: pointer; transition: transform .06s; }
.order-card:active { transform: scale(.99); }
.order-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.order-id { font-weight: 700; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.order-amount { margin-left: auto; font-weight: 700; }
.order-sub { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 12px; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 99px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--chip); color: var(--text);
}
.badge.st-new         { background: #e0e7ff; color: #3730a3; }
.badge.st-paid        { background: #dcfce7; color: #166534; }
.badge.st-wait_prod   { background: #fef3c7; color: #92400e; }
.badge.st-in_prod     { background: #ffedd5; color: #9a3412; }
.badge.st-produced    { background: #d1fae5; color: #065f46; }
.badge.st-wait_ship   { background: #e0f2fe; color: #075985; }
.badge.st-shipped     { background: #cffafe; color: #155e75; }
.badge.st-wait_client { background: #fae8ff; color: #86198f; }
.badge.st-done        { background: #f3f4f6; color: #374151; }
[data-theme="dark"] .badge.st-new         { background: #31316b; color: #c7d2fe; }
[data-theme="dark"] .badge.st-paid        { background: #14432a; color: #bbf7d0; }
[data-theme="dark"] .badge.st-wait_prod   { background: #4d3a10; color: #fde68a; }
[data-theme="dark"] .badge.st-in_prod     { background: #4d2c12; color: #fed7aa; }
[data-theme="dark"] .badge.st-produced    { background: #0e3d2e; color: #a7f3d0; }
[data-theme="dark"] .badge.st-wait_ship   { background: #0e3a52; color: #bae6fd; }
[data-theme="dark"] .badge.st-shipped     { background: #10424c; color: #a5f3fc; }
[data-theme="dark"] .badge.st-wait_client { background: #4a1652; color: #f5d0fe; }
[data-theme="dark"] .badge.st-done        { background: #30363d; color: #d1d5db; }

/* Filters */
.filters { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  border: none; background: var(--chip); color: var(--text);
  padding: 6px 13px; border-radius: 99px; font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap; flex: none;
}
.chip.active { background: var(--accent); color: var(--accent-text); }

.searchbar { position: relative; margin-bottom: 10px; }
/* input[type="text"] ниже по файлу имеет ту же специфичность —
   уточняем селектор, чтобы отступ под иконку лупы не перебивался */
.searchbar input[type="text"] {
  width: 100%; padding: 11px 14px 11px 38px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--text); font-size: 15px; outline: none;
}
.searchbar input[type="text"]:focus { border-color: var(--accent); }
.searchbar .si { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); }

/* Forms */
label.fld { display: block; margin-bottom: 12px; }
label.fld span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type="text"], input[type="tel"], input[type="number"], input[type="date"], textarea, select {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); font-size: 15px; outline: none;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 84px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 12px; padding: 11px 18px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  background: var(--chip); color: var(--text);
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

/* Detail */
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 8px; }
.photos .ph { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--chip); }
.photos .ph img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: pointer; }
.photos .ph .del {
  position: absolute; top: 4px; right: 4px;
  background: rgba(0,0,0,.55); color: #fff; border: none; border-radius: 50%;
  width: 24px; height: 24px; cursor: pointer; font-size: 12px;
}

/* Timeline */
.timeline { margin: 0; padding: 0; list-style: none; }
.timeline li { position: relative; padding: 0 0 14px 22px; }
.timeline li::before {
  content: ""; position: absolute; left: 5px; top: 6px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
}
.timeline li::after {
  content: ""; position: absolute; left: 8px; top: 16px; bottom: 0;
  width: 2px; background: var(--border);
}
.timeline li:last-child::after { display: none; }
.timeline .t-when { font-size: 12px; color: var(--muted); }
.timeline .t-comment {
  margin-top: 4px; padding: 6px 10px; border-radius: 8px;
  background: var(--chip); font-size: 13px; white-space: pre-wrap;
}

/* Modal */
.modal-back {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--card); border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  width: 100%; max-width: 760px; max-height: 88vh; overflow-y: auto;
}
@media (min-width: 640px) {
  .modal-back { align-items: center; }
  .modal { border-radius: 18px; max-width: 480px; }
}
.modal h3 { margin: 0 0 14px; }

.viewer {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
.viewer img { max-width: 96vw; max-height: 92vh; object-fit: contain; }

/* Misc */
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
h2.section { font-size: 15px; margin: 18px 2px 8px; }
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.report-big { font-size: 26px; font-weight: 800; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 8px; }
table.tbl td { padding: 8px; border-top: 1px solid var(--border); }
table.tbl td:last-child, table.tbl th:last-child { text-align: right; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 99px; font-size: 14px;
  z-index: 100; box-shadow: var(--shadow); white-space: nowrap;
  animation: fadein .2s;
}
@keyframes fadein { from { opacity: 0; transform: translate(-50%, 8px); } }

.user-row { display: flex; align-items: center; gap: 10px; }
.user-row .un { flex: 1; min-width: 0; }
.user-row .un .muted { font-size: 12px; }
.user-row select { width: auto; }

.login-note { max-width: 320px; }

/* dev-login (только при DEV_LOGIN=1) */
.dev-login { display: flex; flex-direction: column; gap: 8px; margin-top: 24px; width: 260px; }

/* кнопка копирования рядом с телефоном */
.copy-inline { background: none; border: none; cursor: pointer; font-size: 15px; padding: 0 4px; vertical-align: middle; }
.copy-inline:active { transform: scale(.9); }

/* фильтр по дате в списке заказов */
.date-filter { display: flex; align-items: flex-end; gap: 8px; margin-bottom: 10px; }
.date-filter label { flex: 1; }
.date-filter label span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.date-filter .btn { flex: none; }

/* новые статусы */
.badge.st-returned { background: #fee2e2; color: #991b1b; }
.badge.st-canceled { background: #e5e7eb; color: #6b7280; }
[data-theme="dark"] .badge.st-returned { background: #4c1515; color: #fecaca; }
[data-theme="dark"] .badge.st-canceled { background: #2b2f36; color: #9ca3af; }

.user-row .user-del { font-size: 16px; }

/* --- фиксы фильтра дат --- */
/* нативный date-input имеет внутреннюю min-width и распирает колонки на мобильных */
input[type="date"] { min-width: 0; width: 100%; }
.date-filter label { min-width: 0; }
.date-filter.hidden { display: none; }
.report-grid > * { min-width: 0; }

/* кнопка-тумблер фильтра дат в строке поиска */
.searchbar input[type="text"] { padding-right: 42px; }
.searchbar .si-right {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 17px;
  padding: 5px 7px; border-radius: 9px; line-height: 1;
}
.searchbar .si-right.on { background: var(--accent); }
