:root {
  --pink: #b75675;
  --pink-soft: #ecd2db;
  --pink-mid: #c99fab;
  --sand: #e7e0da;
  --cream: #f7f2ee;
  --ink: #2a2426;
  --muted: #6b5e62;
  --line: #e2d5d8;
  --ok: #2f7a4a;
  --warn: #b06a12;
  --danger: #b33a4a;
  --sidebar: #2f2629;
  --sidebar-text: #f3e9ec;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(42, 36, 38, 0.08);
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 22px;
  --space-6: 28px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #f3dfe6 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #efe6df 0%, transparent 45%),
    var(--cream);
}

.hidden { display: none !important; }
.brand {
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--pink);
}
.muted { color: var(--muted); font-size: 0.92rem; }

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-5);
}
.auth-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: var(--space-6);
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 8px 0 12px; font-size: 1.5rem; }

.shell {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: linear-gradient(180deg, #352b2f, var(--sidebar));
  color: var(--sidebar-text);
  padding: var(--space-5) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.sidebar-brand {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3) var(--space-4);
}
.sidebar-brand .brand { color: #f7dce5; font-size: 1.55rem; }
.sidebar-sub { opacity: 0.65; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item, .nav-logout, .nav-site {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  display: block;
}
.nav-item:hover, .nav-logout:hover, .nav-site:hover { background: rgba(255,255,255,0.08); }
.nav-item.active { background: rgba(183, 86, 117, 0.45); }
.nav-section {
  margin: 14px 12px 4px;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.5;
}
.nav-logout { margin-top: auto; color: #f0b8c5; }
.nav-site { color: #d8c4ca; font-size: 0.9rem; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.72);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.page-title { margin: 0; font-family: var(--display); font-size: 1.35rem; flex: 1; }
.topbar-user { font-size: 0.88rem; color: var(--muted); }
.icon-btn {
  display: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  width: 40px;
  height: 40px;
  cursor: pointer;
}
.content { padding: var(--space-5); }

.grid-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}
.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 0.82rem; }
.stat .value { font-family: var(--display); font-size: 1.6rem; margin-top: 4px; }

.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-5);
  box-shadow: var(--shadow);
  margin-bottom: var(--space-5);
}
.panel h2 { margin: 0 0 var(--space-3); font-size: 1.1rem; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  margin-bottom: var(--space-4);
}
.toolbar .spacer { flex: 1; min-width: 8px; }

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 9px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary { background: var(--pink); color: #fff; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-danger { background: #fff; border-color: #efc1c8; color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 0.86rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

input[type="text"], input[type="number"], input[type="email"], input[type="url"],
input[type="date"], input[type="time"], input[type="color"], input[type="search"],
select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
label.field { display: grid; gap: 6px; font-size: 0.88rem; color: var(--muted); }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
}
.check-row { display: flex; align-items: center; gap: 8px; color: var(--ink); }

.table-wrap { overflow: auto; -webkit-overflow-scrolling: touch; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
table.data th, table.data td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
table.data tr:hover td { background: #faf6f7; }
.thumb {
  width: 48px; height: 48px; object-fit: cover; border-radius: 8px; background: var(--sand);
}
.home-card-preview {
  width: 100%;
  max-height: 220px;
  min-height: 140px;
  object-fit: cover;
  border-radius: 12px;
  display: block;
  background: var(--sand);
}
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--pink-soft);
  color: #7a3550;
}
.badge-ok { background: #d9f0e2; color: var(--ok); }
.badge-warn { background: #f7e5c8; color: var(--warn); }
.badge-off { background: #eee; color: #666; }

.swatch {
  width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--line); display: inline-block;
}
[data-color-preview] {
  width: 48px; height: 48px; border-radius: 10px; border: 1px solid var(--line);
  flex-shrink: 0;
}

.toast-host {
  position: fixed; right: 16px; bottom: 16px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: #2a2426; color: #fff; padding: 12px 16px; border-radius: 12px;
  box-shadow: var(--shadow); max-width: 340px; animation: rise 0.25s ease;
}
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(42,36,38,0.45); z-index: 200;
  display: grid; place-items: center; padding: 16px;
}
.modal {
  width: min(720px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border-radius: 16px;
  padding: 0;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 0;
}
.modal-header h3 { margin: 0; font-family: var(--display); font-size: 1.25rem; }
.modal-x {
  border: 0;
  background: transparent;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  width: 36px;
  height: 36px;
  border-radius: 8px;
}
.modal-x:hover { background: var(--sand); color: var(--ink); }
.modal-body { padding: 16px 20px; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 0 20px 18px;
  margin-top: 4px;
}

.color-checks { display: flex; flex-wrap: wrap; gap: 8px; }
.color-check {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border: 2px solid transparent; border-radius: 10px; cursor: pointer;
}
.color-check:has(input:checked) { border-color: var(--pink); }

#zonesMap {
  height: min(520px, 60vh);
  border-radius: 12px;
  border: 1px solid var(--line);
  margin: var(--space-3) 0;
}

.cal-nav {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.cal-nav h3 { margin: 0; flex: 1; text-align: center; font-family: var(--display); font-size: 1.15rem; }
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 6px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}
.cal-day {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 6px;
  text-align: center;
  cursor: pointer;
  background: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  min-height: 44px;
}
.cal-day.on {
  background: #d9f0e2;
  border-color: var(--ok);
  color: #1d5c36;
}
.cal-day.off {
  background: #f8e0e3;
  border-color: #e8a0ad;
  color: var(--danger);
}
.cal-day.past {
  opacity: 0.45;
  cursor: not-allowed;
  background: #ececec;
  border-color: #d0d0d0;
  color: #6b6b6b;
}
.cal-day.forced {
  background: #fff3d6;
  border-color: #e0a100;
  color: #8a5a00;
}
.cal-day.selected {
  outline: 2px solid var(--accent, #2f6fed);
  outline-offset: 1px;
}
.cal-day.cal-empty { visibility: hidden; pointer-events: none; }

.date-drawer {
  position: fixed;
  inset: 0;
  z-index: 80;
  pointer-events: none;
  visibility: hidden;
}
.date-drawer.open {
  pointer-events: auto;
  visibility: visible;
}
.date-drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 24, 32, 0.35);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.date-drawer.open .date-drawer-backdrop { opacity: 1; }
.date-drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 92vw);
  background: var(--panel, #fff);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 28px rgba(0, 0, 0, 0.08);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transform: translateX(105%);
  transition: transform 0.22s ease;
  overflow: auto;
}
.date-drawer.open .date-drawer-panel { transform: none; }
.date-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.date-drawer-slots {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.date-drawer-actions {
  margin-top: auto;
  flex-wrap: wrap;
}

.empty { padding: 28px; text-align: center; color: var(--muted); }

@media (max-width: 1024px) {
  .content { padding: var(--space-4); }
  .panel { padding: var(--space-4); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: none; }
  .icon-btn { display: inline-flex; align-items: center; justify-content: center; }
  .content { padding: 14px; }
  #zonesMap { height: 360px; }
  .cal-day { padding: 10px 4px; font-size: 0.82rem; min-height: 40px; }
}
@media (max-width: 768px) {
  .date-drawer-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: min(78vh, 560px);
    border-left: none;
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.1);
    transform: translateY(105%);
  }
  .date-drawer.open .date-drawer-panel { transform: none; }
}
@media (max-width: 390px) {
  .page-title { font-size: 1.1rem; }
  .btn { padding: 8px 12px; font-size: 0.88rem; }
  .stat .value { font-size: 1.3rem; }
}
