:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --bg-soft: #e9eef3;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #687078;
  --line: #d7dde2;
  --head: #0d6efd;
  --head-dark: #0b5ed7;
  --tab: #e0e0e0;
  --tab-active: #d0d0d0;
  --accent: #dc3545;
  --ok: #198754;
  --radius: 6px;
  --topbar-h: 70px;
  --workbar-h: 58px;
  --bottom-nav-h: 58px;
  --shadow: 0 10px 28px rgba(31, 35, 40, 0.16);
}

body.theme-dark {
  color-scheme: dark;
  --bg: #20252b;
  --bg-soft: #252b32;
  --panel: #2b3138;
  --ink: #f3f5f7;
  --muted: #aab4bf;
  --line: #46505a;
  --head: #3f8cff;
  --head-dark: #68a4ff;
  --tab: #27303a;
  --tab-active: #37414d;
  --accent: #ff7b86;
  --ok: #58d08f;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  min-height: 100svh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  width: min(980px, 100%);
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: var(--topbar-h) 10px 10px;
  background: var(--bg);
}

.topbar {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(980px, 100%);
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: var(--topbar-h);
  margin: 0;
  padding: 10px max(10px, env(safe-area-inset-left)) 9px max(10px, env(safe-area-inset-right));
  background: rgba(243, 245, 247, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

body.theme-dark .topbar {
  background: rgba(32, 37, 43, 0.96);
}

.topbar > div {
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.topbar p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .loaded-at {
  color: #495057;
}

body.theme-dark .topbar .loaded-at {
  color: #c1cad3;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-button,
.back-button,
.theme-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--head-dark);
  border-radius: var(--radius);
  background: var(--head);
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
}

.theme-button {
  width: 38px;
  min-width: 38px;
  padding: 0;
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 18px;
  box-shadow: none;
}

.theme-button:active {
  background: var(--tab-active);
}

.back-button {
  min-height: 34px;
  background: #6c757d;
  border-color: #5c636a;
}

.label-short {
  display: none;
}

.file-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.loader-panel {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: calc(100svh - 92px);
  padding: 28px 16px;
  border: 1px dashed #9ea7b0;
  border-radius: var(--radius);
  background: var(--panel);
  text-align: center;
}

.loader-panel strong {
  font-size: 21px;
}

.loader-panel span,
.empty-state span {
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.workspace {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 9px;
  min-height: calc(100svh - var(--topbar-h));
  padding-top: 10px;
}

.screenbar {
  position: fixed;
  top: var(--topbar-h);
  left: 50%;
  transform: translateX(-50%);
  width: min(980px, 100%);
  z-index: 4;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px max(10px, env(safe-area-inset-left)) 4px max(10px, env(safe-area-inset-right));
  background: var(--bg);
}

.screenbar h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar {
  position: fixed;
  top: calc(var(--topbar-h) + 48px);
  left: 50%;
  transform: translateX(-50%);
  width: min(980px, 100%);
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  padding: 0 max(10px, env(safe-area-inset-left)) 8px max(10px, env(safe-area-inset-right));
  background: var(--bg);
}

.home-help {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.clock-widget {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.clock-face {
  position: relative;
  width: 124px;
  height: 124px;
  border: 5px solid #b8c0c8;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, var(--panel) 0 56%, transparent 57%),
    radial-gradient(circle at 50% 50%, #eef2f6 0 100%);
  box-shadow:
    inset 0 0 0 2px #8f9aa5,
    inset 0 0 0 7px #d7dde2,
    0 3px 10px rgba(31, 35, 40, 0.18);
}

body.theme-dark .clock-face {
  border-color: #5d6874;
  background:
    radial-gradient(circle at 50% 50%, #303741 0 56%, transparent 57%),
    radial-gradient(circle at 50% 50%, #222932 0 100%);
  box-shadow:
    inset 0 0 0 2px #77818d,
    inset 0 0 0 7px #3a434d,
    0 3px 10px rgba(0, 0, 0, 0.34);
}

.clock-tick {
  position: absolute;
  left: 50%;
  top: 8px;
  width: 1px;
  height: 5px;
  background: var(--muted);
  transform: translateX(-50%) rotate(calc(var(--tick) * 6deg));
  transform-origin: 50% 54px;
}

.clock-tick.major {
  top: 7px;
  width: 2px;
  height: 9px;
  background: var(--ink);
}

.clock-num {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
}

.n1 { transform: rotate(30deg) translateY(-43px) rotate(-30deg); }
.n2 { transform: rotate(60deg) translateY(-43px) rotate(-60deg); }
.n3 { transform: rotate(90deg) translateY(-43px) rotate(-90deg); }
.n4 { transform: rotate(120deg) translateY(-43px) rotate(-120deg); }
.n5 { transform: rotate(150deg) translateY(-43px) rotate(-150deg); }
.n6 { transform: rotate(180deg) translateY(-43px) rotate(-180deg); }
.n7 { transform: rotate(210deg) translateY(-43px) rotate(-210deg); }
.n8 { transform: rotate(240deg) translateY(-43px) rotate(-240deg); }
.n9 { transform: rotate(270deg) translateY(-43px) rotate(-270deg); }
.n10 { transform: rotate(300deg) translateY(-43px) rotate(-300deg); }
.n11 { transform: rotate(330deg) translateY(-43px) rotate(-330deg); }
.n12 { transform: rotate(0deg) translateY(-43px) rotate(0deg); }

.clock-brand,
.clock-city {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  color: var(--muted);
  font-weight: 800;
  letter-spacing: 0;
}

.clock-brand {
  top: 34px;
  font-size: 12px;
}

.clock-city {
  top: 76px;
  font-size: 10px;
}

.hand {
  position: absolute;
  left: 50%;
  bottom: 50%;
  width: 3px;
  transform-origin: 50% 100%;
  border-radius: 999px;
  background: var(--ink);
}

.hour-hand {
  height: 32px;
  width: 4px;
}

.minute-hand {
  height: 43px;
}

.second-hand {
  height: 48px;
  width: 1px;
  background: var(--accent);
}

.clock-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 11px;
  height: 11px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: var(--head);
  transform: translate(-50%, -50%);
}

.clock-text strong {
  display: block;
  font-size: 22px;
  line-height: 1.1;
}

.clock-text span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.help-toggle {
  width: 100%;
  min-height: 38px;
  border: 0;
  background: var(--tab);
  color: var(--ink);
  font-weight: 700;
  text-align: left;
  padding: 0 10px;
}

.help-toggle::after {
  content: "Показать";
  float: right;
  font-weight: 600;
  color: var(--muted);
}

.help-toggle.open::after {
  content: "Скрыть";
}

.help-content {
  display: grid;
  gap: 6px;
  padding: 10px;
  border-top: 1px solid var(--line);
}

.help-content h3 {
  margin: 4px 0 2px;
  font-size: 14px;
}

.help-content p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.help-content ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.toolbar input,
.date-filters input {
  width: 100%;
  min-height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
}

.date-filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.export-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.export-actions button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--tab);
  color: var(--ink);
  font-weight: 700;
}

.export-actions button:active {
  background: var(--tab-active);
}

body.theme-dark .toolbar input,
body.theme-dark .date-filters input {
  background: #252b32;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  border: 1px solid #c8cdd2;
  border-radius: var(--radius);
  overflow: hidden;
  background: #c8cdd2;
}

.tab {
  min-height: 38px;
  border: 0;
  background: var(--tab);
  color: var(--ink);
  font-weight: 600;
}

.tab.active {
  background: var(--head);
  color: #fff;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.55);
}

body.theme-dark .tab.active {
  background: var(--head);
  color: #07111f;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.55);
}

.content {
  display: grid;
  gap: 8px;
  min-height: 0;
  padding-top: var(--workbar-h);
  padding-bottom: max(22px, env(safe-area-inset-bottom));
}

.data-table {
  display: grid;
  align-content: start;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.data-table::after {
  content: "";
  display: block;
  min-height: 18px;
  border-top: 1px solid rgba(128, 128, 128, 0.08);
}

.table-head,
.table-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(74px, auto);
  gap: 8px;
  align-items: center;
}

.table-head {
  min-height: 34px;
  padding: 0 10px;
  background: var(--head);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.table-row {
  width: 100%;
  min-height: 58px;
  padding: 8px 10px;
  border: 0;
  border-top: 1px solid var(--line);
  background: var(--panel);
  text-align: left;
}

.category-row:first-of-type b {
  color: var(--head-dark);
}

.table-row:active {
  background: #eef4ff;
}

body.theme-dark .table-row:active {
  background: #303a46;
}

.table-row span {
  min-width: 0;
}

.table-row b {
  display: block;
  min-width: 0;
  font-size: 14px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.table-row small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.qty {
  justify-self: end;
  max-width: 110px;
  padding: 4px 7px;
  border: 1px solid #cfe2ff;
  border-radius: var(--radius);
  background: #eef4ff;
  color: #084298;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  overflow-wrap: anywhere;
}

body.theme-dark .qty {
  border-color: #355f9d;
  background: #26384f;
  color: #d6e8ff;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 160px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  text-align: center;
}

.details-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  align-items: end;
  padding: 12px;
  background: rgba(31, 35, 40, 0.38);
}

.details-card {
  width: min(720px, 100%);
  max-height: min(78svh, 720px);
  margin: 0 auto;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px 6px 4px 4px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.details-title {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.details-title strong {
  display: block;
  font-size: 16px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.details-title span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8f9fa;
  font-size: 22px;
  line-height: 1;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
}

.details-grid div {
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8f9fa;
}

body.theme-dark .details-grid div,
body.theme-dark .serial-list span,
body.theme-dark .history-list div,
body.theme-dark .icon-button {
  background: #252b32;
}

.details-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.details-grid b {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.details-card h3 {
  margin: 0;
  padding: 10px 12px 6px;
  font-size: 14px;
}

.serial-list,
.history-list {
  display: grid;
  gap: 6px;
  padding: 0 12px 12px;
}

.serial-search {
  padding: 0 12px 8px;
}

.serial-search input {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
}

body.theme-dark .serial-search input {
  background: #252b32;
}

.serial-list span,
.history-list div {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow-wrap: anywhere;
}

.serial-empty {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.serial-list .serial-hit {
  border-color: #ffc107;
  background: #fff3cd;
  color: #3b2b00;
  font-weight: 700;
}

body.theme-dark .serial-list .serial-hit {
  border-color: #ffd45a;
  background: #4c3d18;
  color: #fff3c4;
}

.serial-list small,
.history-list span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.show-more {
  width: calc(100% - 24px);
  min-height: 38px;
  margin: 0 12px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--tab);
  color: var(--ink);
  font-weight: 600;
}

.show-more:active {
  background: var(--tab-active);
}

.section-toggle {
  width: calc(100% - 24px);
  min-height: 42px;
  margin: 4px 12px 12px;
  border: 1px solid var(--head-dark);
  border-radius: var(--radius);
  background: var(--head);
  color: #fff;
  font-weight: 700;
  text-align: left;
  padding: 0 12px;
}

.section-toggle::after {
  content: "Показать";
  float: right;
  font-weight: 600;
  opacity: 0.9;
}

.section-toggle.open::after {
  content: "Скрыть";
}

.history-section {
  display: grid;
}

@media (max-width: 720px) {
  .app-shell {
    padding: var(--topbar-h) 8px 72px;
  }

  .workspace {
    min-height: calc(100svh - var(--topbar-h));
  }

  h1 {
    font-size: 18px;
  }

  .file-button {
    min-width: 76px;
    padding: 0 10px;
  }

  .theme-button {
    width: 38px;
    min-width: 38px;
    padding: 0;
  }

  .label-full {
    display: none;
  }

  .label-short {
    display: inline;
  }

  .tabs:not(.hidden) {
    position: fixed;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 8;
    background: var(--line);
    box-shadow: 0 10px 30px rgba(31, 35, 40, 0.2);
  }

  .tabs:not(.hidden) + .content {
    padding-bottom: calc(var(--bottom-nav-h) + 18px + env(safe-area-inset-bottom));
  }

  .tabs:not(.hidden)::before {
    content: "";
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--bottom-nav-h) + 18px + env(safe-area-inset-bottom));
    z-index: -1;
    background: var(--bg);
  }

  .tab {
    min-height: 46px;
    font-size: 14px;
  }

  .details-panel {
    padding: 8px;
  }

  .details-card {
    max-height: 82svh;
  }
}

@media (max-width: 380px) {
  .topbar {
    gap: 8px;
  }

  .topbar-actions {
    gap: 6px;
  }

  h1 {
    font-size: 17px;
  }

  .table-head,
  .table-row {
    grid-template-columns: minmax(0, 1fr) minmax(58px, auto);
  }

  .qty {
    max-width: 86px;
    padding-inline: 5px;
  }

  .details-grid {
    grid-template-columns: 1fr;
  }
}
