:root {
  --bg: #070607;
  --bg-elevated: #131117;
  --bg-inset: #1b171d;
  --border: #2b2530;
  --border-soft: #1f1a22;
  --text: #f5f2f6;
  --text-muted: #948d9b;
  --accent: #e0212f;
  --accent-bright: #ff3b48;
  --accent-hover: #b7161f;
  --accent-glow: rgba(224, 33, 47, 0.35);
  --success: #3ddc84;
  --danger: #ff5a5f;
  --radius: 8px;
  --radius-lg: 12px;
  --font-display: 'Oswald', 'Segoe UI', sans-serif;
  --font-body: 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(ellipse 1100px 600px at 12% -8%, rgba(224, 33, 47, 0.10), transparent 55%),
    radial-gradient(ellipse 800px 500px at 100% 100%, rgba(224, 33, 47, 0.06), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  position: relative;
}

/* Film-grain — a fixed, ultra-light noise layer over the whole app. Generated
   in CSS (no image asset), never intercepts clicks. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

a { color: var(--accent-bright); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font-family: var(--font-mono);
  background: var(--bg-inset);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.88em;
  color: #ffb3b8;
}

::selection { background: var(--accent); color: #fff; }

/* ---------- Topbar ---------- */

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: linear-gradient(180deg, #110f13, #0c0b0d);
  border-bottom: 1px solid var(--border);
}

.topbar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, var(--accent-bright), var(--accent) 30%, transparent 70%);
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.topbar .brand img {
  height: 32px;
  width: 32px;
  border-radius: 7px;
  object-fit: cover;
  box-shadow: 0 0 0 1px var(--border), 0 0 16px var(--accent-glow);
}

.rec-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent-bright);
  box-shadow: 0 0 8px var(--accent-bright);
  animation: rec-pulse 2.2s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.topbar .user { display: flex; align-items: center; gap: 12px; font-size: 13.5px; color: var(--text-muted); }
.topbar .user img { width: 29px; height: 29px; border-radius: 50%; box-shadow: 0 0 0 2px var(--border-soft); }

/* ---------- Layout ---------- */

.layout { display: flex; min-height: calc(100vh - 62px); }

.sidebar {
  width: 224px;
  flex-shrink: 0;
  background: #0a090b;
  border-right: 1px solid var(--border);
  padding: 22px 12px;
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 13px;
  margin-bottom: 2px;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: 0.01em;
  border-left: 2px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s, padding-left 0.12s;
}

.nav-ico { font-size: 14px; width: 18px; text-align: center; flex-shrink: 0; opacity: 0.85; }

.sidebar a:hover { background: var(--bg-inset); color: var(--text); padding-left: 16px; }
.sidebar a.active {
  background: linear-gradient(90deg, rgba(224, 33, 47, 0.18), rgba(224, 33, 47, 0.02));
  color: #fff;
  border-left-color: var(--accent-bright);
  box-shadow: inset 0 0 22px rgba(224, 33, 47, 0.06);
}

.content { flex: 1; padding: 34px 38px 60px; max-width: 820px; }

.eyebrow-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-bright);
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

h1 {
  font-family: var(--font-display);
  font-size: 27px;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0 0 6px;
}
.subtitle { color: var(--text-muted); font-size: 14.5px; margin: 0 0 28px; line-height: 1.55; max-width: 62ch; }

/* ---------- Cards & forms ---------- */

.card {
  position: relative;
  background: linear-gradient(180deg, var(--bg-elevated), #100e13);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 24px 26px;
  margin-bottom: 20px;
  box-shadow: 0 12px 28px -14px rgba(0, 0, 0, 0.6), 0 1px 0 rgba(255, 255, 255, 0.02) inset;
  overflow: hidden;
}

.card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent-bright), var(--accent) 40%, transparent 85%);
  opacity: 0.85;
}

.card h2 {
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 18px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

label { display: block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; margin-top: 18px; letter-spacing: 0.01em; }
label:first-child { margin-top: 0; }

input[type="text"], input[type="url"], input[type="file"], input[type="number"], input[type="password"], textarea, select {
  width: 100%;
  padding: 10px 13px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
}

input[type="file"] { padding: 8px 13px; color: var(--text-muted); }

textarea { min-height: 80px; resize: vertical; line-height: 1.5; }

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

select { accent-color: var(--accent); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; }
.toggle-row label { margin: 0; color: var(--text); font-size: 14px; font-weight: 500; }

.switch { position: relative; display: inline-block; width: 40px; height: 23px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; cursor: pointer; inset: 0; background: #2c282d; border-radius: 24px; transition: 0.15s;
}
.switch .slider::before {
  content: ""; position: absolute; height: 17px; width: 17px; left: 3px; bottom: 3px;
  background: white; border-radius: 50%; transition: 0.15s;
}
.switch input:checked + .slider { background: var(--accent); box-shadow: 0 0 12px var(--accent-glow); }
.switch input:checked + .slider::before { transform: translateX(17px); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: linear-gradient(180deg, var(--accent-bright), var(--accent));
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 2px 14px rgba(224, 33, 47, 0.3);
  transition: transform 0.1s, box-shadow 0.15s;
}
.btn:hover { box-shadow: 0 4px 22px rgba(224, 33, 47, 0.45); text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.secondary { background: var(--bg-inset); border: 1px solid var(--border); box-shadow: none; color: var(--text); }
.btn.secondary:hover { background: #242026; box-shadow: none; }
.btn.danger { background: linear-gradient(180deg, var(--danger), #d63c40); box-shadow: 0 2px 14px rgba(255, 90, 95, 0.25); }

.actions { margin-top: 24px; display: flex; gap: 10px; }

.hint { font-size: 12.5px; color: var(--text-muted); margin-top: 8px; line-height: 1.55; }

.flash {
  position: relative;
  padding: 13px 16px 13px 18px;
  border-radius: 7px;
  margin-bottom: 20px;
  font-size: 14px;
  background: rgba(61, 220, 132, 0.08);
  border: 1px solid rgba(61, 220, 132, 0.25);
  color: var(--success);
  overflow: hidden;
}
.flash::before { content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 3px; background: var(--success); }

/* ---------- Tables ---------- */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 8px; border-bottom: 1px solid var(--border-soft); }
th { color: var(--text-muted); font-weight: 600; font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; }
tr:last-child td { border-bottom: none; }

.thumb-preview {
  max-width: 180px; max-height: 100px; border-radius: 7px; border: 1px solid var(--border);
  display: block; margin-top: 10px; object-fit: cover;
}

/* ---------- Login / error (full-bleed, no boxed card — the grain + vignette carry it) ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
  text-align: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse 900px 560px at 50% 8%, rgba(224, 33, 47, 0.16), transparent 60%),
    radial-gradient(ellipse 1200px 900px at 50% 120%, rgba(224, 33, 47, 0.05), transparent 60%),
    var(--bg);
}

/* Faint diagonal scratch texture, echoing the logo's claw marks. */
.login-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(115deg, rgba(255,255,255,0.02) 0px, rgba(255,255,255,0.02) 1px, transparent 1px, transparent 22px);
  pointer-events: none;
}

/* Vignette */
.login-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 160px 40px rgba(0, 0, 0, 0.65);
  pointer-events: none;
}

.login-wrap .logo-glow {
  position: relative;
  z-index: 2;
  height: 108px; width: 108px;
  border-radius: 22px;
  object-fit: cover;
  box-shadow: 0 0 0 1px var(--border), 0 0 70px var(--accent-glow);
  animation: logo-breathe 4.5s ease-in-out infinite;
}
@keyframes logo-breathe {
  0%, 100% { box-shadow: 0 0 0 1px var(--border), 0 0 70px var(--accent-glow); }
  50% { box-shadow: 0 0 0 1px var(--border), 0 0 100px var(--accent-glow); }
}

.login-wrap .eyebrow {
  position: relative;
  z-index: 2;
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--accent-bright);
  font-weight: 500;
}

.login-wrap h1 {
  position: relative;
  z-index: 2;
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
  text-shadow: 0 0 40px rgba(224, 33, 47, 0.35);
}

.login-wrap p {
  position: relative;
  z-index: 2;
  color: var(--text-muted);
  font-size: 14.5px;
  max-width: 380px;
  margin: 0;
  line-height: 1.65;
}

.login-wrap .btn { position: relative; z-index: 2; padding: 13px 30px; font-size: 14.5px; margin-top: 10px; }

.error-card .logo-glow { box-shadow: 0 0 0 1px var(--border), 0 0 70px rgba(255, 90, 95, 0.35); }

/* ---------- Status pills ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  font-family: var(--font-mono);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.on { background: rgba(61, 220, 132, 0.12); color: var(--success); }
.pill.off { background: rgba(148, 141, 155, 0.12); color: var(--text-muted); }
.pill.open { background: rgba(224, 33, 47, 0.14); color: var(--accent-bright); }
.pill.closed { background: rgba(148, 141, 155, 0.12); color: var(--text-muted); }

/* ---------- List rows (types/panels/tickets) ---------- */

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 4px;
  border-bottom: 1px solid var(--border-soft);
}
.list-row:last-child { border-bottom: none; }
.list-row-name { font-weight: 600; font-size: 14.5px; }
.list-row-meta { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }
.list-row-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.btn-tiny {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-inset);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
.btn-tiny:hover { background: #242026; text-decoration: none; }
.btn-tiny.danger { border-color: rgba(255, 90, 95, 0.35); color: var(--danger); }
.btn-tiny.danger:hover { background: rgba(255, 90, 95, 0.1); }
.btn-tiny:disabled { opacity: 0.35; cursor: default; }
.btn-tiny:disabled:hover { background: var(--bg-inset); }

.empty-hint { color: var(--text-muted); font-size: 13.5px; padding: 6px 4px; }

/* ---------- Dynamic question rows ---------- */

.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 20px;
  margin-bottom: 8px;
}

.repeat-row {
  position: relative;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 40px 14px 14px;
  margin-bottom: 10px;
}
.repeat-row label { margin-top: 10px; }
.repeat-row label:first-of-type { margin-top: 0; }
.repeat-row-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.remove-row-btn {
  position: absolute; top: 10px; right: 10px;
  width: 24px; height: 24px; border-radius: 6px;
  background: transparent; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 14px;
}
.remove-row-btn:hover { background: rgba(255, 90, 95, 0.12); color: var(--danger); }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}
.checkbox-row input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------- Searchable select ---------- */

.searchable-select { position: relative; }
.searchable-select-native { display: none; }
.searchable-select-input { width: 100%; }
.searchable-select-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  max-height: 240px;
  overflow-y: auto;
  background: #1c1a1f;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 20;
}
.searchable-select-item {
  padding: 9px 13px;
  font-size: 14px;
  cursor: pointer;
}
.searchable-select-item:hover, .searchable-select-item.active { background: var(--bg-inset); }
.searchable-select-empty { padding: 9px 13px; font-size: 13px; color: var(--text-muted); }
