:root {
  --bg0: #071018;
  --bg1: #0c1a24;
  --panel: rgba(16, 32, 44, 0.92);
  --panel-solid: #122433;
  --border: rgba(120, 180, 200, 0.16);
  --text: #eef7fb;
  --muted: #8aa3b3;
  --accent: #22d3c5;
  --accent-2: #38bdf8;
  --accent-ink: #04201e;
  --danger: #fb7185;
  --ok: #34d399;
  --warn: #fbbf24;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --sidebar: 260px;
  --font: "Manrope", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 480px at 8% -8%, rgba(34, 211, 197, 0.18), transparent 55%),
    radial-gradient(700px 420px at 100% 0%, rgba(56, 189, 248, 0.14), transparent 50%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
  min-height: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-2); }
.hidden { display: none !important; }

#root { min-height: 100%; }

/* ——— Login ——— */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
.brand-mark .logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  color: var(--accent-ink);
  font-weight: 800;
  letter-spacing: -0.04em;
}
.brand-mark strong { font-size: 1.15rem; letter-spacing: -0.02em; }
.login-card h1 {
  margin: 0 0 8px;
  font-size: 1.65rem;
  letter-spacing: -0.03em;
  line-height: 1.2;
}
.login-card .lead {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.45;
}
.field { margin-bottom: 14px; }
.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}
.field input, .field select, .field textarea,
.input, .select, .textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(7, 16, 24, 0.65);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus,
.input:focus, .select:focus, .textarea:focus {
  border-color: rgba(34, 211, 197, 0.55);
  box-shadow: 0 0 0 3px rgba(34, 211, 197, 0.12);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #14b8a6);
  color: var(--accent-ink);
  transition: transform .12s, filter .12s, opacity .12s;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-danger {
  background: linear-gradient(135deg, #fb7185, #e11d48);
  color: #fff;
}
.btn-sm { padding: 8px 12px; font-size: 0.9rem; border-radius: 10px; }
.error {
  color: #fecaca;
  background: rgba(251, 113, 133, 0.12);
  border: 1px solid rgba(251, 113, 133, 0.28);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0 0 12px;
  font-size: 0.9rem;
  min-height: 0;
}
.error:empty { display: none; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 10px; }

/* ——— Shell ——— */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
}
.sidebar {
  border-right: 1px solid var(--border);
  background: rgba(8, 18, 26, 0.78);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 18px;
}
.sidebar .brand .logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  color: var(--accent-ink); font-weight: 800;
}
.nav-btn {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 11px 12px;
  border-radius: 12px;
  font-weight: 600;
}
.nav-btn:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-btn.active {
  background: rgba(34, 211, 197, 0.14);
  color: var(--accent);
}
.sidebar-foot {
  margin-top: auto;
  padding: 12px 8px 4px;
  border-top: 1px solid var(--border);
}
.sidebar-foot .phone { color: var(--muted); font-size: 0.85rem; margin-bottom: 10px; word-break: break-all; }

.main {
  min-width: 0;
  padding: 22px 24px 40px;
}
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.topbar h1 {
  margin: 0;
  font-size: 1.55rem;
  letter-spacing: -0.03em;
}
.topbar .sub { color: var(--muted); margin-top: 4px; font-size: 0.92rem; }
.pvz-select {
  min-width: 220px;
  max-width: 360px;
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat-card .label { color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.stat-card .value {
  margin-top: 8px;
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.panel h2 {
  margin: 0 0 14px;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}
.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.panel-head h2 { margin: 0; }

.table-wrap { overflow: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
table.data th, table.data td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data th {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
table.data tr:hover td { background: rgba(255,255,255,0.02); }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  background: rgba(255,255,255,0.06);
  color: var(--muted);
}
.badge.ok { background: rgba(52, 211, 153, 0.15); color: var(--ok); }
.badge.warn { background: rgba(251, 191, 36, 0.15); color: var(--warn); }
.badge.danger { background: rgba(251, 113, 133, 0.15); color: var(--danger); }

.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.empty {
  color: var(--muted);
  padding: 24px 8px;
  text-align: center;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.form-grid .full { grid-column: 1 / -1; }
.checks {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(7, 16, 24, 0.4);
  font-size: 0.9rem;
}
.check input { accent-color: var(--accent); }

/* Calendar */
.cal-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}
.cal-dow {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px;
}
.cal-day {
  min-height: 92px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  background: rgba(7, 16, 24, 0.35);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.cal-day:hover { border-color: rgba(34, 211, 197, 0.45); }
.cal-day.muted { opacity: 0.35; cursor: default; }
.cal-day.selected {
  border-color: var(--accent);
  background: rgba(34, 211, 197, 0.1);
}
.cal-day .num { font-weight: 800; font-size: 0.95rem; margin-bottom: 6px; }
.cal-chip {
  display: block;
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 6px;
  margin-bottom: 3px;
  background: rgba(56, 189, 248, 0.18);
  color: #bae6fd;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat {
  display: grid;
  grid-template-rows: 1fr auto;
  height: min(70vh, 640px);
  gap: 12px;
}
.chat-log {
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px;
}
.bubble {
  max-width: min(70%, 520px);
  padding: 10px 12px;
  border-radius: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble.me {
  align-self: flex-end;
  background: rgba(34, 211, 197, 0.18);
  border: 1px solid rgba(34, 211, 197, 0.28);
}
.bubble.them {
  align-self: flex-start;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
}
.bubble .meta {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.75rem;
}
.chat-compose {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}
.chat-compose textarea { min-height: 64px; resize: vertical; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  width: min(560px, 100%);
  max-height: min(90vh, 800px);
  overflow: auto;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 14px; font-size: 1.15rem; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  max-width: 360px;
}
.toast.error { border-color: rgba(251, 113, 133, 0.45); }
.toast.ok { border-color: rgba(52, 211, 153, 0.45); }

.mobile-bar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(8, 18, 26, 0.92);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  backdrop-filter: blur(8px);
}

@media (max-width: 1100px) {
  .grid-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cal-day { min-height: 78px; }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(280px, 86vw);
    z-index: 40;
    transform: translateX(-105%);
    transition: transform .18s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-bar { display: flex; align-items: center; justify-content: space-between; }
  .main { padding: 16px; }
  .form-grid, .checks { grid-template-columns: 1fr; }
  .grid-cards { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .grid-cards { grid-template-columns: 1fr; }
  .cal-grid { gap: 4px; }
  .cal-day { min-height: 64px; padding: 5px; }
  .cal-chip { font-size: 0.65rem; }
}
