:root {
  color-scheme: dark;
}

html[data-theme="light"] {
  color-scheme: light;
  --primary: #087f8c;
  --primary-strong: #076d78;
  --secondary: #2563a6;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface2: #edf1f4;
  --surface3: #e2e7eb;
  --text: #1d252c;
  --text-dim: #5f6b75;
  --accent: #9a6700;
  --danger: #b42318;
  --warning: #9a6700;
  --success: #237a3f;
  --glass: rgba(255, 255, 255, 0.92);
  --card-border: rgba(31, 41, 51, 0.18);
  --border: #cbd5dc;
  --green: #168a45;
  --green-dim: #e4f5e9;
  --green-mid: #11763a;
  --sent: #dcfce7;
  --skip: #fff3e0;
  --skip-text: #9a4d00;
}

.theme-control {
  position: relative;
  display: flex;
  min-height: 38px;
  margin-top: 4px;
  padding: 9px 10px 5px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-top: 1px solid var(--card-border, var(--border));
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.82rem;
}

.theme-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.theme-switch {
  position: relative;
  width: 34px;
  height: 20px;
  flex: 0 0 auto;
  background: var(--surface3, var(--surface));
  border: 1px solid var(--card-border, var(--border));
  border-radius: 10px;
  transition: background 0.2s, border-color 0.2s;
}

.theme-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: left 0.2s, background 0.2s;
}

.theme-control input:checked + .theme-switch {
  background: var(--primary);
  border-color: var(--primary);
}

.theme-control input:checked + .theme-switch::after {
  left: 17px;
  background: #ffffff;
}

.theme-control input:focus-visible + .theme-switch {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.theme-icon-button {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 500;
  display: inline-flex;
  width: 38px;
  height: 38px;
  padding: 0;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--card-border, var(--border));
  border-radius: 7px;
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14);
}

.theme-icon-button:hover,
.theme-icon-button:focus-visible {
  border-color: var(--primary, var(--green));
  outline: none;
}

html[data-theme="light"] body {
  background-color: var(--bg);
  background-image: none;
  color: var(--text);
}

html[data-theme="light"] header,
html[data-theme="light"] .operation-footer {
  background: rgba(255, 255, 255, 0.97);
}

html[data-theme="light"] .page-nav {
  box-shadow: 0 10px 28px rgba(31, 41, 51, 0.16);
}

html[data-theme="light"] .page-nav a:hover,
html[data-theme="light"] .btn-outline:hover,
html[data-theme="light"] .hamburger-icon:hover {
  background: rgba(8, 127, 140, 0.08);
}

html[data-theme="light"] input,
html[data-theme="light"] select,
html[data-theme="light"] textarea {
  background: var(--surface2);
  border-color: var(--card-border, var(--border));
  color: var(--text);
}

html[data-theme="light"] input::placeholder,
html[data-theme="light"] textarea::placeholder {
  color: #7a858e;
}

html[data-theme="light"] .card,
html[data-theme="light"] section,
html[data-theme="light"] .step,
html[data-theme="light"] .entry-panel,
html[data-theme="light"] .table-container,
html[data-theme="light"] .toolbar {
  box-shadow: 0 1px 3px rgba(31, 41, 51, 0.07);
}

html[data-theme="light"] .stat-item,
html[data-theme="light"] .chart-placeholder,
html[data-theme="light"] .point-preview-item {
  background: rgba(31, 41, 51, 0.04);
}

html[data-theme="light"] .point-preview-list,
html[data-theme="light"] .sync-status,
html[data-theme="light"] .db-stats {
  background: var(--surface2);
}

html[data-theme="light"] th {
  background: var(--surface2);
  color: var(--text-dim);
}

html[data-theme="light"] td,
html[data-theme="light"] .preview-table td {
  border-color: var(--card-border, var(--border));
}

html[data-theme="light"] tr:hover,
html[data-theme="light"] tbody tr:hover {
  background: rgba(8, 127, 140, 0.045);
}

html[data-theme="light"] tbody tr.done {
  background: rgba(35, 122, 63, 0.06);
}

html[data-theme="light"] tbody tr.selected {
  background: rgba(8, 127, 140, 0.09);
}

html[data-theme="light"] .table-input {
  background: #ffffff;
}

html[data-theme="light"] code {
  background: rgba(31, 41, 51, 0.08);
}

html[data-theme="light"] #btnBackup {
  background: var(--surface2) !important;
}

html[data-theme="light"] .card > div[style*="background: rgba(0,0,0"] {
  background: var(--surface2) !important;
}

html[data-theme="light"] .spinner {
  border-color: rgba(31, 41, 51, 0.13);
  border-top-color: var(--primary);
}

html[data-theme="light"] .status-sent {
  color: #166534;
}

html[data-theme="light"] .preview-table td {
  border-bottom-color: var(--border);
}

@media (max-width: 760px) {
  .theme-icon-button {
    top: 12px;
    right: 12px;
  }
}
