/* UItsmijter: styling modelled on the UniFi Network application. */

:root {
  color-scheme: light;
  --bg: #f4f5f6;
  --rail: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f8f9;
  --hover: #f1f3f5;
  --border: #e4e6e9;
  --border-strong: #cdd0d5;
  --text: #212327;
  --text-2: #696e76;
  --text-3: #9ca1a8;
  --accent: #006fff;
  --accent-soft: rgba(0, 111, 255, 0.1);
  --primary: #006fff;
  --primary-hover: #005ad1;
  --warn: #b86e00;
  --warn-line: #f5a524;
  --warn-soft: rgba(245, 165, 36, 0.14);
  --danger: #d23539;
  --danger-soft: rgba(240, 70, 75, 0.1);
  --success: #18914a;
  --success-soft: rgba(56, 204, 101, 0.13);
  --info-soft: rgba(0, 111, 255, 0.07);
  --switch-off: #c5c9ce;
  --shadow: 0 10px 30px rgba(17, 19, 22, 0.14);
  --backdrop: rgba(17, 19, 22, 0.32);
  --toast: #2b2d31;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111214;
    --rail: #17181b;
    --surface: #1b1c1f;
    --surface-2: #212226;
    --hover: #25272b;
    --border: #2c2e33;
    --border-strong: #3c3f45;
    --text: #f1f2f4;
    --text-2: #a2a6ad;
    --text-3: #6e737b;
    --accent: #4b97ff;
    --accent-soft: rgba(75, 151, 255, 0.15);
    --primary: #006fff;
    --primary-hover: #2b85ff;
    --warn: #f5a524;
    --warn-line: #f5a524;
    --warn-soft: rgba(245, 165, 36, 0.12);
    --danger: #f2585c;
    --danger-soft: rgba(242, 88, 92, 0.14);
    --success: #3fcf70;
    --success-soft: rgba(63, 207, 112, 0.14);
    --info-soft: rgba(75, 151, 255, 0.09);
    --switch-off: #474a51;
    --shadow: 0 10px 34px rgba(0, 0, 0, 0.55);
    --backdrop: rgba(0, 0, 0, 0.5);
    --toast: #33363b;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111214;
  --rail: #17181b;
  --surface: #1b1c1f;
  --surface-2: #212226;
  --hover: #25272b;
  --border: #2c2e33;
  --border-strong: #3c3f45;
  --text: #f1f2f4;
  --text-2: #a2a6ad;
  --text-3: #6e737b;
  --accent: #4b97ff;
  --accent-soft: rgba(75, 151, 255, 0.15);
  --primary: #006fff;
  --primary-hover: #2b85ff;
  --warn: #f5a524;
  --warn-line: #f5a524;
  --warn-soft: rgba(245, 165, 36, 0.12);
  --danger: #f2585c;
  --danger-soft: rgba(242, 88, 92, 0.14);
  --success: #3fcf70;
  --success-soft: rgba(63, 207, 112, 0.14);
  --info-soft: rgba(75, 151, 255, 0.09);
  --switch-off: #474a51;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.55);
  --backdrop: rgba(0, 0, 0, 0.5);
  --toast: #33363b;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
svg.i-sm { width: 14px; height: 14px; stroke-width: 2; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-3); }
.warn-text { color: var(--warn); }

/* ---- shell ---------------------------------------------------------------- */

.app { display: flex; min-height: 100vh; }
.rail {
  width: 56px; flex: none; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 0;
  background: var(--rail); border-right: 1px solid var(--border);
}
.rail .logo { width: 32px; height: 32px; margin-bottom: 12px; display: block; }
.rail-item {
  width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center;
  color: var(--text-2);
}
.rail-item.active { color: var(--accent); background: var(--accent-soft); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 52px; flex: none; position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .logo-sm { display: none; width: 26px; height: 26px; }
.topbar h1 { font-size: 16px; font-weight: 600; margin: 0; white-space: nowrap; }
.topbar .meta { color: var(--text-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 6px; border: 0; background: transparent;
  color: var(--text-2); display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-btn.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.content { width: 100%; max-width: 1180px; margin: 0 auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }

/* ---- panels & table ----------------------------------------------------- */

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.panel-head h2 { font-size: 14px; font-weight: 600; margin: 0; }
.count {
  font-size: 11px; font-weight: 600; color: var(--text-2); line-height: 18px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 0 7px;
}
.panel-stats { margin-left: auto; font-size: 12px; color: var(--text-2); }

.tr {
  display: grid;
  grid-template-columns: 52px minmax(200px, 2.3fr) 80px minmax(90px, 1fr) minmax(110px, 1fr) minmax(130px, 1.2fr) 24px;
  column-gap: 12px; align-items: center; min-height: 46px;
  padding: 0 10px 0 16px; border-bottom: 1px solid var(--border);
}
.tr:last-child { border-bottom: 0; }
.c-sched { display: contents; }
.th { min-height: 34px; font-size: 12px; color: var(--text-2); background: var(--surface-2); }
.rule { font-size: 13px; cursor: pointer; position: relative; }
.rule:hover { background: var(--hover); }
.rule:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.rule.has-warn::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--warn-line); }

/* Paused: everything except the switch is greyed out. */
.rule.paused > :not(.c-toggle):not(.c-sched), .rule.paused .c-sched > * { opacity: 0.42; filter: grayscale(1); }
.rule.paused .name { font-weight: 400; }
.rule.paused .c-sched > .warn { filter: none; opacity: 0.7; }

.c-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-days, .c-time, .c-default { display: flex; align-items: center; gap: 5px; white-space: nowrap; min-width: 0; }
.c-default { color: var(--text-2); }
.c-days.warn, .c-time.warn { color: var(--warn); font-weight: 600; }
.c-chev { color: var(--text-3); display: grid; place-items: center; }
.lbl-mobile { display: none; }
.empty { padding: 18px 16px; color: var(--text-3); font-size: 13px; }

.badge { display: inline-block; font-size: 11px; font-weight: 600; line-height: 18px; padding: 0 7px; border-radius: 4px; white-space: nowrap; }
.badge.block { color: var(--danger); background: var(--danger-soft); }
.badge.allow { color: var(--success); background: var(--success-soft); }
.badge.neutral { color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); line-height: 16px; }

/* ---- switch --------------------------------------------------------------- */

.switch { position: relative; display: inline-block; width: 32px; height: 18px; flex: none; }
.switch input { position: absolute; inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 9px; background: var(--switch-off); transition: background 0.15s; }
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: transform 0.15s;
}
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(14px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled { cursor: progress; }
.switch input:disabled + span { opacity: 0.55; }

/* ---- notices, buttons, inputs ------------------------------------------- */

.notice { display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px; border-radius: 6px; border: 1px solid var(--border); font-size: 13px; }
.notice svg { margin-top: 1px; }
.notice .grow { flex: 1; }
.notice.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn-line) 45%, transparent); }
.notice.warn svg { color: var(--warn); }
.notice.error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.notice.error svg { color: var(--danger); }
.notice.info { background: var(--info-soft); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.notice.info svg { color: var(--accent); }

.btn {
  height: 32px; padding: 0 14px; border-radius: 6px; border: 1px solid transparent;
  font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.4; cursor: default; }
.btn-secondary { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--hover); }
.btn-block { width: 100%; }

.input {
  height: 32px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.loading { display: flex; align-items: center; gap: 10px; color: var(--text-2); padding: 40px 0; justify-content: center; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }

/* ---- edit panel (drawer) ------------------------------------------------- */

.backdrop { position: fixed; inset: 0; z-index: 20; background: var(--backdrop); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 21; width: 420px; max-width: 100%;
  display: flex; flex-direction: column; visibility: hidden;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  transform: translateX(100%); transition: transform 0.22s ease, visibility 0s linear 0.22s;
}
.drawer.open { transform: none; visibility: visible; transition: transform 0.22s ease; }
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 14px 12px 14px 18px; border-bottom: 1px solid var(--border); }
.drawer-head h3 { flex: 1; margin: 0; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 22px; }
.drawer-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.drawer-foot .form-error { flex: 1; }

.field-label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field-title { font-size: 13px; font-weight: 500; }
.hint { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-2); margin-top: 8px; }
.hint:empty { display: none; }
.hint.warn-text { color: var(--warn); font-weight: 500; }
.form-error { color: var(--danger); font-size: 12px; min-height: 1em; }

.days { display: flex; gap: 6px; flex-wrap: wrap; }
.day {
  min-width: 40px; height: 32px; padding: 0 8px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font-size: 13px; font-weight: 500;
}
.day:hover { border-color: var(--accent); color: var(--text); }
.day[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }
.day:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.time-row { display: flex; align-items: center; gap: 10px; }
.time-row .input { width: 120px; }
.field.is-warn .day[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--warn-line); }
.field.is-warn .input { border-color: var(--warn-line); }

.default-box {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); font-size: 13px;
}
.details { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13px; margin: 0; }
.details dt { color: var(--text-2); }
.details dd { margin: 0; overflow-wrap: anywhere; }

/* ---- toasts --------------------------------------------------------------- */

.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 40; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; width: max-content; max-width: calc(100% - 32px); }
.toast { background: var(--toast); color: #fff; padding: 9px 14px; border-radius: 6px; font-size: 13px; box-shadow: var(--shadow); transition: opacity 0.3s, transform 0.3s; }
.toast.error { background: var(--danger); }
.toast.out { opacity: 0; transform: translateY(6px); }

/* ---- sign-in page --------------------------------------------------------- */

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; padding: 32px 28px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 20px; margin: 14px 0 4px; }
.login-card p { margin: 0 0 22px; color: var(--text-2); font-size: 13px; }
.login-card form { text-align: left; display: flex; flex-direction: column; gap: 8px; }
.login-card .input { width: 100%; height: 38px; }
.login-card .btn { height: 38px; margin-top: 6px; }

/* ---- small screens -------------------------------------------------------- */

@media (max-width: 760px) {
  .rail { display: none; }
  .topbar { padding: 0 8px 0 16px; gap: 8px; }
  .topbar .logo-sm { display: block; }
  .topbar .meta { display: none; }
  .content { padding: 16px; gap: 14px; }
  .th { display: none; }
  .tr.rule {
    grid-template-columns: 46px minmax(0, 1fr) 20px;
    grid-template-areas: "tog name chev" "tog sched chev" "tog def chev";
    row-gap: 3px; padding: 11px 8px 11px 14px;
  }
  .c-toggle { grid-area: tog; align-self: start; padding-top: 1px; }
  .c-name { grid-area: name; }
  .c-action { display: none; }
  .c-sched { grid-area: sched; display: flex; gap: 12px; }
  .c-default { grid-area: def; font-size: 12px; }
  .c-chev { grid-area: chev; }
  .lbl-mobile { display: inline; }
  .panel-stats { font-size: 11px; }
  .drawer { width: 100%; border-left: 0; }
}
