:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --text: #17211f;
  --muted: #65716d;
  --line: #d9e1de;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --accent: #b45309;
  --danger: #b42318;
  --ok: #157347;
  --shadow: 0 14px 40px rgba(18, 36, 33, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  background: var(--brand);
  color: #fff;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 700;
}

button.secondary {
  background: #24312e;
}

button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.icon-btn {
  width: 40px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

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

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

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
}

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

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(140deg, rgba(15, 118, 110, 0.18), transparent 38%),
    linear-gradient(330deg, rgba(180, 83, 9, 0.14), transparent 44%),
    var(--bg);
}

.login-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 26px;
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.login-panel p {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.5;
}

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

.form-grid .full {
  grid-column: 1 / -1;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.topbar-inner {
  max-width: 1220px;
  margin: 0 auto;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
}

.user-block {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}

.content {
  max-width: 1220px;
  margin: 0 auto;
  padding: 22px 20px 48px;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 4px 0 18px;
}

.section-head h1 {
  margin: 0;
  font-size: 26px;
}

.section-head p {
  margin: 5px 0 0;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat,
.panel,
.chair-card,
.admin-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(18, 36, 33, 0.04);
}

.stat {
  padding: 16px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

.panel {
  padding: 16px;
}

.panel h2,
.admin-box h3 {
  margin: 0 0 12px;
  font-size: 18px;
}

.range-panel {
  margin-bottom: 16px;
}

.range-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 14px;
  margin-bottom: 14px;
}

.range-head h2 {
  margin-bottom: 4px;
}

.range-head p {
  margin: 0;
  color: var(--muted);
}

.range-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, auto));
  align-items: end;
  gap: 10px;
}

.range-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.mall-group {
  border: 1px solid var(--line);
  border-left: 7px solid var(--mall-color);
  border-radius: 8px;
  padding: 14px;
  margin-top: 16px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--mall-color) 9%, #fff), #fff 42%);
}

.mall-group:first-child {
  margin-top: 0;
}

.mall-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.mall-title h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 17px;
  color: var(--mall-color);
}

.mall-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--mall-color);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--mall-color) 16%, transparent);
}

.mall-title span {
  color: var(--muted);
  font-size: 13px;
}

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

.chair-card {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.chair-main {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.chair-main h4 {
  margin: 0 0 4px;
}

.chair-main small {
  color: var(--muted);
}

.badge {
  align-self: start;
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: var(--surface-2);
  color: var(--brand-dark);
}

.badge.running {
  background: #dcfce7;
  color: var(--ok);
}

.badge.error {
  background: #fee4e2;
  color: var(--danger);
}

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

.mini {
  background: var(--surface-2);
  border-radius: 7px;
  padding: 9px;
}

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

.mini strong {
  font-size: 15px;
}

.log-list {
  display: grid;
  gap: 10px;
  max-height: 680px;
  overflow: auto;
}

.log-row {
  border-left: 4px solid var(--brand);
  background: #fff;
  border-radius: 7px;
  padding: 10px 10px 10px 12px;
}

.log-row.start {
  border-color: var(--ok);
}

.log-row.end {
  border-color: var(--accent);
}

.log-row.error {
  border-color: var(--danger);
}

.log-row strong {
  display: block;
  font-size: 14px;
}

.log-row span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.admin-area {
  margin-top: 18px;
}

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

.management-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 14px;
}

.admin-box {
  padding: 16px;
}

.admin-box form {
  display: grid;
  gap: 12px;
}

.password-form {
  display: grid;
  gap: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.42);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.entry-modal {
  width: min(980px, 100%);
  max-height: min(720px, 86vh);
  overflow: auto;
}

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

.modal-head h3 {
  margin: 0;
}

.modal-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.entry-lines {
  display: grid;
  gap: 10px;
}

.modal-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.modal-tabs button {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.modal-tabs button.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.entry-line {
  display: grid;
  grid-template-columns: 42px 1.1fr 1.4fr 1.4fr;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.entry-no {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--surface-2);
  font-weight: 800;
  color: var(--brand-dark);
}

.entry-line span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

.entry-line strong {
  display: block;
  font-size: 14px;
}

.history-table table {
  min-width: 0;
}

.table-wrap {
  overflow: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-weight: 800;
  background: var(--surface-2);
}

td small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

td input,
td select {
  min-width: 130px;
}

.action-cell {
  display: flex;
  gap: 8px;
  min-width: 160px;
}

.message {
  min-height: 22px;
  color: var(--danger);
  font-size: 14px;
  margin-top: 12px;
}

.empty {
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 7px;
  padding: 14px;
}

@media (max-width: 980px) {
  .stats,
  .range-stats,
  .admin-grid,
  .management-grid,
  .layout,
  .chair-grid,
  .entry-line {
    grid-template-columns: 1fr;
  }

  .range-head {
    align-items: stretch;
    flex-direction: column;
  }

  .range-controls {
    grid-template-columns: 1fr;
  }

  .topbar-inner,
  .section-head {
    align-items: flex-start;
    flex-direction: column;
    justify-content: flex-start;
    padding-top: 12px;
    padding-bottom: 12px;
  }
}

@media (max-width: 560px) {
  .form-grid,
  .chair-meta {
    grid-template-columns: 1fr;
  }

  .content {
    padding-left: 14px;
    padding-right: 14px;
  }
}
