:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #151b24;
  --muted: #738095;
  --line: #e7eaef;
  --primary: #16a34a;
  --primary-dark: #12813d;
  --danger: #dc2626;
  --danger-soft: #fff1f2;
  --shadow: 0 8px 30px rgba(30, 41, 59, .06);
}

* { box-sizing: border-box; }
.login-overlay { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(15,23,42,.58); backdrop-filter: blur(10px); }
.login-overlay.hidden { display: none; }
.login-card { width: min(390px, 100%); border: 1px solid var(--line); border-radius: 18px; padding: 28px; background: var(--surface); box-shadow: 0 24px 70px rgba(15,23,42,.25); }
.login-brand { width: 52px; height: 52px; margin-bottom: 18px; display: grid; place-items: center; border-radius: 15px; background: var(--primary); color: white; font-size: 28px; font-weight: 900; }
.login-card h2 { margin: 4px 0 22px; }
.login-card .field { margin-bottom: 14px; }
.login-error { min-height: 18px; margin: 2px 0 10px; color: var(--danger); font-size: 12px; font-weight: 800; }
.login-button { width: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}
body.dark {
  --bg: #10141b;
  --surface: #171c24;
  --surface-2: #1d232d;
  --text: #edf2f7;
  --muted: #9aa5b5;
  --line: #2b3440;
  --danger-soft: #352126;
  --shadow: 0 8px 30px rgba(0, 0, 0, .18);
}
.app-shell { width: min(920px, calc(100% - 32px)); margin: 0 auto; padding: 32px 0 24px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.topbar-actions { display: flex; align-items: center; gap: 7px; }
.user-chip { max-width: 160px; overflow: hidden; text-overflow: ellipsis; border-radius: 99px; padding: 7px 10px; background: rgba(22,163,74,.09); color: var(--primary); font-size: 12px; font-weight: 900; white-space: nowrap; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; color: white; background: var(--primary); font-size: 24px; font-weight: 800; box-shadow: 0 8px 18px rgba(22,163,74,.2); }
.brand h1 { margin: 2px 0 0; font-size: 22px; letter-spacing: -.35px; }
.eyebrow { margin: 0; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1.1px; font-weight: 800; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--muted); cursor: pointer; font-size: 18px; }
.control-card, .checklist { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.control-card { padding: 18px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.field input { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; background: var(--surface-2); color: var(--text); font: inherit; outline: none; }
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22,163,74,.08); }
.period-row { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-top: 16px; }
.segmented { display: flex; padding: 4px; width: 220px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--line); }
.segment { flex: 1; height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-weight: 800; cursor: pointer; }
.segment.active { background: var(--surface); color: var(--primary); box-shadow: 0 2px 8px rgba(30,41,59,.08); }
.progress-wrap { width: 280px; }
.progress-label { display: flex; justify-content: space-between; margin-bottom: 7px; color: var(--muted); font-size: 12px; }
.progress-label strong { color: var(--text); }
.progress-track { height: 7px; overflow: hidden; border-radius: 99px; background: var(--line); }
.progress-bar { height: 100%; width: 0; border-radius: 99px; background: var(--primary); transition: width .25s ease; }
.toolbar { display: flex; justify-content: space-between; gap: 12px; margin: 16px 0 12px; }
.search-box { flex: 1; max-width: 360px; height: 42px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; background: var(--surface); color: var(--muted); }
.search-box input { border: 0; outline: 0; width: 100%; color: var(--text); background: transparent; font: inherit; }
.secondary-button { height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 0 15px; background: var(--surface); color: var(--text); font-weight: 800; cursor: pointer; }
.secondary-button:hover { border-color: var(--muted); }
.checklist { overflow: hidden; }
.site-row { display: grid; grid-template-columns: minmax(0, 1fr) 146px; align-items: center; gap: 12px; min-height: 62px; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--line); }
.site-row:last-child { border-bottom: 0; }
.site-main { min-width: 0; }
.site-link { display: block; overflow: hidden; color: var(--text); text-decoration: none; font-size: 13px; font-weight: 750; white-space: nowrap; text-overflow: ellipsis; }
.site-link:hover { color: var(--primary); }
.site-domain { margin-top: 3px; color: var(--muted); font-size: 11px; }
.status-actions { display: grid; grid-template-columns: 68px 68px; gap: 5px; }
.status-button { height: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 800; cursor: pointer; }
.status-button.ok.active { border-color: #86efac; background: #ecfdf3; color: #15803d; }
.status-button.error.active { border-color: #fecaca; background: var(--danger-soft); color: var(--danger); }
.note-input { grid-column: 1 / -1; width: 100%; height: 38px; margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; background: var(--surface-2); color: var(--text); font: inherit; font-size: 12px; outline: none; }
.site-row.has-error { background: color-mix(in srgb, var(--danger-soft) 45%, var(--surface)); }
.bottom-actions { position: sticky; bottom: 12px; display: grid; grid-template-columns: 1fr 140px; gap: 10px; margin-top: 14px; }
.primary-button { height: 48px; border: 0; border-radius: 12px; background: var(--primary); color: white; font-weight: 850; cursor: pointer; box-shadow: 0 10px 24px rgba(22,163,74,.18); }
.primary-button:hover { background: var(--primary-dark); }
.primary-button span { margin-right: 6px; }
.wide { height: 48px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; border-radius: 10px; padding: 12px 16px; background: #171c24; color: white; font-size: 13px; font-weight: 700; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.empty-state { padding: 28px; text-align: center; color: var(--muted); }

.history-button { white-space: nowrap; }
.edit-history-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; border: 1px solid rgba(22,163,74,.25); border-radius: 12px; padding: 12px 14px; background: rgba(22,163,74,.08); }
.edit-history-banner[hidden] { display: none; }
.edit-history-banner > div { display: grid; gap: 2px; }
.edit-history-label { color: var(--primary); font-size: 11px; font-weight: 900; text-transform: uppercase; }
.edit-history-banner strong { font-size: 13px; }
.edit-history-banner button { height: 38px; flex-shrink: 0; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; background: var(--surface); color: var(--text); font-weight: 800; cursor: pointer; }
.history-panel[hidden] { display: none; }
.history-panel { margin-bottom: 12px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.history-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px; border-bottom: 1px solid var(--line); }
.history-header h2 { margin: 2px 0 0; font-size: 17px; }
.history-tools { display: flex; align-items: center; gap: 8px; }
.month-picker { height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; background: var(--surface-2); color: var(--text); }
.history-cycle { display: block; margin-top: 5px; color: var(--primary); font-size: 12px; font-weight: 800; }
.history-export-button { height: 42px; border: 0; border-radius: 10px; padding: 0 12px; background: var(--primary); color: white; font-size: 12px; font-weight: 850; white-space: nowrap; cursor: pointer; }
.history-export-button:hover { background: var(--primary-dark); }
.close-history { width: 42px; font-size: 22px; }
.history-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 12px 16px; }
.summary-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface-2); }
.summary-card span { display: block; color: var(--muted); font-size: 11px; }
.summary-card strong { display: block; margin-top: 3px; font-size: 20px; }
.history-list { border-top: 1px solid var(--line); }
.history-item { display: grid; grid-template-columns: 118px 100px minmax(120px, 1fr) auto; align-items: center; gap: 10px; min-height: 58px; padding: 9px 16px; border-bottom: 1px solid var(--line); }
.history-item:last-child { border-bottom: 0; }
.history-date { font-size: 13px; font-weight: 800; }
.period-badge { width: fit-content; border-radius: 99px; padding: 5px 9px; background: var(--surface-2); color: var(--primary); font-size: 11px; font-weight: 900; text-transform: uppercase; }
.history-counts { color: var(--muted); font-size: 12px; }
.history-open { height: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 12px; font-weight: 800; cursor: pointer; }
.history-empty { padding: 30px 16px; text-align: center; color: var(--muted); }

@media (max-width: 680px) {
  .app-shell { width: min(100% - 20px, 920px); padding: 14px 0 calc(84px + env(safe-area-inset-bottom)); }
  .topbar { margin-bottom: 14px; }
  .brand-mark { width: 40px; height: 40px; border-radius: 12px; }
  .brand h1 { font-size: 18px; }
  .field-row { grid-template-columns: 1fr; }
  .control-card { padding: 14px; }
  .period-row { align-items: stretch; flex-direction: column; gap: 14px; }
  .segmented { width: 100%; }
  .progress-wrap { width: 100%; }
  .toolbar { align-items: center; }
  .search-box { min-width: 0; }
  .toolbar .secondary-button { padding: 0 10px; }
  .edit-history-banner { align-items: stretch; flex-direction: column; }
  .edit-history-banner button { width: 100%; }
  .history-header { align-items: flex-start; flex-direction: column; }
  .history-tools { width: 100%; flex-wrap: wrap; }
  .month-picker { flex: 1; min-width: 140px; }
  .history-export-button { flex: 1; min-width: 150px; }
  .history-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 10px; gap: 6px; }
  .summary-card { padding: 9px; }
  .summary-card strong { font-size: 16px; }
  .history-item { grid-template-columns: 1fr auto; gap: 6px; padding: 10px 12px; }
  .history-counts { grid-column: 1 / 2; }
  .history-open { grid-column: 2; grid-row: 1 / 3; }
  .period-badge { position: absolute; margin-left: 92px; margin-top: -28px; }
  .site-row { grid-template-columns: 1fr; padding: 10px 12px; }
  .status-actions { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .status-button { width: 100%; }
  .bottom-actions { position: fixed; z-index: 20; left: 10px; right: 10px; bottom: 10px; margin: 0; grid-template-columns: 1fr 118px; }
  .primary-button { height: 52px; }
  .wide { height: 52px; }
}

@media (max-width: 380px) {
  .brand .eyebrow { display: none; }
  .user-chip { display: none; }
  .toolbar { flex-wrap: wrap; }
  .search-box { flex-basis: 100%; max-width: none; }
  .history-button, #resetButton { flex: 1; }
  .bottom-actions { grid-template-columns: 1fr 100px; }
}

@media (min-width: 681px) and (max-height: 700px) {
  .bottom-actions { position: static; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
