/* ПСО УРУС-МАРТАН — интерфейс. Мобильный в первую очередь, крупные цели касания, высокий контраст. */
:root {
  --green-900: #0B3326;
  --green-800: #0F4433;
  --green-700: #17583F;
  --green-100: #E3EDE7;
  --orange-600: #D9620E;
  --orange-500: #F28024;
  --orange-100: #FDEBDC;
  --cream: #FBF6EC;
  --paper: #FFFDF8;
  --ink: #1B2420;
  --muted: #56625C;
  --line: #DDD6C8;
  --red-700: #A4161A;
  --red-100: #FBE3E1;
  --amber-100: #FFF2CC;
  --amber-800: #7A5300;
  --radius: 14px;
  --tap: 52px;
  --shadow: 0 1px 2px rgba(11, 51, 38, .08), 0 4px 14px rgba(11, 51, 38, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font: 17px/1.45 var(--font); color: var(--ink); background: var(--cream);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
body.bare { padding-bottom: 0; }
img { max-width: 100%; height: auto; }
a { color: var(--green-700); }
h1 { font-size: 1.5rem; line-height: 1.2; margin: .2em 0 .6em; color: var(--green-900); }
h2 { font-size: 1.15rem; margin: 1.4em 0 .6em; color: var(--green-900); }
h3 { font-size: 1rem; margin: 0 0 .3em; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.sr-title, .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

.skip { position: absolute; left: -999px; top: 0; background: #fff; padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--orange-500); outline-offset: 2px; }

/* ---- Шапка ---- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 8px 14px; padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--green-800); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; min-height: 44px; }
.brand img { width: 40px; height: 40px; background: var(--cream); border-radius: 50%; padding: 2px; }
.brand-name { font-weight: 800; letter-spacing: .02em; font-size: 1rem; white-space: nowrap; }
.topnav { display: none; margin-left: 24px; gap: 4px; }
.topnav a { color: #fff; text-decoration: none; padding: 10px 14px; border-radius: 10px; font-weight: 600; }
.topnav a[aria-current="page"] { background: var(--green-700); box-shadow: inset 0 -3px 0 var(--orange-500); }
.usermenu { margin-left: auto; position: relative; }
.usermenu summary { list-style: none; cursor: pointer; min-width: 44px; min-height: 44px; display: grid; place-items: center; }
.usermenu summary::-webkit-details-marker { display: none; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--orange-500); color: var(--green-900); display: grid; place-items: center; font-weight: 800; }
.usermenu-pop {
  position: absolute; right: 0; top: 52px; background: var(--paper); color: var(--ink); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px; min-width: 220px; border: 1px solid var(--line);
}
.usermenu-pop a, .usermenu-pop .linklike { display: block; padding: 10px 6px; color: var(--ink); text-decoration: none; font-size: 1rem; }
.btn-ghost-light { margin-left: auto; white-space: nowrap; color: #fff !important; border: 2px solid rgba(255,255,255,.6); background: transparent; }

/* ---- Нижняя навигация ---- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--paper); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 10px; min-height: 64px;
  color: var(--muted); text-decoration: none; font-size: .8rem; font-weight: 600;
}
.bottomnav svg { width: 26px; height: 26px; fill: currentColor; }
.bottomnav a[aria-current="page"] { color: var(--green-800); box-shadow: inset 0 3px 0 var(--orange-500); }

.container { max-width: 1180px; margin: 0 auto; padding: 16px 14px 24px; }

/* ---- Главная: 4 крупные кнопки ---- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 4px 0 20px; }
.tile {
  display: flex; flex-direction: column; justify-content: space-between; min-height: 118px; padding: 16px;
  border-radius: 18px; background: var(--green-800); color: #fff; text-decoration: none; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.tile svg { width: 34px; height: 34px; fill: var(--orange-500); }
.tile-title { font-size: 1.2rem; font-weight: 800; }
.tile-meta { font-size: .85rem; opacity: .85; }
.tile:active { transform: scale(.98); }
.tile.accent { background: var(--orange-500); color: var(--green-900); }
.tile.accent svg { fill: var(--green-900); }

.hero-public { text-align: center; padding: 18px 0 8px; }
.hero-public img { width: 168px; height: auto; }

/* ---- Карточки и списки ---- */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); margin-bottom: 12px; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.row-link {
  display: flex; align-items: center; gap: 12px; padding: 12px 4px; min-height: var(--tap);
  color: var(--ink); text-decoration: none;
}
.row-link:hover { background: var(--green-100); }
.row-main { flex: 1; min-width: 0; }
.row-title { display: block; font-weight: 700; overflow-wrap: anywhere; }
.row-sub { display: block; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.chev { color: var(--muted); font-size: 1.4rem; }
.onhand-row { padding-bottom: 10px; }
.row-actions { display: flex; gap: 8px; padding: 0 4px; }
.row-actions .btn { flex: 1; }
.row-actions.wrap { flex-wrap: wrap; }
.row-actions.wrap .btn { flex: 1 1 140px; }
.row-actions.wrap input[type=text] { flex: 1 1 100%; min-height: 44px; }
@media (min-width: 600px) { .row-actions .btn { flex: 0 0 auto; } }
.empty { text-align: center; padding: 26px 12px; color: var(--muted); }
.empty .btn { margin-top: 10px; }

.kv { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 6px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .8rem; font-weight: 700; background: var(--green-100); color: var(--green-800); white-space: nowrap; }
.badge-ok { background: var(--green-100); color: var(--green-800); }
.badge-warn { background: var(--amber-100); color: var(--amber-800); }
.badge-bad { background: var(--red-100); color: var(--red-700); }
.badge-out { background: var(--orange-100); color: #8A3B00; }
.inv { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--green-900); letter-spacing: .02em; }

.statusbox { border-radius: var(--radius); padding: 14px; margin-bottom: 12px; font-weight: 600; }
.statusbox.ok { background: var(--green-100); color: var(--green-900); }
.statusbox.out { background: var(--orange-100); color: #6B2E00; }
.statusbox.bad { background: var(--red-100); color: var(--red-700); }

/* ---- Кнопки ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 10px 18px;
  border-radius: 12px; border: 2px solid transparent; font: inherit; font-weight: 700; cursor: pointer; text-decoration: none;
  background: var(--green-800); color: #fff; text-align: center;
}
.btn:hover { background: var(--green-700); }
.btn-primary { background: var(--orange-500); color: var(--green-900); }
.btn-primary:hover { background: #F59341; }
.btn-secondary { background: var(--paper); color: var(--green-800); border-color: var(--green-800); }
.btn-secondary:hover { background: var(--green-100); }
.btn-danger { background: var(--paper); color: var(--red-700); border-color: var(--red-700); }
.btn-small { min-height: 40px; padding: 6px 12px; font-size: .95rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.actions .btn { flex: 1 1 160px; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--green-700); text-decoration: underline; cursor: pointer; }
.fab-row { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 8px; }
.fab-row h1 { margin: 0; }
.back { display: inline-block; margin-bottom: 6px; color: var(--muted); text-decoration: none; padding: 6px 0; }

/* ---- Формы ---- */
.stack { display: grid; gap: 14px; }
details.more .stack { padding: 6px 0 10px; }
.field { display: grid; gap: 6px; }
.field label, .field .label { font-weight: 700; }
.hint { color: var(--muted); font-size: .875rem; }
input[type=text], input[type=tel], input[type=search], input[type=password], input[type=number], input[type=datetime-local], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; font: inherit; color: var(--ink); background: #fff;
  border: 2px solid #C9C1B1; border-radius: 12px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--green-700); outline: none; box-shadow: 0 0 0 3px rgba(242, 128, 36, .35); }
.check { display: flex; gap: 10px; align-items: flex-start; min-height: 44px; padding: 8px 0; cursor: pointer; }
.check input { width: 24px; height: 24px; margin: 0; flex: none; accent-color: var(--green-800); }
.seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; border: 0; padding: 0; margin: 0; }
.seg legend { font-weight: 700; margin-bottom: 6px; padding: 0; }
.seg label { display: block; cursor: pointer; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span {
  display: flex; align-items: center; justify-content: center; text-align: center; min-height: var(--tap); padding: 8px;
  border: 2px solid #C9C1B1; border-radius: 12px; background: #fff; font-weight: 700;
}
.seg input:checked + span { border-color: var(--green-800); background: var(--green-800); color: #fff; }
.seg input:focus-visible + span { outline: 3px solid var(--orange-500); outline-offset: 2px; }
.seg.danger input:checked + span.bad { background: var(--red-700); border-color: var(--red-700); }
.grid2 { display: grid; gap: 14px; }
details.more { border: 1px dashed var(--line); border-radius: 12px; padding: 6px 12px; }
details.more summary { cursor: pointer; font-weight: 700; padding: 8px 0; color: var(--green-700); }
.form-error { background: var(--red-100); color: var(--red-700); border-radius: 12px; padding: 12px; font-weight: 600; }

.searchbar { display: flex; gap: 8px; margin-bottom: 12px; }
.searchbar input { flex: 1; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; }
.chips a { white-space: nowrap; padding: 8px 14px; border-radius: 99px; border: 2px solid var(--line); text-decoration: none; color: var(--ink); font-weight: 600; background: var(--paper); min-height: 40px; display: inline-flex; align-items: center; }
.chips a[aria-current="true"] { background: var(--green-800); color: #fff; border-color: var(--green-800); }
.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--green-100); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.tabs a { text-align: center; padding: 10px; border-radius: 9px; text-decoration: none; color: var(--green-800); font-weight: 700; min-height: 44px; }
.tabs a[aria-current="true"] { background: var(--paper); box-shadow: var(--shadow); }

.flash { border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-weight: 600; }
.flash-ok { background: var(--green-100); color: var(--green-900); border-left: 5px solid var(--green-800); }
.flash-error { background: var(--red-100); color: var(--red-700); border-left: 5px solid var(--red-700); }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 10px 0 10px 16px; border-left: 3px solid var(--green-100); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 15px; width: 11px; height: 11px; border-radius: 50%; background: var(--green-700); }
.timeline .when { color: var(--muted); font-size: .85rem; }

table.data { width: 100%; border-collapse: collapse; background: var(--paper); }
table.data th, table.data td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.data th { font-size: .85rem; color: var(--muted); font-weight: 700; }

.login-wrap { max-width: 420px; margin: 6vh auto; }
.login-wrap .logo { display: block; width: 150px; margin: 0 auto 10px; }

/* ---- Компьютер штаба ---- */
@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .bottomnav { display: none; }
  .topnav { display: flex; }
  .topbar { padding-left: 24px; padding-right: 24px; }
  .container { padding: 24px; }
  .tiles { grid-template-columns: repeat(4, 1fr); gap: 16px; }
  .tile { min-height: 150px; padding: 20px; }
  .tile-title { font-size: 1.35rem; }
  .cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; align-items: start; }
  .grid2 { grid-template-columns: 1fr 1fr; }
  h1 { font-size: 1.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .tile:active { transform: none; }
}

/* ---- Печать этикеток ---- */
.labels { display: flex; flex-wrap: wrap; gap: 6mm; }
.label {
  width: 58mm; border: 1px solid #000; border-radius: 2mm; padding: 3mm; display: grid; grid-template-columns: 22mm 1fr;
  gap: 2mm; align-items: center; break-inside: avoid; background: #fff; color: #000;
}
.label canvas, .label .qr { width: 22mm; height: 22mm; image-rendering: pixelated; }
.label .l-org { font-size: 7pt; font-weight: 700; }
.label .l-inv { font-size: 15pt; font-weight: 900; letter-spacing: .02em; }
.label .l-name { font-size: 8pt; line-height: 1.15; }
.print-bar { margin-bottom: 14px; }
@media print {
  .print-bar { display: none; }
  body { background: #fff; padding: 0; }
}

/* ---- Поиски ---- */
.person { display: grid; gap: 14px; }
.person h1 { margin-top: 0; }
.person-photo { width: 100%; max-width: 360px; border-radius: 12px; display: block; }
@media (min-width: 600px) { .person { grid-template-columns: 240px 1fr; } .person:not(:has(img)) { grid-template-columns: 1fr; } }
.contact { display: grid; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.contact:last-child { border-bottom: 0; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.actions form { display: contents; }
.person-edit { padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px dashed var(--line); }
.tiles .tile { min-height: 96px; }
