:root {
  --bg: #14181d; --card: #1e242c; --line: #303945; --text: #e8edf2; --dim: #93a0ae;
  --accent: #ff8a1f; --ok: #4cc27a; --bad: #ef5d5d;
  --field: #12161b; --btn: #2b3440; --nav: #10141a; --warn: #ffcf66; --row: #262e38; --hl: #ff8a1f1c;
  --shade: #000a; --toast: #000d; --toast-text: #e8edf2;
  --top: max(env(safe-area-inset-top), var(--safe-area-inset-top, 0px));
  --bottom: max(env(safe-area-inset-bottom), var(--safe-area-inset-bottom, 0px));
}
/* Светлая тема: приложение ставит data-theme на <html> по настройке или по системе. */
:root[data-theme="light"] {
  --bg: #eef1f6; --card: #ffffff; --line: #ccd5e0; --text: #11161c; --dim: #5a6775;
  --accent: #cf6a00; --ok: #17803d; --bad: #cc3333;
  --field: #ffffff; --btn: #e6ebf2; --nav: #ffffff; --warn: #8a5a00; --row: #e8ecf2; --hl: #cf6a0022;
  --shade: #0007; --toast: #202830f2; --toast-text: #ffffff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, Roboto, sans-serif; overscroll-behavior: none; }
main { padding: calc(var(--top) + 12px) 16px calc(var(--bottom) + 84px); max-width: 640px; margin: 0 auto; }
h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 15px; margin: 22px 0 8px; color: var(--dim); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
p { margin: 8px 0; }
.dim { color: var(--dim); font-size: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 10px 0; }
label { display: block; font-size: 13px; color: var(--dim); margin: 10px 0 4px; }
select, input[type=text], input[type=number], textarea {
  width: 100%; min-height: 46px; padding: 8px 12px; font: inherit; color: var(--text);
  background: var(--field); border: 1px solid var(--line); border-radius: 10px;
}
button { font: inherit; color: var(--text); background: var(--btn); border: 1px solid var(--line); border-radius: 10px; min-height: 46px; padding: 8px 14px; }
button:active { filter: brightness(1.25); }
:root[data-theme="light"] button:active { filter: brightness(.93); }
button.primary { background: var(--accent); border-color: var(--accent); color: #1a1205; font-weight: 700; }
button.ok { background: var(--ok); border-color: var(--ok); color: #06240f; font-weight: 700; }
button.ghost { background: none; border-color: transparent; }
button.small { min-height: 36px; padding: 4px 10px; font-size: 14px; }
button.danger { color: var(--bad); }
button:disabled { opacity: .45; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; min-width: 0; }
.row > .fit { flex: 0 0 auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chips button { min-height: 34px; padding: 2px 12px; font-size: 14px; border-radius: 17px; }
.chips button.on { background: var(--accent); color: #111; border-color: var(--accent); }
/* снятый профиль: название ставит на оружие, корзина удаляет */
.chips .pair { display: inline-flex; max-width: 100%; }
.chips .pair button:first-child { border-radius: 17px 0 0 17px; min-width: 0; }
.chips .pair button:last-child { border-radius: 0 17px 17px 0; margin-left: -1px; padding: 2px 10px; flex: none; }
.stack > button { width: 100%; margin-top: 8px; }
.item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item > div { flex: 1; min-width: 0; }
.item b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* миниатюра мишени в журнале: видно, что снимок на месте и запись открывается */
.item > .thumb { flex: none; width: 52px; height: 66px; border-radius: 8px; object-fit: cover; background: var(--line); border: 1px solid var(--line); }
.item > .thumb.none { display: flex; align-items: center; justify-content: center; font-size: 22px; color: var(--dim); }
.big { font-size: 26px; font-weight: 800; letter-spacing: .01em; }
.up { color: var(--accent); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 15px; }
.kv span { color: var(--dim); }
.warn { color: var(--warn); font-size: 14px; }
ol { padding-left: 20px; margin: 6px 0; }

#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--nav); border-top: 1px solid var(--line); padding-bottom: var(--bottom); z-index: 5; }
#tabs button { flex: 1; background: none; border: 0; border-radius: 0; min-height: 60px; font-size: 12px; color: var(--dim); padding: 4px 0; }
#tabs button i { display: block; font-style: normal; font-size: 22px; line-height: 26px; }
#tabs button.on { color: var(--accent); }

#analysis { position: fixed; inset: 0; z-index: 10; background: var(--bg); display: flex; flex-direction: column; padding-top: var(--top); }
#analysis[hidden] { display: none; }
#analysis header { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; flex: 0 0 auto; }
#an-stage { position: relative; flex: 1 1 55%; min-height: 0; background: #000; touch-action: none; }
#an-canvas { width: 100%; height: 100%; display: block; touch-action: none; }
#an-busy { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: #000a; font-size: 18px; }
#an-busy[hidden] { display: none; }
#an-panel { flex: 0 1 auto; max-height: 45%; overflow-y: auto; padding: 8px 14px calc(var(--bottom) + 12px); }

dialog { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 14px; width: min(92vw, 460px); padding: 16px; }
dialog::backdrop { background: var(--shade); }
dialog h3 { margin: 0 0 6px; }
#toast { position: fixed; left: 50%; bottom: calc(var(--bottom) + 80px); transform: translateX(-50%); background: var(--toast); color: var(--toast-text); border: 1px solid var(--line); padding: 10px 16px; border-radius: 22px; z-index: 30; max-width: 90vw; text-align: center; }
#an-title { flex: 1; min-width: 0; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#analysis header button { white-space: nowrap; }

.tbl { overflow-x: auto; }
.tbl table { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
.tbl th { text-align: right; font-weight: 600; font-size: 12px; color: var(--dim); padding: 4px 6px; border-bottom: 1px solid var(--line); }
.tbl td { text-align: right; padding: 7px 6px; border-bottom: 1px solid var(--row); white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.hl td { background: var(--hl); }
.tbl td small { display: block; color: var(--dim); font-size: 12px; }
.article table th, .article table td { text-align: left; white-space: normal; }
.article { line-height: 1.5; }
.article ul, .article ol { padding-left: 20px; margin: 8px 0; }
.article li { margin: 5px 0; }
.item b.wrap { white-space: normal; }
.item[data-act] { cursor: pointer; }
.ret { display: flex; gap: 14px; align-items: flex-start; }
.ret svg { flex: 0 0 auto; color: var(--text); }
.ret p { margin: 4px 0 0; font-size: 14px; color: var(--dim); }
#tabs button { font-size: 11px; }
a.btn { display: flex; align-items: center; justify-content: center; min-height: 46px; padding: 8px 14px; border-radius: 10px; text-decoration: none; background: var(--btn); color: var(--text); border: 1px solid var(--line); }
a.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1205; font-weight: 700; }
.banner { display: flex; align-items: center; gap: 10px; border-color: var(--accent); cursor: pointer; }
.banner > div { flex: 1; }
.banner b, .banner span { color: var(--accent); }
.notes { max-height: 42vh; overflow-y: auto; margin: 8px 0; }
.notes ul { margin: 4px 0 12px; padding-left: 20px; }
.notes li { margin: 4px 0; font-size: 15px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatches button { width: 38px; height: 38px; min-height: 0; padding: 0; border-radius: 50%; border: 2px solid var(--line); }
.swatches button.on { outline: 3px solid var(--text); outline-offset: 2px; }

/* Карточка-слот: оружие и то, что на нём стоит */
.slot { padding: 14px; }
.slot[data-act] { cursor: pointer; }
.slot.on { border-color: var(--accent); }
.slot .head { display: flex; align-items: center; gap: 10px; }
.slot .head > div { flex: 1; min-width: 0; }
.slot .head b { display: block; font-size: 17px; }
.slot label { margin-top: 14px; }
.slot .chips button { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.wide { width: 100%; }

/* Поиск по базе в форме профиля */
.found { max-height: 38vh; overflow-y: auto; margin: 4px 0 2px; }
.found.tall { max-height: 56vh; }
.stack > button .sub { display: block; font-size: 13px; font-weight: 400; opacity: .75; }
.found h4 { margin: 10px 0 8px; font-size: 16px; }
.spec { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 12px; font-size: 14px; }
.spec dt { color: var(--dim); }
.spec dd { margin: 0; }
.found .stack > button { text-align: center; border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--btn, none); }
.found .stack > button.primary { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 600; }
.found p { margin: 10px 0 4px; }
.found button { display: block; width: 100%; text-align: left; min-height: 0; padding: 9px 2px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: none; }
.found button:active { background: var(--hl); filter: none; }
.found button b { display: block; font-weight: 600; }
.found button[data-pick="up"] { position: sticky; top: 0; background: var(--card); color: var(--accent); z-index: 1; }
.found button span { display: block; font-size: 13px; }
input[type=search] { width: 100%; min-height: 46px; padding: 8px 12px; font: inherit; color: var(--text); background: var(--field); border: 1px solid var(--line); border-radius: 10px; }

button.wide { width: 100%; margin-top: 10px; }
textarea { width: 100%; resize: vertical; font: inherit; }

/* Сравнение патронов и карточка поправок */
.chart { width: 100%; height: auto; display: block; margin-top: 10px; }
.chart text { font-size: 9px; fill: var(--dim); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; margin: 4px 0 8px; }
.dope table { width: 100%; border-collapse: collapse; margin-top: 10px; font-variant-numeric: tabular-nums; }
.dope th { text-align: left; font-size: 12px; font-weight: 600; color: var(--dim); padding: 4px 6px; border-bottom: 1px solid var(--line); }
.dope td { padding: 9px 6px; font-size: 22px; border-bottom: 1px solid var(--row); white-space: nowrap; }
.dope td:first-child { font-weight: 700; }
.dope td:last-child, .dope th:last-child { text-align: right; font-size: 15px; }
.dope tr.hl td { background: var(--hl); }
.dope tr:last-child td { border-bottom: 0; }

/* Карточка характеристик: сетка, «на кого», справка о производителе */
.sheet { max-height: 68vh; overflow-y: auto; }
.sheet h4 { margin: 0 0 8px; font-size: 17px; }
.sheet h5, .found h5 { margin: 14px 0 6px; font-size: 13px; color: var(--dim); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.sheet ul, .found ul { margin: 6px 0; padding-left: 20px; }
.sheet .ret, .found .ret { margin: 4px 0; }
.spec select { min-height: 38px; padding: 4px 8px; }
/* кнопки «Выбрать» и «Вернуться» остаются на виду, пока карточка прокручивается */
.found .stack.pin { position: sticky; bottom: 0; background: var(--card); padding: 2px 0 4px; }

/* Календарь охоты */
input[type=date] { width: 100%; min-height: 46px; padding: 8px 12px; font: inherit; color: var(--text); background: var(--field); border: 1px solid var(--line); border-radius: 10px; color-scheme: dark; }
:root[data-theme="light"] input[type=date] { color-scheme: light; }
.caution { border-color: var(--warn); }
.alarm { border-color: var(--bad); color: var(--bad); }
.tag { display: inline-block; font-size: 12px; color: var(--dim); border: 1px solid var(--line); border-radius: 9px; padding: 1px 8px; margin: 3px 0 4px; }
.tag.warn { color: var(--warn); border-color: var(--warn); }
.tag.bad { color: var(--bad); border-color: var(--bad); }
.tag.ok { color: var(--ok); border-color: var(--ok); }
