:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --ink: #102a43;
  --muted: #60748a;
  --line: #d6dee8;
  --brand: #155e75;
  --brand-dark: #0f4b5d;
  --success: #16794c;
  --danger: #b42318;
  --warning: #b7791f;
  font-family: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel,
.main-view {
  width: min(1120px, 100%);
  margin: 0 auto;
}

.login-panel {
  display: grid;
  gap: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 42px rgba(15, 42, 61, 0.12);
}

.main-view {
  padding: 20px;
}

.topbar,
.section-header,
.actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 20px;
}

.brand-title {
  min-width: 0;
}

.brand-title h1 {
  white-space: nowrap;
}

.eyebrow {
  color: var(--brand);
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 4px;
  text-transform: uppercase;
  font-size: 0.82rem;
}

h1,
h2 {
  margin: 0;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  padding: 10px 12px;
}

.setup-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 18px;
  overflow: hidden;
}

.setup-section.is-hidden-during-run {
  display: none;
}

.setup-toggle {
  width: 100%;
  min-height: 54px;
  border: 0;
  background: #fff;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 900;
}

.setup-toggle:hover {
  background: #f9fbfd;
}

#setupToggleText {
  color: var(--brand);
  font-size: 0.92rem;
}

.setup-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr 0.8fr 0.8fr 1.2fr;
  gap: 14px;
  border-top: 1px solid var(--line);
  padding: 16px;
}

.setup-grid.is-collapsed {
  display: none;
}

.counter-board {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 22px;
}

.timer-card,
.formula-card {
  display: grid;
  gap: 8px;
  align-content: center;
  min-height: 148px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #f9fbfd;
}

.formula-card {
  grid-column: 1 / -1;
  min-height: 0;
  padding: 10px 14px;
}

.timer-card strong {
  font-size: 4.5rem;
  line-height: 1;
}

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

.timer-label,
.formula-card span,
.metrics-grid span {
  color: var(--muted);
  font-weight: 700;
}

.formula-card strong {
  font-size: 1.45rem;
  line-height: 1.15;
}

.count-button {
  min-height: 154px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-size: clamp(2rem, 7vw, 4.3rem);
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.success-button {
  background: var(--success);
}

.fault-button {
  background: var(--danger);
}

button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.primary-button,
.secondary-button,
.small-button,
.secondary-link {
  min-height: 44px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 10px 16px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary-button {
  background: var(--brand);
  color: #fff;
}

.primary-button:hover {
  background: var(--brand-dark);
}

.secondary-button,
.small-button,
.secondary-link {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.small-button {
  min-height: 36px;
  padding: 7px 10px;
}

.metrics-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.metrics-grid div {
  display: grid;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.metrics-grid strong {
  font-size: 1.45rem;
}

.counter-board > .actions-row,
.counter-board > .message {
  grid-column: 1 / -1;
}

.message {
  min-height: 24px;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.message.error {
  color: var(--danger);
}

.message.ok {
  color: var(--success);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
  flex-shrink: 0;
}

.icon-status,
.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 6px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

.icon-button {
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.icon-status svg,
.icon-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-status {
  background: #fee2e2;
  color: #991b1b;
}

.icon-status.online {
  background: #dcfce7;
  color: #166534;
}

.icon-status.sync-ok {
  background: #dcfce7;
  color: #166534;
}

.icon-status.sync-waiting {
  background: #fef3c7;
  color: #92400e;
}

.icon-status.sync-error {
  background: #fee2e2;
  color: #991b1b;
}

.results-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.compact {
  justify-content: flex-end;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 840px;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.88rem;
}

.pending {
  color: var(--warning);
  font-weight: 800;
}

.synced {
  color: var(--success);
  font-weight: 800;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 42, 61, 0.58);
}

.modal-panel {
  position: relative;
  width: min(980px, 100%);
  max-height: min(92vh, 980px);
  overflow: auto;
  background: var(--panel);
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(15, 42, 61, 0.28);
  padding: 18px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.help-rule,
.help-formula {
  margin: 0 0 12px;
  color: var(--ink);
  font-weight: 700;
}

.help-formula {
  margin: 12px 0 0;
  color: var(--muted);
}

.plan-frame {
  position: relative;
  width: min(100%, 760px);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.plan-frame img {
  display: block;
  width: 100%;
  height: auto;
}

.help-marker {
  position: absolute;
  border: 4px solid #d7263d;
  background: rgba(215, 38, 61, 0.18);
  border-radius: 999px;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 9999px rgba(21, 94, 117, 0.08);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 6px;
  pointer-events: none;
}

.help-marker span {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(215, 38, 61, 0.35);
  border-radius: 999px;
  color: #9f1239;
  font-size: 0.85rem;
  font-weight: 900;
  line-height: 1.1;
  padding: 5px 8px;
}

@media (max-width: 820px) {
  .main-view {
    padding: 12px;
  }

  .topbar,
  .section-header,
  .actions-row {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    align-items: center;
    flex-direction: row;
  }

  .brand-title h1 {
    font-size: clamp(1.45rem, 6vw, 2rem);
  }

  .header-actions {
    justify-content: flex-end;
  }

  .icon-status,
  .icon-button {
    width: 38px;
    height: 38px;
  }

  .setup-grid,
  .counter-board {
    grid-template-columns: 1fr;
  }

  .metrics-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .timer-card strong {
    font-size: 4rem;
  }

  .formula-card strong {
    font-size: 1.35rem;
  }

  .count-button {
    min-height: 132px;
  }

  .modal {
    padding: 8px;
  }

  .modal-panel {
    max-height: 95vh;
    padding: 12px;
  }

  .help-marker span {
    font-size: 0.72rem;
  }
}
