:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --border: #cbd5e1;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-text: #ffffff;
  --hover-bg: #eff6ff;
  --error-bg: #fef2f2;
  --error-border: #dc2626;
  --error-text: #991b1b;
  --ok-bg: #f0fdf4;
  --ok-border: #16a34a;
  --warn-bg: #fffbeb;
  --warn-border: #d97706;
  --burgundy: #881337;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: #334155;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --hover-bg: #1e3a8a;
    --error-bg: #450a0a;
    --error-border: #f87171;
    --error-text: #fecaca;
    --ok-bg: #052e16;
    --ok-border: #4ade80;
    --warn-bg: #451a03;
    --warn-border: #fbbf24;
    --burgundy: #fda4af;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 16px;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 16px 24px;
}

header.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 24px;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

/* Hamburger & Dropdown */
.nav-menu-wrap {
  position: relative;
}

.menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.menu-toggle:hover {
  border-color: var(--accent);
}

.hamburger-icon {
  display: inline-flex;
  flex-direction: column;
  justify-content: space-between;
  width: 20px;
  height: 14px;
}

.hamburger-icon span {
  display: block;
  width: 100%;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

.nav-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: min(360px, calc(100vw - 48px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.14);
  padding: 8px;
  z-index: 100;
  max-height: 75vh;
  overflow-y: auto;
}

.nav-dropdown a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--text);
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.95rem;
}

.nav-dropdown a:hover,
.nav-dropdown a:focus-visible {
  background: var(--hover-bg);
  color: var(--accent);
}

.nav-dropdown-all {
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  border-radius: 6px 6px 0 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

h1 { font-size: 1.5rem; margin: 0 0 12px; line-height: 1.25; }
h2 { font-size: 1.2rem; margin: 20px 0 8px; }
h3 { font-size: 1.05rem; margin: 16px 0 6px; }

.grid-modules {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 600px) {
  .grid-modules { grid-template-columns: 1fr 1fr; }
}

.module-link {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 44px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}

.module-link:hover, .module-link:focus-visible {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: end;
}

@media (min-width: 600px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
}

.field {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
  height: 100%;
}

.full, .field.full { grid-column: 1 / -1; width: 100%; }

label {
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.35;
}

input[type="text"],
input[type="number"],
input[type="date"],
select {
  display: block;
  min-height: 46px;
  height: 46px;
  padding: 10px 14px;
  font-size: 16px;
  line-height: 24px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--surface);
  color: var(--text);
  width: 100%;
  margin: 0;
}

select {
  padding-right: 40px;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px 16px;
  cursor: pointer;
}

input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.checkbox-row {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  min-height: 44px;
  height: auto;
}

.checkbox-row input[type="checkbox"],
.checkbox-row input[type="radio"] {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  margin: 0;
  cursor: pointer;
}

.checkbox-row label {
  cursor: pointer;
}

/* Custom Datepicker */
.dp-wrap {
  position: relative;
  width: 100%;
}

.dp-input {
  padding-right: 46px !important;
  cursor: pointer;
}

.dp-trigger {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 38px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.dp-trigger:hover {
  color: var(--accent);
  background: var(--hover-bg);
}

.dp-popup {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  width: 340px;
  max-width: calc(100vw - 48px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
  padding: 16px;
  z-index: 120;
}

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

.dp-nav-btn {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.dp-nav-btn:hover {
  border-color: var(--accent);
  background: var(--hover-bg);
}

.dp-title {
  font-weight: 700;
  font-size: 1rem;
  text-align: center;
  flex: 1;
}

.dp-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 8px;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.dp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.dp-day {
  min-width: 38px;
  min-height: 40px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.dp-day:hover {
  background: var(--hover-bg);
  border-color: var(--accent);
}

.dp-day.is-selected {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}

.dp-day.is-today {
  border-color: var(--accent);
}

button.btn-primary {
  min-height: 46px;
  padding: 10px 22px;
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

button.btn-primary:hover { background: var(--accent-hover); }
button.btn-primary[aria-busy="true"] { opacity: 0.7; cursor: wait; }

.alert {
  padding: 14px 16px;
  border-radius: var(--radius);
  border-left: 4px solid;
  margin-bottom: 16px;
}

.alert-error {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error-text);
}

.alert-result {
  background: var(--ok-bg);
  border-color: var(--ok-border);
}

.alert-warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
}

.result-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.result-row:last-child { border-bottom: none; }
.result-val { font-weight: 700; text-align: right; }

.muted { color: var(--muted); font-size: 0.9rem; }

.faq-item { margin-bottom: 14px; }
.faq-item summary {
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.related-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.related-links a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--accent);
  text-decoration: none;
}

footer.site-footer {
  margin-top: 32px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}

.field-hint {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.result-hero {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 2px solid var(--ok-border);
  font-size: 1.25rem;
  font-weight: 700;
}

.result-hero-val {
  font-size: 1.5rem;
  font-weight: 800;
  text-align: right;
}

.result-hero-block {
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 2px solid var(--ok-border);
}

.result-hero-block .result-hero {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 6px;
}

.result-sub-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.92rem;
  color: var(--muted);
  padding: 2px 0;
}

.limit-highlight {
  color: var(--burgundy);
}
