:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --border: #dde1e8;
  --primary: #2f5fd0;
  --primary-text: #ffffff;
  --danger: #c4372f;
  --success-bg: #e7f6ec;
  --success-border: #9fd8b1;
  --error-bg: #fdecea;
  --error-border: #f2b4ae;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d;
    --surface: #1d222b;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --border: #323946;
    --primary: #5b85ea;
    --danger: #e0635b;
    --success-bg: #183324;
    --success-border: #2e6b45;
    --error-bg: #3a1d1b;
    --error-border: #7a3530;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--primary); }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
code { font-size: .9em; background: color-mix(in srgb, var(--border) 45%, transparent); padding: .1em .35em; border-radius: 4px; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.mb { margin-bottom: 1rem; }

/* Layout */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem;
  padding: .75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 1.25rem; text-decoration: none; color: var(--text); }
.nav { display: flex; flex-wrap: wrap; gap: .25rem; flex: 1; }
.nav a { padding: .35rem .65rem; border-radius: 6px; text-decoration: none; color: var(--muted); }
.nav a:hover { color: var(--text); }
.nav a.active { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); font-weight: 600; }
.userbox { display: flex; align-items: center; gap: .75rem; margin-left: auto; }
.userbox form { margin: 0; }
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.card.narrow { max-width: 440px; margin: 2rem auto; }
.card.narrow-left { max-width: 560px; }
.center { text-align: center; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.big-icon { font-size: 3rem; line-height: 1; margin-bottom: .5rem; color: var(--primary); }

/* Forms */
.stack { display: flex; flex-direction: column; gap: .9rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .95rem; }
label small { font-weight: 400; }
input[type=text], input[type=password], input:not([type]), input[type=file] {
  font: inherit; padding: .6rem .7rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); width: 100%;
}
input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
label.check { flex-direction: row; align-items: center; gap: .55rem; font-weight: 500; cursor: pointer; }
label.check input { width: 1.15rem; height: 1.15rem; margin: 0; accent-color: var(--primary); }
label.check.indent { margin-left: 1.7rem; }
.divider { display: flex; align-items: center; gap: .75rem; margin: 1.25rem 0 .9rem; color: var(--muted); font-size: .9rem; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.input-prefix { display: flex; align-items: stretch; }
.input-prefix > span { display: flex; align-items: center; padding: 0 .6rem; border: 1px solid var(--border); border-right: 0; border-radius: 8px 0 0 8px; color: var(--muted); }
.input-prefix > input { border-radius: 0 8px 8px 0; }
.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .75rem; }
.inline-form input { width: auto; flex: 1; min-width: 160px; padding: .4rem .6rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  font: inherit; font-weight: 600; padding: .55rem 1rem; border-radius: 8px; border: 1px solid transparent;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn-sm { padding: .3rem .65rem; font-size: .875rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.btn:hover { filter: brightness(1.06); }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.actions form { margin: 0; }

/* Feedback */
.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash p { margin: .25rem 0; }
.flash-success { background: var(--success-bg); border-color: var(--success-border); }
.flash-error { background: var(--error-bg); border-color: var(--error-border); }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 99px; font-size: .8rem; font-weight: 600; border: 1px solid var(--border); }
.badge-active { background: var(--success-bg); border-color: var(--success-border); }
.badge-pending { background: color-mix(in srgb, #e3a008 18%, transparent); border-color: color-mix(in srgb, #e3a008 50%, transparent); }
.badge-disabled { background: var(--error-bg); border-color: var(--error-border); }

/* Tables & lists */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1.25rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem; padding: .55rem 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.tabs { display: flex; flex-wrap: wrap; gap: .25rem; margin-bottom: 1rem; }
.tabs a { padding: .4rem .8rem; border-radius: 99px; text-decoration: none; color: var(--muted); border: 1px solid var(--border); background: var(--surface); }
.tabs a.active { color: var(--primary-text); background: var(--primary); border-color: var(--primary); }
.inline-details { display: inline-block; }
.inline-details > summary { list-style: none; cursor: pointer; }
.inline-details > summary::-webkit-details-marker { display: none; }
.inline-details[open] { display: block; flex-basis: 100%; }

/* Apps */
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.app-tile {
  display: flex; flex-direction: column; gap: .25rem; padding: 1.25rem; min-height: 110px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  text-decoration: none; color: var(--text); justify-content: center;
}
.app-tile:hover { border-color: var(--primary); }
.app-tile.inactive { opacity: .6; }
.app-title { font-weight: 700; font-size: 1.1rem; }

/* Registration / QR */
.qr-small { max-width: 240px; background: #fff; border-radius: 8px; padding: .5rem; }
.qr-small svg, .present-qr svg { display: block; width: 100%; height: auto; }
.url-line code { font-size: .8rem; }
.token-line { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

.present { min-height: 100vh; display: flex; flex-direction: column; padding: 1rem; }
.present-toolbar { display: flex; gap: .5rem; }
.present > div[hx-get] { flex: 1; display: flex; }
.present-panel { flex: 1; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 3rem; padding: 1rem; }
.present-qr { width: min(80vh, 90vw); background: #fff; padding: 1rem; border-radius: 16px; }
.present-info h1 { font-size: clamp(1.8rem, 4vw, 3rem); max-width: 14ch; }
.present-timer { font-size: clamp(1.4rem, 3vw, 2.2rem); }
.present-url code { font-size: clamp(1rem, 1.8vw, 1.4rem); }
.present-closed { flex-direction: column; text-align: center; gap: .5rem; }
.present-closed h1 { font-size: clamp(2rem, 5vw, 3.5rem); }
