/* Dark only: there is no light theme. */
:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #262624;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #9a9890;
  --border: rgba(255, 255, 255, 0.12);
  --grid: #2c2c2a;
  --axis: #383835;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --danger: #e66767;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #e66767;
  --neutral: #898781;
  --highlight: #3a3218;
  --flash-ok: #15301a;
  --flash-err: #3a1717;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--page); color: var(--ink); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
code { font-size: .8rem; color: var(--ink-2); word-break: break-word; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 800; font-size: 1.15rem; color: var(--ink); letter-spacing: .04em; }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.topbar nav a { padding: .35rem .65rem; border-radius: 6px; color: var(--ink-2); }
.topbar nav a:hover { background: var(--surface-2); text-decoration: none; }
.topbar nav a.active { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.me { display: flex; align-items: center; gap: .75rem; font-size: .9rem; }
.me a { color: var(--ink); }
.me form { margin: 0; }

main { max-width: 1280px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }

/* Buttons & inputs */
button, .button {
  font: inherit; font-size: .9rem; cursor: pointer;
  padding: .45rem .9rem; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  display: inline-block; text-decoration: none;
}
button:hover, .button:hover { background: var(--surface-2); text-decoration: none; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.primary:hover { background: var(--accent); filter: brightness(1.08); }
.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button.link:hover { text-decoration: underline; background: none; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: .45rem .6rem; width: 100%;
  font-weight: 400;
}
input[type=checkbox], input[type=radio] { width: auto; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.stack { display: flex; flex-direction: column; gap: .9rem; }
.stack label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .9rem; }
.stack label.inline { flex-direction: row; align-items: center; gap: .5rem; }
.narrow { max-width: 640px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.actions { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.actions form { margin: 0; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .9rem; margin: 0; }
legend { font-weight: 600; font-size: .9rem; padding: 0 .3rem; }
.radios { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; }
.stack .radio { flex-direction: row; align-items: center; gap: .35rem; font-weight: 400; }
.danger-zone { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border); max-width: 640px; }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .75rem; }
.filters input[type=search] { flex: 1 1 240px; width: auto; }
.filters select { width: auto; }
.filters label.inline { display: flex; align-items: center; gap: .35rem; font-size: .9rem; color: var(--ink-2); }
.filters label.inline input[type=date] { width: auto; }

.flash { padding: .65rem .9rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid var(--border); }
.flash.success { background: var(--flash-ok); }
.flash.error { background: var(--flash-err); }

/* Cards, tables */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
th, td { padding: .5rem .6rem; border-bottom: 1px solid var(--grid); vertical-align: middle; }
#results > .table-wrap, #results > table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.clip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr.highlight td { background: var(--highlight); }
tr.inactive td { color: var(--muted); }
.warn-text { color: var(--critical); font-weight: 600; }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin-top: 1rem; }

/* Status badges: colored dot + text label (never color alone) */
.badge { display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap; font-size: .85rem; color: var(--ink); }
.badge::before { content: ""; width: .6rem; height: .6rem; border-radius: 50%; background: var(--neutral); flex: none; }
h1 .badge { font-size: 1rem; margin-right: .5rem; }
/* movements */
.s-receive::before { background: var(--accent); }
.s-ready::before { background: var(--good); }
.s-issue::before { background: var(--warning); }
.s-return::before, .s-flight::before { background: var(--neutral); }
.s-adjust::before { background: var(--serious); }
/* flight outcomes: success green, failure yellow, other grey, returned red */
.s-destroyed::before, .s-hit::before, .s-done::before, .s-unobserved::before, .s-mining::before { background: var(--good); }
.s-missed::before, .s-video_lost::before, .s-control_lost::before, .s-battery_out::before,
.s-shot_down::before, .s-fiber_break::before, .s-no_detonation::before { background: var(--warning); }
.s-other::before { background: var(--neutral); }
.s-returned::before { background: var(--critical); }
.outcome-group + .outcome-group { margin-top: .6rem; }
.outcome-group > span { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .25rem; }

/* Equipment quantity stepper */
.qty { white-space: nowrap; }
.stepper { display: inline-flex; align-items: center; gap: .4rem; margin: 0; }
.stepper button { padding: .1rem .5rem; line-height: 1.2; }
.stepper span { min-width: 2.5ch; text-align: center; }

/* Item details */
.details dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem 1.5rem; margin: 0; }
.details dt { font-size: .8rem; color: var(--muted); }
.details dd { margin: .15rem 0 0; }
.notes { white-space: pre-wrap; margin: 1rem 0 0; }

/* Item page: photo beside the details */
.item-layout { display: grid; grid-template-columns: minmax(220px, 340px) 1fr; gap: 0 1rem; align-items: start; }
.photo { display: block; width: 100%; max-height: 420px; object-fit: contain; border-radius: 6px; background: var(--surface-2); margin-bottom: .9rem; }
.photo-empty { display: grid; place-items: center; height: 180px; border: 1px dashed var(--border); border-radius: 6px; margin-bottom: .9rem; }
.photo-card form + form { margin-top: .6rem; }
.thumb-cell { width: 52px; padding-right: 0; }
.thumb { display: block; width: 44px; height: 44px; object-fit: cover; border-radius: 4px; background: var(--surface-2); }
input[type=file] { padding: .3rem; font-size: .85rem; }

a:has(> .thumb), a:has(> .photo) { display: block; cursor: zoom-in; }

/* Photo modal */
.lightbox { padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); max-width: 96vw; max-height: 96vh; overflow: hidden; }
.lightbox::backdrop { background: rgba(0, 0, 0, .8); }
.lightbox img { display: block; max-width: 96vw; max-height: 94vh; object-fit: contain; }
.lightbox form { position: absolute; top: .5rem; right: .5rem; margin: 0; }
.lightbox button { background: var(--page); padding: .25rem .6rem; }

/* Repair queue */
.card-table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.note-form { display: flex; gap: .4rem; margin: 0; min-width: 220px; }
.note-form input { padding: .25rem .4rem; }
.note-form button { padding: .25rem .6rem; }
.inline-form input[type=number] { width: 3.5rem; }

/* Photo block on the equipment form */
.photo-inline { display: flex; gap: 1rem; align-items: flex-start; }
.photo-inline .thumb { width: 120px; height: 120px; }
.small-empty { width: 120px; height: 120px; margin: 0; flex: none; }
.photo-inline > .stack { flex: 1; }

/* Collapsible sections (Майстерня) */
details.section { margin-bottom: 1.25rem; }
details.section > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
details.section[open] > summary::before { transform: rotate(90deg); }
details.section > summary h2 { margin: 0; }
details.section > summary:hover h2 { color: var(--accent); }

/* Back link above a form's title */
.back { display: inline-block; margin-bottom: .6rem; font-size: .9rem; color: var(--ink-2); }

/* Waiting for the position's confirmation */
.chip.pending { border-color: var(--warning); color: var(--warning); }
.pending-card { border-color: var(--warning); }
.pending-card form { margin: 0; }
.pending-text { color: var(--warning); }
.places .chip { margin-right: .25rem; }
.actions.end { justify-content: flex-end; flex-wrap: nowrap; }
.chip.opto { border-color: var(--accent); color: var(--accent); }

/* A sub-form inside a card, set apart from the list above it */
.subform { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.subform h3 { font-size: .95rem; margin: 0 0 .75rem; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .3rem 1rem; max-height: 16rem; overflow-y: auto; }
.stack .checks label { flex-direction: row; align-items: center; gap: .4rem; font-weight: 400; }

/* Tabs (catalogue sections, position filter) */
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: .75rem; }
.page-head .tabs { margin-bottom: 0; }
.tabs a { padding: .35rem .75rem; border-radius: 6px; color: var(--ink-2); border: 1px solid var(--border); font-size: .9rem; }
.tabs a:hover { background: var(--surface-2); text-decoration: none; }
.tabs a.active { background: var(--surface-2); color: var(--ink); font-weight: 600; border-color: var(--accent); }

/* Repeating form rows: shipment lines, custom fields */
.lines { display: flex; flex-direction: column; gap: .4rem; margin-bottom: .6rem; }
.line { display: grid; grid-template-columns: 1fr 7rem; gap: .5rem; }
.line.even { grid-template-columns: 1fr 1fr; }
.medium { max-width: 860px; }
.inline-form { display: inline-flex; gap: .4rem; align-items: center; margin: 0; }
.inline-form input { width: 5.5rem; text-align: right; padding: .25rem .4rem; }
.inline-form button { padding: .25rem .6rem; }
.chip { display: inline-block; padding: .05rem .45rem; border: 1px solid var(--border); border-radius: 999px; font-size: .8rem; white-space: nowrap; margin: .1rem 0; }
.spaced { margin-top: 1.25rem; }
h2 .muted { font-weight: 400; }

/* Dashboard */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.tile {
  display: flex; flex-direction: column; gap: .2rem; padding: .9rem 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--ink);
}
.tile:hover { text-decoration: none; border-color: var(--accent); }
.tile-label { font-size: .85rem; color: var(--ink-2); }
.tile-value { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.tile-sub { font-size: .8rem; color: var(--muted); }
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.chart-card { margin: 0 0 1rem; }
.chart-card figcaption { font-weight: 600; margin-bottom: .5rem; }
.chart-box { position: relative; height: 240px; }
.columns { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; align-items: start; }
.columns.three { grid-template-columns: repeat(3, 1fr); }
.columns.four { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 0 1rem; }
.tile form { margin: .4rem 0 0; }
a.tile-value, a.tile-label { color: inherit; }
a.tile-label { color: var(--ink-2); }

/* Login */
.login { max-width: 360px; margin: 10vh auto 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; }

@media (max-width: 760px) {
  .charts, .columns, .columns.three, .columns.four, .row, .item-layout { grid-template-columns: 1fr; }
  .topbar { gap: .5rem; }
  .me { width: 100%; justify-content: space-between; }
}
