/*
 * ErpgoPlatform — the whole stylesheet.
 *
 * ======================= WHY THERE IS NO BUILD STEP ========================
 * One file, hand-written, served as-is. No Tailwind, no PostCSS, no bundler.
 * The reasons are specific to this deployment rather than general taste:
 *
 *  * Every build tool is memory this box does not have at the moment it is
 *    needed. A deploy happens while a Claude run may be holding 1.7 GB.
 *  * A stylesheet small enough to read is a stylesheet whose cascade can be
 *    reasoned about. This is under 400 lines and covers every screen.
 *  * It is one request, cached, and it does not change between deploys unless
 *    somebody changed it.
 *
 * ========================== MOBILE FIRST, LITERALLY ========================
 * Every rule here is written for a 380 px screen. The two media queries at the
 * bottom are what a larger screen adds. That order matters: the phone layout is
 * the one that cannot be allowed to degrade, so it is the one with no
 * conditions on it.
 */

/* ------------------------------------------------------------------ tokens */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --ink: #16181d;
  --ink-soft: #5b6270;
  --line: #d9dde5;
  --accent: #2f6fd0;
  --accent-ink: #ffffff;
  --ok: #1d7a4c;
  --warn: #9a6400;
  --bad: #b3261e;

  --radius: 12px;
  --tap: 44px;
  --pad: 16px;

  /* The bottom bar's height, so `main` can reserve room for it. */
  --bar: calc(56px + env(safe-area-inset-bottom, 0px));

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f25;
    --surface-2: #23272f;
    --ink: #e8eaee;
    --ink-soft: #99a1b0;
    --line: #333944;
    --accent: #6ea4f0;
    --accent-ink: #0d1117;
    --ok: #57c48c;
    --warn: #e0a638;
    --bad: #ef7f77;
  }
}

/* ------------------------------------------------------------------- reset */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  /* Keeps a long page from shifting when a short one follows it. */
  scrollbar-gutter: stable;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font:
    16px/1.5 system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    'Helvetica Neue',
    sans-serif;
  /* Reserves the bottom bar so the last row of a list is never under it. */
  padding-bottom: var(--bar);
  min-height: 100dvh;
}

body.body--bare {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ============ THE LOGIN SCREEN HAS NO HEADER, AND THAT IS WHY =============
   The header carries the brand, and so does the login card — rendered at
   380 px that was the word "ErpgoPlatform" twice, 90 px apart. Worse, the card
   block is `min-height: 100dvh`, so the header pushed the one screen that must
   never scroll to 857 px inside a 780 px viewport.
   ========================================================================= */
body.body--bare .top {
  display: none;
}

h1,
h2,
h3 {
  margin: 0 0 8px;
  line-height: 1.25;
  font-weight: 620;
}

h1 {
  font-size: 22px;
}
h2 {
  font-size: 18px;
}

p {
  margin: 0 0 12px;
}

a {
  color: var(--accent);
}

/* ------------------------------------------------------------------ header */

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) var(--pad) 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 650;
  letter-spacing: -0.01em;
  margin-right: auto;
}

/* The live indicator. Three states, set by app.js on `data-live`. */
.live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-soft);
}

.live i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-soft);
}

.live[data-live='on'] i {
  background: var(--ok);
}

.live[data-live='off'] i {
  background: var(--bad);
}

.live[data-live='pending'] i {
  background: var(--warn);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.25;
  }
}

/* `prefers-reduced-motion` is not decoration here: a pulsing dot in the corner
   of a page somebody is watching for two hours is a real problem for some
   people. */
@media (prefers-reduced-motion: reduce) {
  .live[data-live='pending'] i {
    animation: none;
  }
  * {
    transition: none !important;
  }
}

.live__text {
  display: none;
}

/* The account menu — a <details>, so it works with JavaScript disabled. */
.menu {
  position: relative;
}

.menu summary {
  list-style: none;
  cursor: pointer;
  min-width: var(--tap);
  min-height: var(--tap);
  display: grid;
  place-items: center;
}

.menu summary::-webkit-details-marker {
  display: none;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  text-transform: uppercase;
}

.menu__panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  box-shadow: 0 12px 28px rgb(0 0 0 / 18%);
  display: grid;
  gap: 2px;
}

.menu__panel a {
  display: block;
  padding: 11px 10px;
  min-height: var(--tap);
  border-radius: 8px;
  text-decoration: none;
  color: var(--ink);
}

.menu__panel a:hover {
  background: var(--surface-2);
}

.menu__who {
  margin: 4px 10px 8px;
  font-size: 13px;
  color: var(--ink-soft);
}

.menu__langs {
  display: flex;
  gap: 4px;
  padding: 6px 4px 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}

.lang {
  flex: 1;
  /* ===================== MEASURED, NOT ASSUMED =============================
     This was 36px until a render at 380px measured it. The static test asserted
     `--tap: 44px` and checked `.btn`, `.tab` and `.linkish` — and passed, while
     the settings screen carried thirteen targets under 44px. A rule that is
     only applied where somebody remembered to apply it is not a rule.
     Full size on a phone; the desktop block below takes it back down, because
     a pointer does not need 44px and a row of three chunky buttons in a
     dropdown looks wrong with a mouse. */
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.lang--on {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* -------------------------------------------------------------------- page */

.page {
  padding: var(--pad);
  max-width: 900px;
  margin: 0 auto;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.panel__blurb {
  color: var(--ink);
}

.panel__note {
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.card h2 {
  margin-bottom: 10px;
}

.muted {
  color: var(--ink-soft);
  font-size: 14px;
}

.rows {
  display: grid;
  gap: 10px;
  margin: 0;
}

/* ============ A ROW IS TWO STACKED BLOCKS UNTIL THERE IS ROOM =============
   This was `display: flex; justify-content: space-between` unconditionally,
   and it read fine in the markup. Rendered at 380 px it was not fine: a label
   like "Предел стоимости одной работы, USD" next to a number input and a submit
   button left the button hanging over the edge of its card, and the autonomy
   `<select>` was clipped mid-word.
   
   None of the measurements caught it — there was no horizontal OVERFLOW,
   because flex had squeezed everything instead. Overflow is what a container
   does when it gives up; squeezing is what it does first, and it is just as
   unusable. Hence: stack on a phone, sit side by side once there is width.
   ========================================================================= */
.row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.row:last-child {
  border-bottom: 0;
}

.row dt,
.row__label {
  color: var(--ink-soft);
  font-size: 14px;
}

.row dd,
.row__value {
  margin: 0;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

/* An input inside a row shares the line with its submit button rather than
   pushing it off. `min-width: 0` is what lets a flex item actually shrink —
   without it the input keeps its default intrinsic width and overflows. */
.row__value input,
.row__value select {
  flex: 1 1 auto;
  min-width: 0;
}

.row__value .btn {
  flex: 0 0 auto;
}

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--line);
}

.pill--ok {
  color: var(--ok);
  border-color: currentColor;
}
.pill--warn {
  color: var(--warn);
  border-color: currentColor;
}
.pill--bad {
  color: var(--bad);
  border-color: currentColor;
}

/* ------------------------------------------------------------------- forms */

.form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
  color: var(--ink-soft);
}

input[type='text'],
input[type='password'],
input[type='number'],
select {
  /* 16px exactly. Anything smaller makes iOS Safari zoom the page on focus,
     which on a login form means the submit button leaves the screen. */
  font: inherit;
  font-size: 16px;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* The six-digit code. Wide tracking and a numeric keypad make it retypable
   from a phone notification without misreading a digit. */
.code-input {
  font-size: 28px;
  letter-spacing: 0.35em;
  text-align: center;
  padding-left: 0.35em;
}

.btn {
  font: inherit;
  font-weight: 600;
  min-height: var(--tap);
  padding: 12px 18px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  width: 100%;
}

.btn--quiet {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.btn--small {
  width: auto;
  /* "Small" is about WIDTH and type size, not about the hit area. A 36px-tall
     save button next to a numeric input is a mis-tap on a setting that governs
     production. Reduced to 36px for a pointer, below. */
  min-height: var(--tap);
  padding: 6px 14px;
  font-size: 14px;
}

.btn[disabled] {
  opacity: 0.55;
  cursor: default;
}

/* A bare link that behaves as a control — "start over" on the code screen. An
   anchor has no min-height of its own, so it rendered 22px tall. */
.link-quiet {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
}

.linkish {
  background: none;
  border: 0;
  color: var(--accent);
  font: inherit;
  padding: 12px 0;
  min-height: var(--tap);
  cursor: pointer;
}

.notice {
  margin: 0 0 14px;
  padding: 11px 13px;
  border-radius: 10px;
  font-size: 15px;
  border: 1px solid;
}

.notice--error {
  color: var(--bad);
  border-color: currentColor;
  background: color-mix(in srgb, var(--bad) 8%, transparent);
}

.notice--ok {
  color: var(--ok);
  border-color: currentColor;
  background: color-mix(in srgb, var(--ok) 8%, transparent);
}

.notice--info {
  color: var(--ink-soft);
  border-color: var(--line);
  background: var(--surface-2);
}

/* ------------------------------------------------------------------- login */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--pad);
}

.login__box {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
}

.login__title {
  margin-bottom: 4px;
}

.login__sub {
  color: var(--ink-soft);
  font-size: 14px;
  margin-bottom: 18px;
}

/* --------------------------------------------------------------- tab bar */

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tab {
  min-height: 56px;
  display: grid;
  place-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 11px;
  padding: 6px 2px;
}

.tab svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab--on {
  color: var(--accent);
  font-weight: 600;
}

/* ------------------------------------------------------------------ tables */

/* Wide content scrolls inside its own box; the page itself never scrolls
   sideways on a phone. */
.scroller {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
}

th,
td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  color: var(--ink-soft);
  font-weight: 600;
}

code,
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

/* ------------------------------------------------------- larger screens */

@media (min-width: 720px) {
  .live__text {
    display: inline;
  }

  /* Wide enough for the label and the control to share a line. */
  .row {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  .row__value {
    flex: 0 0 auto;
    max-width: 55%;
  }

  /* A pointer is precise, so the touch floor comes back off the two controls
     that only wear it for a thumb. Everything else keeps 44px. */
  .btn--small,
  .lang {
    min-height: 36px;
  }

  .link-quiet {
    min-height: 0;
  }

  .btn {
    width: auto;
  }

  .form .btn {
    justify-self: start;
  }

  /* The bar moves to the top and becomes a row of links: on a pointer device
     the thumb argument does not apply, and a fixed bottom bar wastes a strip of
     a large screen. */
  body {
    padding-bottom: 0;
  }

  .tabs {
    position: static;
    grid-template-columns: repeat(4, max-content);
    gap: 4px;
    border-top: 0;
    border-bottom: 1px solid var(--line);
    padding: 6px var(--pad);
  }

  .tab {
    grid-auto-flow: column;
    min-height: var(--tap);
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 14px;
  }

  .tab--on {
    background: var(--surface-2);
  }
}

@media (min-width: 1000px) {
  .page {
    padding: 24px;
  }
}
