:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
  --page-bg: #f4f7f5;
  --surface-bg: #ffffff;
  --header-bg: #16483e;
  --footer-bg: #e6eeeb;
  --text: #22302d;
  --text-muted: #60706c;
  --border: #ccd8d3;
  --table-row: #ffffff;
  --table-row-hover: #eef5f2;
  --table-header: #e7efec;
  --input-bg: #ffffff;
  --placeholder: #75847f;
  --primary: #176b5b;
  --primary-hover: #115648;
  --secondary: #516b64;
  --link: #0d6555;
  --link-hover: #08483d;
  --link-active: #0a5548;
  --focus: #d99016;
  --success-bg: #dff1e7;
  --success-text: #155c35;
  --warning-bg: #fff2d8;
  --warning-text: #734d0c;
  --warning-border: #d88918;
  --error-bg: #f9e1df;
  --error-text: #8d2925;
  --inactive-bg: #e8ebea;
  --inactive-text: #52615c;
  --button-text: #ffffff;
  --header-text: #ffffff;
  --shadow: #0000000d;
  --backdrop: #07100db3;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --page-bg: #101714;
    --surface-bg: #18211d;
    --header-bg: #0c3029;
    --footer-bg: #131c18;
    --text: #e4ede9;
    --text-muted: #a9b8b2;
    --border: #3b4b45;
    --table-row: #18211d;
    --table-row-hover: #21302a;
    --table-header: #23312b;
    --input-bg: #121a17;
    --placeholder: #899a93;
    --primary: #31a589;
    --primary-hover: #3fbaa0;
    --secondary: #49635c;
    --link: #65d2b5;
    --link-hover: #8ae5ca;
    --link-active: #4ec3a4;
    --focus: #ffc45b;
    --success-bg: #173a2a;
    --success-text: #8ae0ad;
    --warning-bg: #3d3018;
    --warning-text: #ffd38a;
    --warning-border: #d99b35;
    --error-bg: #3c201f;
    --error-text: #ffaaa4;
    --inactive-bg: #2b3531;
    --inactive-text: #c1ccc7;
    --shadow: #00000052;
    --backdrop: #000000bf;
  }
  :root:not([data-theme]) .theme-icon-sun { display: none; }
  :root:not([data-theme]) .theme-icon-moon { display: block; }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page-bg: #101714;
  --surface-bg: #18211d;
  --header-bg: #0c3029;
  --footer-bg: #131c18;
  --text: #e4ede9;
  --text-muted: #a9b8b2;
  --border: #3b4b45;
  --table-row: #18211d;
  --table-row-hover: #21302a;
  --table-header: #23312b;
  --input-bg: #121a17;
  --placeholder: #899a93;
  --primary: #31a589;
  --primary-hover: #3fbaa0;
  --secondary: #49635c;
  --link: #65d2b5;
  --link-hover: #8ae5ca;
  --link-active: #4ec3a4;
  --focus: #ffc45b;
  --success-bg: #173a2a;
  --success-text: #8ae0ad;
  --warning-bg: #3d3018;
  --warning-text: #ffd38a;
  --warning-border: #d99b35;
  --error-bg: #3c201f;
  --error-text: #ffaaa4;
  --inactive-bg: #2b3531;
  --inactive-text: #c1ccc7;
  --shadow: #00000052;
  --backdrop: #000000bf;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  display: flex;
  min-height: 100vh;
  margin: 0;
  flex-direction: column;
  color: var(--text);
  background: var(--page-bg);
}

a:link, a:visited { color: var(--link); }
a:hover { color: var(--link-hover); }
a:active { color: var(--link-active); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

header { color: var(--header-text); background: var(--header-bg); }
.bar, .container { width: 100%; max-width: 1280px; margin: auto; padding: 1.1rem 2rem; }
.bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.header-actions { display: flex; align-items: center; gap: .8rem; }
.brand:link, .brand:visited, .brand:hover, .brand:active {
  color: var(--header-text);
  text-decoration: none;
  font-size: 1.2rem;
  font-weight: 700;
}
.inline { display: inline; margin: 0; }
.link { color: var(--header-text); background: transparent; border: 1px solid #b7d0d4; }
.link:hover { color: var(--header-text); background: #ffffff1a; }

.theme-toggle {
  display: inline-grid;
  width: 2.5rem;
  height: 2.5rem;
  padding: .45rem;
  place-items: center;
  color: var(--header-text);
  background: transparent;
  border: 1px solid #b7d0d4;
  border-radius: 50%;
}
.theme-toggle:hover { background: #ffffff1a; }
.theme-icon { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-icon-moon { display: none; }
:root[data-theme="dark"] .theme-icon-sun { display: none; }
:root[data-theme="dark"] .theme-icon-moon { display: block; }

.container { flex: 1 0 auto; padding-top: 2rem; }
h1 { margin: 0; font-size: 1.8rem; }
h2 { margin-top: 0; font-size: 1.2rem; }
.heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.3rem; }
.muted { color: var(--text-muted); margin: .2rem 0; }

.button, button {
  display: inline-block;
  padding: .65rem 1rem;
  color: var(--button-text);
  background: var(--primary);
  border: 0;
  border-radius: 4px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.button:link, .button:visited, .button:hover, .button:active { color: var(--button-text); }
button:hover, .button:hover { background: var(--primary-hover); }
button:disabled, .button[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.secondary { background: var(--secondary); }
.danger { color: var(--error-text); background: var(--surface-bg); border: 1px solid var(--error-text); }
.danger:hover { color: var(--error-text); background: var(--error-bg); }

.filters { display: flex; gap: .7rem; margin-bottom: 1.25rem; }
.filters input { min-width: 320px; }
input, select {
  padding: .6rem;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
}
input::placeholder { color: var(--placeholder); opacity: 1; }
input[type="checkbox"] { accent-color: var(--primary); }
label { display: flex; flex-direction: column; gap: .35rem; font-weight: 600; }
.check { flex-direction: row; align-items: center; margin-top: 1rem; }
.check input { width: auto; }

.table-wrap, .panel, .login, .empty, dialog {
  color: var(--text);
  background: var(--surface-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 1px 2px var(--shadow);
}
table { width: 100%; border-collapse: collapse; background: var(--table-row); }
th, td { padding: .8rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--table-header); }
tbody tr { background: var(--table-row); }
tbody tr:hover { background: var(--table-row-hover); }
.badge { display: inline-block; padding: .2rem .55rem; border-radius: 1rem; font-size: .85rem; font-weight: 700; }
.badge.active { color: var(--success-text); background: var(--success-bg); }
.badge.inactive { color: var(--inactive-text); background: var(--inactive-bg); }

.panel { padding: 1.3rem; margin-bottom: 1rem; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.program { padding: 1rem; margin: 1rem 0; border: 1px solid var(--border); border-radius: 5px; }
.program-grid { display: grid; grid-template-columns: 120px 1fr 180px 180px; gap: 1rem; }
.program small, label small, .field-error { min-height: 1.2em; color: var(--error-text); }
.actions { display: flex; justify-content: flex-end; align-items: center; gap: 1rem; }

.warning { padding: .7rem; color: var(--warning-text); background: var(--warning-bg); border-left: 4px solid var(--warning-border); }
.flash { padding: .8rem 1rem; margin-bottom: 1rem; border-radius: 4px; }
.flash.success { color: var(--success-text); background: var(--success-bg); }
.flash.error { color: var(--error-text); background: var(--error-bg); }
.flash.warning { color: var(--warning-text); background: var(--warning-bg); }
.login { width: 100%; max-width: 430px; margin: 4vh auto; padding: 2rem; }
.login form { display: grid; gap: 1rem; margin-top: 1.5rem; }
.empty { padding: 3rem; text-align: center; }
.error-page { padding: 5rem 1rem; text-align: center; }
dialog::backdrop { background: var(--backdrop); }

.site-footer {
  flex: 0 0 auto;
  padding: 1.2rem 1rem;
  color: var(--text-muted);
  background: var(--footer-bg);
  text-align: center;
  border-top: 1px solid var(--border);
}
.site-footer p { margin: .5rem 0 0; font-size: .9rem; }
.external-links { display: flex; justify-content: center; flex-wrap: wrap; gap: .5rem 1.2rem; }
.external-links a:link, .external-links a:visited { color: var(--link); }
.external-links a:hover, .external-links a:active { color: var(--link-hover); }

@media (max-width: 850px) {
  .program-grid, .grid { grid-template-columns: 1fr 1fr; }
  .bar, .container { padding-left: 1rem; padding-right: 1rem; }
  .filters { flex-wrap: wrap; }
  .table-wrap { overflow: auto; }
}

@media (max-width: 520px) {
  .bar { align-items: flex-start; }
  .header-actions { flex-wrap: wrap; justify-content: flex-end; }
  .program-grid, .grid { grid-template-columns: 1fr; }
  .filters input { min-width: 0; width: 100%; }
}
