/* «Надёжная зарядка» — design system.
   Built on Telegram's theme variables with explicit fallbacks, so the app looks
   right in light and dark, inside Telegram and in a plain browser. */

:root {
  /* surfaces */
  --bg:        var(--tg-theme-bg-color, #ffffff);
  --bg-2:      var(--tg-theme-secondary-bg-color, #f2f3f5);
  --card:      var(--tg-theme-bg-color, #ffffff);
  --fg:        var(--tg-theme-text-color, #0d0f12);
  --muted:     var(--tg-theme-hint-color, #78808c);
  --link:      var(--tg-theme-link-color, #2f80ed);
  --accent:    var(--tg-theme-button-color, #2f80ed);
  --accent-fg: var(--tg-theme-button-text-color, #ffffff);

  /* semantic */
  --ok:    #1db572;
  --warn:  #e8a33d;
  --err:   #e5484d;
  --info:  #2f80ed;
  --ok-bg:   rgba(29,181,114,.12);
  --warn-bg: rgba(232,163,61,.14);
  --err-bg:  rgba(229,72,77,.12);
  --info-bg: rgba(47,128,237,.12);

  --line: color-mix(in srgb, var(--fg) 10%, transparent);
  --line-soft: color-mix(in srgb, var(--fg) 6%, transparent);
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);

  --r-sm: 10px;
  --r:    14px;
  --r-lg: 18px;
  --r-xl: 24px;

  --pad: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --ease: cubic-bezier(.22,.61,.36,1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:   var(--tg-theme-bg-color, #17191c);
    --bg-2: var(--tg-theme-secondary-bg-color, #0f1114);
    --card: var(--tg-theme-bg-color, #1e2126);
    --fg:   var(--tg-theme-text-color, #eef1f5);
    --muted:var(--tg-theme-hint-color, #8d97a5);
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg-2);
  color: var(--fg);
  font: 400 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text",
        "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(76px + var(--safe-bottom)); }

#root { padding: calc(var(--safe-top) + 10px) var(--pad) 8px; max-width: 640px; margin: 0 auto; }

h1 { font-size: 24px; line-height: 1.2; margin: 0 0 4px; letter-spacing: -.02em; font-weight: 700; }
h2 { font-size: 17px; margin: 0 0 10px; font-weight: 650; letter-spacing: -.01em; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; color: var(--muted);
     text-transform: uppercase; letter-spacing: .05em; }
p  { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; line-height: 1.4; }
.tiny  { font-size: 12px; line-height: 1.35; }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
        font-size: .92em; letter-spacing: -.01em; }
.nodata { color: var(--muted); font-style: italic; }

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  animation: rise .32s var(--ease) both;
}
.card.flat { box-shadow: none; border: 1px solid var(--line-soft); }
.card + .card { margin-top: 0; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------------- hero */

.hero { position: relative; overflow: hidden; padding: 20px 18px; }
.hero .halo {
  position: absolute; inset: -40% -30% auto -30%; height: 220px;
  background: radial-gradient(60% 70% at 50% 0%, var(--halo, rgba(47,128,237,.22)), transparent 70%);
  pointer-events: none;
}
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hero-num { font-size: 52px; font-weight: 760; letter-spacing: -.04em; line-height: 1;
            margin: 10px 0 2px; font-variant-numeric: tabular-nums; }
.hero-num .of { font-size: 19px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.hero-sub { color: var(--muted); font-size: 14px; }

/* battery meter */
.meter { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 14px 0 4px; }
.meter > i { display: block; height: 100%; border-radius: 99px;
             background: linear-gradient(90deg, var(--ok), #38d39f);
             transition: width .6s var(--ease); }
.meter.warn > i { background: linear-gradient(90deg, var(--warn), #f0c674); }
.meter.err  > i { background: linear-gradient(90deg, var(--err), #ff7b7e); }

/* ---------------------------------------------------------------- pills */

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600; padding: 5px 11px; border-radius: 99px;
  background: var(--line); color: var(--muted); white-space: nowrap;
}
.pill.ok   { background: var(--ok-bg);   color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: #b9791c; }
.pill.err  { background: var(--err-bg);  color: var(--err); }
.pill.info { background: var(--info-bg); color: var(--info); }
@media (prefers-color-scheme: dark) { .pill.warn { color: var(--warn); } }

.dot { width: 7px; height: 7px; border-radius: 99px; background: currentColor; flex: none; }
.dot.live { animation: pulse 1.8s var(--ease) infinite; }
@keyframes pulse {
  0%,100% { opacity: 1; transform: scale(1); }
  50%     { opacity: .45; transform: scale(.82); }
}

/* ---------------------------------------------------------------- buttons */

button { font: inherit; cursor: pointer; border: 0; }

.btn {
  width: 100%; padding: 15px 18px; border-radius: var(--r);
  background: var(--accent); color: var(--accent-fg);
  font-size: 16.5px; font-weight: 640; letter-spacing: -.01em;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  transition: transform .14s var(--ease), opacity .14s var(--ease), filter .14s var(--ease);
}
.btn:active:not(:disabled) { transform: scale(.975); filter: brightness(.94); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.secondary { background: var(--line); color: var(--fg); }
.btn.ghost { background: transparent; color: var(--link); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.danger { background: var(--err); color: #fff; }
.btn.sm { padding: 10px 14px; font-size: 14.5px; border-radius: var(--r-sm); width: auto; }

.btn-row { display: flex; gap: 8px; }
.btn-row .btn { width: auto; flex: 1; }

/* sticky primary action */
.sticky-cta {
  position: sticky; bottom: calc(var(--safe-bottom) + 10px);
  margin-top: 14px; z-index: 5;
}

/* spinner inside a button */
.spin {
  width: 17px; height: 17px; border-radius: 99px; flex: none;
  border: 2.5px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: rot .7s linear infinite;
}
.spin.dark { border-color: var(--line); border-top-color: var(--fg); }
@keyframes rot { to { transform: rotate(360deg); } }

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

.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13.5px; font-weight: 560; margin-bottom: 6px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; padding: 13px 14px; font-size: 16px; color: var(--fg);
  background: var(--bg-2); border: 1.5px solid transparent; border-radius: var(--r);
  transition: border-color .16s var(--ease), background .16s var(--ease);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); background: var(--bg);
}
.field.bad input { border-color: var(--err); }
.field .err { color: var(--err); font-size: 13px; margin-top: 6px; display: block; }
.field .hint { color: var(--muted); font-size: 12.5px; margin-top: 6px; display: block; }

.check {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  background: var(--bg-2); border-radius: var(--r); font-size: 15px; cursor: pointer;
  user-select: none;
}
.check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; flex: none; }

/* stepper */
.steps { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.steps .s { flex: 1; height: 4px; border-radius: 99px; background: var(--line); overflow: hidden; }
.steps .s > i { display: block; height: 100%; width: 0; background: var(--accent);
                border-radius: 99px; transition: width .45s var(--ease); }
.steps .s.done > i, .steps .s.active > i { width: 100%; }
.steps .s.active > i { background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 45%, transparent)); }
.step-label { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; font-weight: 560; }

/* ---------------------------------------------------------------- rows */

.kv { display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
      padding: 11px 0; border-bottom: 1px solid var(--line-soft); }
.kv:last-child { border-bottom: 0; padding-bottom: 0; }
.kv:first-of-type { padding-top: 0; }
.kv > span { color: var(--muted); font-size: 14px; flex: none; }
.kv > b { font-weight: 620; text-align: right; font-size: 15px; }

.note {
  display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--r);
  font-size: 14px; line-height: 1.4; margin-bottom: 12px;
}
.note .ico { font-size: 17px; line-height: 1.25; flex: none; }
.note.err  { background: var(--err-bg);  color: var(--err); }
.note.ok   { background: var(--ok-bg);   color: var(--ok); }
.note.warn { background: var(--warn-bg); color: #9a6410; }
.note.info { background: var(--info-bg); color: var(--info); }
@media (prefers-color-scheme: dark) { .note.warn { color: var(--warn); } }

/* ---------------------------------------------------------------- states */

.state { text-align: center; padding: 26px 18px; }
.state .emoji { font-size: 46px; line-height: 1; margin-bottom: 12px; display: block;
                animation: pop .45s var(--ease) both; }
.state h2 { font-size: 20px; margin-bottom: 6px; }
.state p { color: var(--muted); font-size: 15px; }
@keyframes pop {
  0%   { transform: scale(.6); opacity: 0; }
  60%  { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

.skeleton { background: var(--line); border-radius: var(--r-sm);
            animation: sheen 1.3s ease-in-out infinite; }
@keyframes sheen { 0%,100% { opacity: .55; } 50% { opacity: .95; } }
.sk-line { height: 13px; margin-bottom: 9px; }
.sk-line.w40 { width: 40%; } .sk-line.w60 { width: 60%; } .sk-line.w80 { width: 80%; }
.sk-num { height: 46px; width: 55%; margin: 10px 0; }

/* ---------------------------------------------------------------- tabbar */

#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; gap: 4px; padding: 7px 10px calc(7px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line-soft);
}
#tabbar button {
  flex: 1; padding: 9px 6px 7px; border-radius: 12px; background: transparent;
  color: var(--muted); font-size: 11px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  transition: color .16s var(--ease);
}
#tabbar button .ic { font-size: 19px; line-height: 1;
                     transition: transform .22s var(--ease); }
#tabbar button.active { color: var(--accent); }
#tabbar button.active .ic { transform: translateY(-1px) scale(1.08); }

/* ---------------------------------------------------------------- admin */

/* Wrap onto multiple rows so every tab is visible on a phone. A single
   horizontally-scrolled row hid later tabs (e.g. «Обслуживание») behind the
   edge with no scrollbar cue. */
.subtabs { display: flex; flex-wrap: wrap; gap: 7px; padding: 2px 0 12px; }
.subtabs button {
  padding: 8px 14px; border-radius: 99px; background: var(--card); color: var(--muted);
  font-size: 13.5px; font-weight: 600; white-space: nowrap; box-shadow: var(--shadow);
  transition: background .16s var(--ease), color .16s var(--ease);
}
.subtabs button.active { background: var(--accent); color: var(--accent-fg); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 9px; }
.stat { background: var(--card); border-radius: var(--r); padding: 12px;
        box-shadow: var(--shadow); }
.stat span { font-size: 11.5px; color: var(--muted); display: block; line-height: 1.3; }
.stat b { font-size: 22px; font-weight: 700; display: block; margin-top: 3px;
          font-variant-numeric: tabular-nums; }

/* slot grid */
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 9px; }
.slot {
  background: var(--bg-2); border-radius: var(--r); padding: 12px;
  border: 1.5px solid transparent; transition: border-color .16s var(--ease),
          transform .14s var(--ease);
  position: relative;
}
.slot.sel { border-color: var(--accent); }
.slot:active { transform: scale(.985); }
.slot .n { font-size: 12px; color: var(--muted); font-weight: 600; }
.slot .uid { font-size: 12.5px; margin: 3px 0 7px; }
.slot .pct { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }
.slot .meter { margin: 7px 0 6px; height: 5px; }
.slot.low .pct { color: var(--warn); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 7px; border-bottom: 1px solid var(--line-soft);
         vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase;
     letter-spacing: .04em; cursor: pointer; user-select: none; }
th.nosort { cursor: default; }
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
tr.low td { background: var(--warn-bg); }
tr.stale td { opacity: .6; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 99px;
         font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.b-ready    { background: var(--ok-bg);   color: var(--ok); }
.b-charging { background: var(--info-bg); color: var(--info); }
.b-error    { background: var(--err-bg);  color: var(--err); }
.b-empty    { background: var(--line);    color: var(--muted); }
.b-issued   { background: rgba(155,120,255,.18); color: #7d5bd6; }
.b-reserved { background: var(--warn-bg); color: #9a6410; }
.b-excluded { background: var(--line);    color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .b-issued { color: #c4b2ff; } .b-reserved { color: var(--warn); }
}

.tag { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.filters { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 12px; }
.filters input, .filters select {
  flex: 1 1 130px; padding: 10px 12px; font-size: 14px; border-radius: var(--r-sm);
  background: var(--bg-2); border: 1.5px solid transparent; color: var(--fg);
}
.filters input:focus, .filters select:focus { outline: none; border-color: var(--accent); }

.pager { display: flex; gap: 10px; justify-content: center; align-items: center;
         margin-top: 14px; }

details > summary { cursor: pointer; color: var(--muted); font-size: 12.5px; padding: 4px 0; }
pre { white-space: pre-wrap; word-break: break-word; font-size: 11.5px; color: var(--muted);
      background: var(--bg-2); padding: 9px; border-radius: var(--r-sm); margin: 6px 0 0; }

/* modal sheet */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end;
  background: rgba(0,0,0,.42); animation: fade .2s var(--ease) both;
}
.sheet {
  width: 100%; max-width: 640px; margin: 0 auto;
  background: var(--bg); border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 18px var(--pad) calc(18px + var(--safe-bottom));
  animation: up .28s var(--ease) both; max-height: 86vh; overflow-y: auto;
}
.sheet .grip { width: 38px; height: 4px; border-radius: 99px; background: var(--line);
               margin: 0 auto 14px; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--safe-bottom));
  transform: translateX(-50%) translateY(14px); opacity: 0;
  background: color-mix(in srgb, var(--fg) 92%, transparent); color: var(--bg);
  padding: 11px 18px; border-radius: 99px; font-size: 14px; font-weight: 560;
  z-index: 60; pointer-events: none; max-width: 90vw; text-align: center;
  transition: opacity .25s var(--ease), transform .25s var(--ease);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
