/* scrap3r UI. Existing class names (panel, stat, pill, btn, flash ...) are kept
   so every page picks up the new look without markup changes. */

:root {
  --bg: #f4f5f9;
  --panel: #ffffff;
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-2: #eef0f4;
  --brand: #4f46e5;
  --brand-2: #4338ca;
  --brand-soft: #eef2ff;
  --ok: #047857;   --ok-soft: #ecfdf5;   --ok-line: #a7f3d0;
  --warn: #b45309; --warn-soft: #fffbeb; --warn-line: #fde68a;
  --bad: #b91c1c;  --bad-soft: #fef2f2;  --bad-line: #fecaca;
  --side: #0f172a;
  --side-ink: #cbd5e1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg: 0 12px 32px rgba(16,24,40,.12);
}

* { box-sizing: border-box; }
/* The hidden attribute always wins: a class that sets display must never
   un-hide an element the code has hidden. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 Inter, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ---------- App shell ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 30;
  background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column; padding: 18px 14px;
}
.sidebar-brand { padding: 4px 8px 18px; border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: 12px; }
.logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: #fff; letter-spacing: -.02em; }
.logo:hover { text-decoration: none; }
.logo-mark {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #22d3ee); color: #fff; font-size: 12px; font-weight: 700;
}
.workspace { margin-top: 10px; font-size: 12px; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 8px;
  color: var(--side-ink); font-weight: 500;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.sidebar-nav a.is-active { background: rgba(99,102,241,.22); color: #fff; box-shadow: inset 3px 0 0 #818cf8; }
.sidebar-nav svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; opacity: .9; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 12px 8px 2px; border-top: 1px solid rgba(255,255,255,.08); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: #334155; color: #fff; display: grid; place-items: center; font-weight: 600; flex: none; }
.sidebar-user .who { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.sidebar-user strong { color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user a { color: #94a3b8; font-size: 12px; }

.content { margin-left: 240px; padding: 28px 32px 64px; max-width: 1320px; }
main.bare { max-width: 440px; margin: 9vh auto; padding: 0 16px; }

.mobilebar, .nav-toggle, .nav-scrim { display: none; }
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .nav-toggle:checked ~ .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .nav-toggle:checked ~ .nav-scrim { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 20; }
  .mobilebar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 10; background: var(--side); padding: 10px 16px; }
  .burger { display: grid; gap: 4px; cursor: pointer; padding: 6px; }
  .burger span { display: block; width: 18px; height: 2px; background: #fff; border-radius: 2px; }
  .content { margin-left: 0; padding: 20px 16px 56px; }
}

/* ---------- Typography & page head ---------- */
h1 { font-size: 24px; line-height: 1.25; margin: 0 0 4px; letter-spacing: -.02em; font-weight: 700; }
h2 { font-size: 15px; margin: 0 0 14px; font-weight: 600; letter-spacing: -.01em; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
.sub { color: var(--muted); margin: 0 0 22px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head .sub { margin: 0; }
.page-head .actions { margin: 0; }

/* ---------- Cards ---------- */
.panel, .card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.panel > h2:first-child, .card > h2:first-child { margin-top: 0; }
.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .n { font-size: 26px; font-weight: 700; letter-spacing: -.03em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 2px; }
.stat .d { font-size: 12px; margin-top: 6px; color: var(--muted); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: #fafbfc; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover, table tr:hover td { background: #fafbff; }
.panel[style*="padding:0"] table th:first-child, .panel[style*="padding:0"] table td:first-child { padding-left: 18px; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; margin: 14px 0 6px; font-size: 13px; color: var(--ink-2); }
label .hint, .hint { font-weight: 400; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url],
input[type=time], input[type=date], input[type=datetime-local], input[type=search], input[type=file],
select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid #d1d5db; border-radius: 8px;
  font: inherit; background: #fff; color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 150px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
input[type=checkbox], input[type=radio] { accent-color: var(--brand); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--brand);
  background: var(--brand); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, box-shadow .15s, transform .05s; white-space: nowrap;
}
.btn:hover { background: var(--brand-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--ink-2); border-color: #d1d5db; }
.btn.ghost:hover { background: #f9fafb; }
.btn.danger { background: var(--bad); border-color: var(--bad); }
.btn.soft { background: var(--brand-soft); color: var(--brand-2); border-color: transparent; }
.btn.sm { padding: 5px 11px; font-size: 13px; }
.btn.lg { padding: 12px 22px; font-size: 15px; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 18px; flex-wrap: wrap; }

/* ---------- Feedback ---------- */
.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 20px; border: 1px solid; white-space: pre-wrap; }
.flash-ok   { background: var(--ok-soft);   border-color: var(--ok-line);   color: var(--ok); }
.flash-err  { background: var(--bad-soft);  border-color: var(--bad-line);  color: var(--bad); }
.flash-warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.notice {
  background: var(--warn-soft); border: 1px solid var(--warn-line); color: #78350f;
  padding: 13px 16px; border-radius: 10px; margin-bottom: 20px;
}
.notice strong { color: #713f12; }
.notice.info { background: var(--brand-soft); border-color: #c7d2fe; color: #3730a3; }

.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid transparent; line-height: 1.6; white-space: nowrap;
}
.pill-new         { background: #f3f4f6; color: #4b5563; }
.pill-contacted   { background: #eff6ff; color: #1d4ed8; }
.pill-replied     { background: var(--warn-soft); color: var(--warn); }
.pill-booked, .pill-won, .pill-sent, .pill-running, .pill-valid { background: var(--ok-soft); color: var(--ok); }
.pill-lost, .pill-unqualified, .pill-skipped, .pill-draft, .pill-paused, .pill-done { background: #f3f4f6; color: #6b7280; }
.pill-failed, .pill-bounced, .pill-invalid { background: var(--bad-soft); color: var(--bad); }
.pill-queued { background: #f3f4f6; color: #4b5563; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono  { font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-all; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters label { margin: 0 0 5px; }
.filters > div { min-width: 150px; }

.empty {
  text-align: center; padding: 44px 20px; color: var(--muted);
  border: 1.5px dashed var(--line); border-radius: var(--radius); background: #fcfcfd;
}
.empty h3 { color: var(--ink); font-size: 16px; margin-bottom: 6px; }

/* ---------- Booking page ---------- */
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); gap: 8px; }
.slots button { padding: 10px 4px; border: 1px solid var(--line); background: #fff; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500; }
.slots button:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.day-head { font-weight: 600; margin: 20px 0 8px; }

.vars code { background: var(--brand-soft); color: var(--brand-2); padding: 1px 6px; border-radius: 5px; font-size: 12px; }
.vars li { margin-bottom: 5px; }

pre.log {
  background: #0b1220; color: #d6dde6; padding: 14px; border-radius: 10px;
  overflow-x: auto; font-size: 12px; line-height: 1.5; max-height: 340px;
}

/* ---------- Auth (logged-out) pages ---------- */
body.is-bare { background: radial-gradient(1200px 600px at 50% -10%, #e0e7ff, var(--bg)); }
main.bare .panel { padding: 28px; box-shadow: var(--shadow-lg); border-color: transparent; }
