/* EdgeDock Collector — visual language
   Mirrors the EdgeDock app (app/frontend/src/index.css + its Tailwind
   slate/blue palette): cobalt accents, Rajdhani for display type only,
   opaque slate panels over a faded blueprint grid, and a soft blue glow on
   hover. Colours are theme tokens; dark is the default and
   html[data-theme="light"] (set by js/theme.js) swaps in the light set. */
@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@500;600;700&display=swap');

:root {
  color-scheme: dark;

  --ed-blue: 26 111 196;        /* #1a6fc4 */
  --ed-blue-light: 46 141 232;  /* #2e8de8 */
  --ed-grid-line: rgb(var(--ed-blue) / 0.08);
  --ed-glow: 0 0 0 1px rgb(var(--ed-blue-light) / 0.3), 0 8px 28px rgb(var(--ed-blue) / 0.2);
  --ed-glow-strong: 0 0 0 1px rgb(var(--ed-blue-light) / 0.5), 0 12px 36px rgb(var(--ed-blue) / 0.3);

  --font-display: 'Rajdhani', ui-sans-serif, system-ui, sans-serif;
  --font-body: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Surfaces (Tailwind slate-950 / 800 / 900) */
  --bg-page: #020617;
  --bg-workspace: linear-gradient(160deg, #0d1117 0%, #111827 55%, #0b1220 100%);
  --bg-workspace-haze: rgb(var(--ed-blue) / 0.16);
  --bg-panel: #1e293b;
  --bg-inset: rgb(15 23 42 / 0.6);
  --bg-input: #0f172a;
  --bg-table-head: rgb(15 23 42 / 0.55);
  --bg-row-hover: rgb(51 65 85 / 0.35);

  --border: #334155;
  --border-input: #475569;
  --border-accent: rgb(var(--ed-blue-light) / 0.45);

  --text-main: #f1f5f9;
  --text-strong: #ffffff;
  --text-muted: #94a3b8;
  --text-label: #cbd5e1;

  --link: #60a5fa;
  --link-hover: #93c5fd;
  --accent-text: #60a5fa;

  --btn-primary: #2563eb;
  --btn-primary-hover: #1d4ed8;
  --btn-secondary-bg: #334155;
  --btn-secondary-hover: #475569;
  --btn-secondary-text: #f1f5f9;
  --btn-danger: #dc2626;
  --btn-danger-hover: #b91c1c;

  /* Status tones: background / text / border (Tailwind *-900/30, *-200, *-700) */
  --tone-blue-bg: rgb(30 58 138 / 0.4);   --tone-blue-fg: #bfdbfe;   --tone-blue-bd: rgb(59 130 246 / 0.45);
  --tone-green-bg: rgb(20 83 45 / 0.4);   --tone-green-fg: #bbf7d0;  --tone-green-bd: rgb(34 197 94 / 0.4);
  --tone-amber-bg: rgb(120 53 15 / 0.4);  --tone-amber-fg: #fde68a;  --tone-amber-bd: rgb(245 158 11 / 0.45);
  --tone-orange-bg: rgb(124 45 18 / 0.4); --tone-orange-fg: #fed7aa; --tone-orange-bd: rgb(249 115 22 / 0.45);
  --tone-red-bg: rgb(127 29 29 / 0.4);    --tone-red-fg: #fecaca;    --tone-red-bd: rgb(239 68 68 / 0.45);
  --tone-purple-bg: rgb(88 28 135 / 0.4); --tone-purple-fg: #e9d5ff; --tone-purple-bd: rgb(168 85 247 / 0.45);
  --tone-gray-bg: rgb(71 85 105 / 0.4);   --tone-gray-fg: #e2e8f0;   --tone-gray-bd: rgb(148 163 184 / 0.4);

  --text-danger: #f87171;
  --diff-add: #86efac;
  --diff-del: #fca5a5;

  /* Calendar heat: cell fill colour and the text drawn over it */
  --cal-rgb: 37 99 235;
  --cal-text: #ffffff;
  --cal-now: #eab308;
}

:root[data-theme="light"] {
  color-scheme: light;

  --ed-grid-line: rgb(var(--ed-blue) / 0.09);
  --ed-glow: 0 0 0 1px rgb(var(--ed-blue-light) / 0.28), 0 6px 22px rgb(var(--ed-blue) / 0.14);
  --ed-glow-strong: 0 0 0 1px rgb(var(--ed-blue-light) / 0.45), 0 12px 32px rgb(var(--ed-blue) / 0.22);

  --bg-page: #f1f5f9;
  --bg-workspace: linear-gradient(160deg, #e2e9f2 0%, #d6e0ec 100%);
  --bg-workspace-haze: rgb(var(--ed-blue) / 0.10);
  --bg-panel: #ffffff;
  --bg-inset: #eef2f7;
  --bg-input: #ffffff;
  --bg-table-head: rgb(var(--ed-blue) / 0.13);
  --bg-row-hover: #eef2f7;

  --border: #e2e8f0;
  --border-input: #cbd5e1;
  --border-accent: rgb(var(--ed-blue-light) / 0.45);

  --text-main: #0f172a;
  --text-strong: #0f172a;
  --text-muted: #475569;
  --text-label: #334155;

  --link: #1d4ed8;
  --link-hover: #1e40af;
  --accent-text: #1d4ed8;

  --btn-secondary-bg: #ffffff;
  --btn-secondary-hover: #f1f5f9;
  --btn-secondary-text: #334155;

  /* Tailwind *-100 / *-800 / *-300 */
  --tone-blue-bg: #dbeafe;   --tone-blue-fg: #1e40af;   --tone-blue-bd: #93c5fd;
  --tone-green-bg: #dcfce7;  --tone-green-fg: #166534;  --tone-green-bd: #86efac;
  --tone-amber-bg: #fef3c7;  --tone-amber-fg: #92400e;  --tone-amber-bd: #fcd34d;
  --tone-orange-bg: #ffedd5; --tone-orange-fg: #9a3412; --tone-orange-bd: #fdba74;
  --tone-red-bg: #fee2e2;    --tone-red-fg: #991b1b;    --tone-red-bd: #fca5a5;
  --tone-purple-bg: #f3e8ff; --tone-purple-fg: #6b21a8; --tone-purple-bd: #d8b4fe;
  --tone-gray-bg: #f1f5f9;   --tone-gray-fg: #334155;   --tone-gray-bd: #cbd5e1;

  --text-danger: #dc2626;
  --diff-add: #15803d;
  --diff-del: #b91c1c;

  --cal-rgb: 96 165 250;
  --cal-text: #0f172a;
  --cal-now: #ca8a04;
}

* {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  background: var(--bg-page);
  color: var(--text-main);
  line-height: 1.55;
}

body {
  position: relative;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.025em;
  line-height: 1.25;
  color: var(--text-strong);
}

.panel > h2:first-child,
.panel > h3:first-child {
  margin-top: 0;
}

h2 { font-size: 1.4rem; }
h3 { font-size: 1.2rem; }
h4 { font-size: 1.05rem; }

/* Links: theme-aware blue, readable on panels in both themes */
a,
a:visited {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  color: var(--link-hover);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:focus-visible,
button:focus-visible,
.btn:focus-visible {
  outline: 2px solid rgb(var(--ed-blue-light));
  outline-offset: 2px;
}

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
}

strong {
  color: var(--text-strong);
}

::selection {
  background: rgb(var(--ed-blue-light) / 0.3);
}

/* Slim, low-contrast scrollbars that turn blue on hover */
* {
  scrollbar-width: thin;
  scrollbar-color: rgb(100 116 139 / 0.4) transparent;
}

/* ── Workspace background ─────────────────────────────── */
.ed-workspace-bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 70% 45% at 50% 0%, var(--bg-workspace-haze) 0%, transparent 70%),
    var(--bg-workspace);
}

.ed-workspace-bg::before {
  content: '';
  position: absolute;
  inset: -60px 0 0 -60px;
  background-image:
    linear-gradient(var(--ed-grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--ed-grid-line) 1px, transparent 1px);
  background-size: 60px 60px;
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, rgb(0 0 0 / 0.55) 35%, transparent 80%);
  mask-image: linear-gradient(to bottom, #000 0%, rgb(0 0 0 / 0.55) 35%, transparent 80%);
  animation: ed-grid-drift 24s linear infinite;
}

@keyframes ed-grid-drift {
  from { transform: translate(0, 0); }
  to { transform: translate(60px, 60px); }
}

.container {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

/* Pages with wide tables use the full width beside the sidebar ({% block container_class %} container-wide). */
.container.container-wide {
  max-width: none;
}

/* ── App shell & sidebar ──────────────────────────────────
   After the EdgeDock app's Sidebar: always dark in both themes, 16rem
   wide or a 4rem icon rail when html[data-sidebar="collapsed"] (set by
   js/sidebar.js). */
.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: 100vh;
}

.app-main {
  flex: 1;
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  width: 16rem;
  height: 100vh;
  color: #f1f5f9;
  background:
    radial-gradient(ellipse 120% 30% at 0% 0%, rgb(var(--ed-blue) / 0.12) 0%, transparent 70%),
    linear-gradient(180deg, #0d1117 0%, #111722 100%);
  border-right: 1px solid rgb(var(--ed-blue) / 0.25);
  transition: width 0.2s;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1rem;
  border-bottom: 1px solid rgb(var(--ed-blue) / 0.2);
}

.sidebar-brand,
.sidebar-brand:visited {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  text-decoration: none;
}

.sidebar-brand:hover {
  text-decoration: none;
}

.sidebar-logo {
  width: 2.25rem;
  height: auto;
  flex-shrink: 0;
  filter: drop-shadow(0 0 8px rgb(46 141 232 / 0.45));
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ed-wordmark {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.04em;
  color: #fff;
}

.ed-wordmark span {
  color: #2e8de8;
}

.sidebar-product {
  margin-top: 0.15rem;
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.24em;
  color: #8b94a0;
}

.sidebar-collapse {
  display: flex;
  flex-shrink: 0;
  padding: 0.25rem;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}

.sidebar-collapse:hover {
  color: #fff;
  background: rgb(var(--ed-blue) / 0.2);
}

.sidebar-collapse svg {
  width: 1.25rem;
  height: 1.25rem;
}

.sidebar-collapse .icon-expand {
  display: none;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ed-nav-link,
.ed-nav-link:visited {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8b94a0;
  text-decoration: none;
  transition: color 0.2s, background 0.2s, box-shadow 0.2s;
}

.ed-nav-link:hover {
  color: #fff;
  background: rgb(var(--ed-blue) / 0.18);
  text-decoration: none;
}

.ed-nav-link.active {
  color: #2e8de8;
  background: rgb(var(--ed-blue) / 0.18);
  box-shadow: inset 0 0 0 1px rgb(var(--ed-blue) / 0.3), 0 0 18px rgb(var(--ed-blue) / 0.15);
}

/* Glowing accent bar on the active item's leading edge */
.ed-nav-link.active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: #2e8de8;
  box-shadow: 0 0 10px #2e8de8, 0 0 2px #2e8de8;
}

.ed-nav-link svg {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  transition: filter 0.2s;
}

.ed-nav-link.active svg,
.ed-nav-link:hover svg {
  filter: drop-shadow(0 0 6px rgb(var(--ed-blue-light) / 0.6));
}

.ed-nav-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Rendered indented beneath the preceding item */
.ed-nav-child {
  margin-left: 1.5rem;
}

.nav-badge {
  display: inline-block;
  min-width: 1.4rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  letter-spacing: 0;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem;
  border-top: 1px solid rgb(var(--ed-blue) / 0.2);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.5rem;
  min-width: 0;
}

.sidebar-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: rgb(var(--ed-blue) / 0.2);
  box-shadow: inset 0 0 0 1px rgb(var(--ed-blue-light) / 0.5), 0 0 12px rgb(26 111 196 / 0.35);
  font-family: var(--font-display);
  font-weight: 700;
  color: #2e8de8;
}

.sidebar-user-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-user-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.875rem;
  font-weight: 500;
}

.sidebar-user-role {
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #8b94a0;
}

.sidebar-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.5rem;
}

.sidebar-logout,
.sidebar-logout:visited {
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
  text-decoration: none;
  transition: color 0.2s;
}

.sidebar-logout:hover {
  color: #fff;
  text-decoration: none;
}

/* Collapsed: icon rail */
html[data-sidebar="collapsed"] .sidebar {
  width: 4rem;
}

html[data-sidebar="collapsed"] .sidebar-header {
  flex-direction: column;
  padding: 1rem 0.5rem;
}

html[data-sidebar="collapsed"] .sidebar-brand-text,
html[data-sidebar="collapsed"] .ed-nav-label,
html[data-sidebar="collapsed"] .sidebar-user-text,
html[data-sidebar="collapsed"] .sidebar-logout,
html[data-sidebar="collapsed"] .sidebar-collapse .icon-collapse {
  display: none;
}

html[data-sidebar="collapsed"] .sidebar-collapse .icon-expand {
  display: block;
}

html[data-sidebar="collapsed"] .ed-nav-link {
  justify-content: center;
  padding: 0.5rem;
}

html[data-sidebar="collapsed"] .ed-nav-child {
  margin-left: 0;
}

html[data-sidebar="collapsed"] .ed-nav-link .nav-badge {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 1.1rem;
  padding: 0 0.25rem;
  font-size: 0.65rem;
}

html[data-sidebar="collapsed"] .sidebar-user,
html[data-sidebar="collapsed"] .sidebar-actions {
  justify-content: center;
  padding: 0;
}

/* Theme toggle (sidebar and login page), styled after EdgeDock's ThemeToggle */
.theme-toggle {
  padding: 0.3rem 0.65rem;
  border-radius: 4px;
  border: 1px solid rgb(var(--ed-blue) / 0.4);
  background: rgb(var(--ed-blue) / 0.1);
  color: #cbd5e1;
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.2s, background 0.2s, box-shadow 0.2s;
}

.theme-toggle:hover {
  color: #fff;
  background: rgb(var(--ed-blue) / 0.25);
  box-shadow: 0 0 12px rgb(var(--ed-blue) / 0.35);
}

.theme-toggle-floating {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 3;
  background: #111722;
}

/* ── Page structure ───────────────────────────────────── */
.page-title {
  font-size: 2rem;
  margin: 0 0 1.5rem;
}

.page-title::after {
  content: '';
  display: block;
  width: 44px;
  height: 3px;
  margin-top: 8px;
  border-radius: 2px;
  background: linear-gradient(90deg, #1a6fc4, #2e8de8);
  box-shadow: 0 0 10px rgb(var(--ed-blue-light) / 0.55);
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08);
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.panel:hover,
.panel:focus-within {
  border-color: var(--border-accent);
  box-shadow: var(--ed-glow);
}

.subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: -0.5rem 0 1.5rem;
}

.subnav a,
.subnav a:visited {
  padding: 0.3rem 0.65rem;
  border-radius: 4px;
  font-family: var(--font-display);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s, background 0.2s;
}

.subnav a:hover {
  color: var(--text-strong);
  background: rgb(var(--ed-blue) / 0.12);
  text-decoration: none;
}

.subnav a.active {
  color: var(--accent-text);
  background: rgb(var(--ed-blue) / 0.15);
  box-shadow: inset 0 0 0 1px rgb(var(--ed-blue) / 0.3);
}

/* ── Forms ────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.4rem;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text-label);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.85rem;
}

.form-control {
  width: 100%;
  padding: 0.55rem 0.8rem;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 6px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control::placeholder {
  color: var(--text-muted);
  opacity: 0.8;
}

.form-control:focus {
  outline: none;
  border-color: rgb(var(--ed-blue-light) / 0.8);
  box-shadow: 0 0 0 3px rgb(var(--ed-blue-light) / 0.25);
}

/* Password with a show / hide button inside its right edge (dialogs.js) */
.password-input {
  position: relative;
}

.password-input .form-control {
  padding-right: 2.4rem;
}

.password-input .icon-btn {
  position: absolute;
  top: 50%;
  right: 0.4rem;
  transform: translateY(-50%);
}

.password-input .icon-btn[aria-pressed="true"] .icon-show,
.password-input .icon-btn[aria-pressed="false"] .icon-hide {
  display: none;
}

.password-input .icon-btn span {
  display: inline-flex;
}

textarea.form-control {
  min-height: 100px;
  resize: vertical;
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: #2563eb;
}

ul.checkbox-row {
  display: flex;
  gap: 0.75rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Checkbox-list labels read as normal text, not as field headings */
ul.checkbox-row label {
  display: inline;
  font-family: inherit;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.95rem;
  color: var(--text-main);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: end;
  margin-bottom: 1.5rem;
}

.filters .form-group {
  margin: 0;
  flex: 1;
  min-width: 160px;
}

/* ── Buttons ──────────────────────────────────────────── */
.btn,
.btn:visited {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.15rem;
  border: 1px solid transparent;
  border-radius: 6px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.3;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.btn:hover {
  text-decoration: none;
}

.btn-primary,
.btn-primary:visited,
.btn-primary:hover {
  background: var(--btn-primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--btn-primary-hover);
  box-shadow: 0 0 0 1px rgb(var(--ed-blue-light) / 0.5), 0 4px 18px rgb(var(--ed-blue) / 0.4);
}

.btn-secondary,
.btn-secondary:visited,
.btn-secondary:hover {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  border-color: var(--border-input);
}

.btn-secondary:hover {
  background: var(--btn-secondary-hover);
  border-color: rgb(var(--ed-blue-light) / 0.6);
}

.btn-danger,
.btn-danger:visited,
.btn-danger:hover {
  background: var(--btn-danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--btn-danger-hover);
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Icon-only row actions, as EdgeDock's tables: muted until hovered, then
   tinted by what they do. Each form in the cell holds one button. */
.icon-actions {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  white-space: nowrap;
}

.icon-actions form {
  display: contents;
}

.icon-btn {
  display: inline-flex;
  padding: 0.25rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s, background-color 0.2s;
}

.icon-btn svg {
  width: 1.1rem;
  height: 1.1rem;
}

.icon-btn:hover { color: var(--accent-text); background: rgb(var(--ed-blue) / 0.12); }
.icon-btn-amber:hover { color: var(--tone-amber-fg); background: var(--tone-amber-bg); }
.icon-btn-green:hover { color: var(--tone-green-fg); background: var(--tone-green-bg); }
.icon-btn-red:hover { color: var(--text-danger); background: var(--tone-red-bg); }

.btn svg {
  width: 1rem;
  height: 1rem;
}

/* ── Page header with a primary action on the right ──── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.page-header .page-title {
  margin-bottom: 0.5rem;
}

.page-subtitle {
  margin: 0;
  color: var(--text-muted);
}

/* ── Modal dialogs (js/dialogs.js) ────────────────────── */
dialog.modal {
  width: min(42rem, calc(100vw - 2rem));
  max-height: 90vh;
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--text-main);
  box-shadow: var(--ed-glow-strong);
}

dialog.modal::backdrop {
  background: rgb(0 0 0 / 0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.modal-header h3 {
  margin: 0;
}

/* Section headings within a dialog form ("ACCOUNT", "NAME") */
.modal-section {
  margin: 1.25rem 0 0.6rem;
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.modal-section + p {
  margin: -0.25rem 0 0.75rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 0.75rem;
}

@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* ── Alerts ───────────────────────────────────────────── */
.alert {
  padding: 0.9rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  border: 1px solid transparent;
}

/* Links inside a tinted alert take the alert's own colour, underlined,
   so they never sit blue-on-blue */
.alert a,
.alert a:visited,
.alert strong {
  color: inherit;
}

.alert a {
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 600;
}

.alert-success { background: var(--tone-green-bg); border-color: var(--tone-green-bd); color: var(--tone-green-fg); }
.alert-danger  { background: var(--tone-red-bg);   border-color: var(--tone-red-bd);   color: var(--tone-red-fg); }
.alert-info    { background: var(--tone-blue-bg);  border-color: var(--tone-blue-bd);  color: var(--tone-blue-fg); }
.alert-warning { background: var(--tone-amber-bg); border-color: var(--tone-amber-bd); color: var(--tone-amber-fg); }

.key-banner {
  background: var(--tone-blue-bg);
  border: 1px solid var(--tone-blue-bd);
  color: var(--text-strong);
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 1rem;
  font-family: var(--font-mono);
  word-break: break-all;
}

/* ── Tables ───────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--bg-table-head);
  font-family: var(--font-display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.85rem;
  color: var(--text-label);
}

tbody tr:hover td {
  background: var(--bg-row-hover);
}

.row-unacknowledged td {
  background: var(--tone-red-bg);
}

/* Sortable / filterable tables (js/tables.js, DataTables 3). As in the
   EdgeDock app's DataTable.css: keep the app's own cell spacing, borders and
   colours rather than DataTables' defaults, and strip the margin it puts
   round the table. :root[data-theme] outranks DataTables' own dark-mode
   arrow colours; the tokens already follow the theme. */
:root,
:root[data-theme] {
  --dt-order-arrow_color: var(--text-label);
  --dt-order-arrow_color-current: var(--accent-text);
  --dt-order-header_outline-hover: 2px solid rgb(var(--ed-blue-light) / 0.35);
}

div.dt-container div.dt-layout-row.dt-layout-table {
  margin: 0;
}

table.dataTable > thead > tr > th,
table.dataTable > tbody > tr > td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

table.dataTable > tbody > tr:last-child > td {
  border-bottom: 1px solid var(--border);
}

table.dataTable > thead > tr.dt-filter-row > td {
  padding: 0.4rem 0.5rem;
  background: var(--bg-table-head);
  border-bottom: 1px solid var(--border);
}

.dt-filter {
  width: 100%;
  min-width: 3.5rem;
  padding: 0.3rem 0.5rem;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 4px;
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
}

.dt-filter::placeholder {
  color: var(--text-muted);
  opacity: 0.8;
}

.dt-filter:focus {
  outline: none;
  border-color: rgb(var(--ed-blue-light) / 0.8);
  box-shadow: 0 0 0 2px rgb(var(--ed-blue-light) / 0.25);
}

table.dataTable td.dt-empty {
  color: var(--text-muted);
  text-align: left;
}

/* ── Badges ───────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.badge-open,
.badge-mode-scheduled {
  background: var(--tone-blue-bg); color: var(--tone-blue-fg); border-color: var(--tone-blue-bd);
}

.badge-closed,
.badge-cat-feedback,
.badge-access-open,
.badge-mode-on {
  background: var(--tone-green-bg); color: var(--tone-green-fg); border-color: var(--tone-green-bd);
}

.badge-in_progress,
.badge-stale,
.badge-exception {
  background: var(--tone-amber-bg); color: var(--tone-amber-fg); border-color: var(--tone-amber-bd);
}

.badge-cat-error,
.badge-cat-crash {
  background: var(--tone-orange-bg); color: var(--tone-orange-fg); border-color: var(--tone-orange-bd);
}

.badge-cat-bug {
  background: var(--tone-red-bg); color: var(--tone-red-fg); border-color: var(--tone-red-bd);
}

.badge-cat-question {
  background: var(--tone-purple-bg); color: var(--tone-purple-fg); border-color: var(--tone-purple-bd);
}

.badge-inactive,
.badge-access-closed,
.badge-mode-off,
.badge[class*="badge-event-"] {
  background: var(--tone-gray-bg); color: var(--tone-gray-fg); border-color: var(--tone-gray-bd);
}

.badge.badge-alert-emergency_open,
.badge.badge-event-emergency_open {
  background: var(--tone-red-bg); color: var(--tone-red-fg); border-color: var(--tone-red-bd);
}

.badge.badge-alert-lease_started,
.badge.badge-event-lease_started {
  background: var(--tone-orange-bg); color: var(--tone-orange-fg); border-color: var(--tone-orange-bd);
}

.badge.badge-alert-visit_declined,
.badge.badge-alert-visit_cancelled,
.badge-visit-times_declined,
.badge-reboot-open {
  background: var(--tone-amber-bg); color: var(--tone-amber-fg); border-color: var(--tone-amber-bd);
}

.badge.badge-alert-visit_ready,
.badge-visit-scheduled {
  background: var(--tone-blue-bg); color: var(--tone-blue-fg); border-color: var(--tone-blue-bd);
}

.badge-visit-awaiting_reply {
  background: var(--tone-purple-bg); color: var(--tone-purple-fg); border-color: var(--tone-purple-bd);
}

.badge-visit-completed,
.badge-reboot-done {
  background: var(--tone-green-bg); color: var(--tone-green-fg); border-color: var(--tone-green-bd);
}

.badge-visit-cancelled,
.badge-visit-expired,
.badge-reboot-cancelled,
.badge-reboot-converted {
  background: var(--tone-gray-bg); color: var(--tone-gray-fg); border-color: var(--tone-gray-bd);
}

.badge.badge-event-shipped {
  background: var(--tone-blue-bg); color: var(--tone-blue-fg); border-color: var(--tone-blue-bd);
}

.badge.badge-event-initialized {
  background: var(--tone-green-bg); color: var(--tone-green-fg); border-color: var(--tone-green-bd);
}

/* ── Stat cards ───────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  text-align: center;
  transition: border-color 0.25s, box-shadow 0.25s, transform 0.25s;
}

/* Stat cards nested in a panel sit on an inset surface so they separate from it */
.panel .stat-card {
  background: var(--bg-inset);
}

.stat-card:hover {
  border-color: var(--border-accent);
  box-shadow: var(--ed-glow);
  transform: translateY(-2px);
}

.stat-value {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--accent-text);
}

.stat-value a,
.stat-value a:visited {
  color: inherit;
}

.stat-label {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-card-alert {
  border-color: var(--tone-red-bd);
  background: var(--tone-red-bg) !important;
}

.stat-card-alert .stat-value {
  color: var(--tone-red-fg);
}

.stat-card-warning {
  border-color: var(--tone-amber-bd);
  background: var(--tone-amber-bg) !important;
}

.stat-card-warning .stat-value {
  color: var(--tone-amber-fg);
}

/* A whole stat card that links to the page with the detail */
a.stat-card-link,
a.stat-card-link:visited {
  display: block;
  color: inherit;
  text-decoration: none;
}

/* ── Dashboard ────────────────────────────────────────── */
.dashboard-clear {
  margin: 0 0 2rem;
  color: var(--text-muted);
}

.activity-heading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.activity-status {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tone-green-fg);
}

.activity-status::before {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.35rem;
  border-radius: 50%;
  background: currentColor;
  vertical-align: 0.05rem;
  animation: activity-pulse 2s ease-in-out infinite;
}

.activity-status-paused {
  color: var(--text-muted);
}

.activity-status-paused::before {
  animation: none;
}

@keyframes activity-pulse {
  50% { opacity: 0.3; }
}

.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 32rem;
  overflow-y: auto;
  border-top: 1px solid var(--border);
}

.activity-row,
.activity-row:visited {
  display: grid;
  grid-template-columns: 9.5rem 11rem minmax(8rem, 14rem) 1fr;
  gap: 0.75rem;
  align-items: baseline;
  padding: 0.45rem 0.25rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-main);
  text-decoration: none;
}

.activity-row:hover {
  background: var(--bg-row-hover);
}

.activity-time {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.activity-site,
.activity-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.activity-new .activity-row {
  animation: activity-arrive 3s ease-out;
}

@keyframes activity-arrive {
  from { background: rgb(var(--ed-blue) / 0.25); }
  to { background: transparent; }
}

@media (max-width: 900px) {
  .activity-row {
    grid-template-columns: auto 1fr;
  }

  .activity-text {
    grid-column: 1 / -1;
    white-space: normal;
  }
}

.badge-logs,
.badge-booking {
  background: var(--tone-blue-bg); color: var(--tone-blue-fg); border-color: var(--tone-blue-bd);
}

.badge-booking-released {
  background: var(--tone-gray-bg); color: var(--tone-gray-fg); border-color: var(--tone-gray-bd);
}

/* ── Pagination ───────────────────────────────────────── */
.pagination {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1.5rem;
}

.pagination a,
.pagination a:visited,
.pagination span {
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  color: var(--text-main);
  border: 1px solid var(--border-input);
  text-decoration: none;
}

.pagination a:hover {
  border-color: rgb(var(--ed-blue-light) / 0.6);
  background: var(--bg-row-hover);
}

.pagination .current {
  background: var(--btn-primary);
  border-color: var(--btn-primary);
  color: #fff;
}

/* ── Login ────────────────────────────────────────────── */
/* Mirrors the EdgeDock application's login page (Login.tsx, .ed-hero): always
   dark whatever the theme, glowing logo above a translucent card. */
.login-page {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  overflow-x: hidden;
  overflow-y: auto;
  color: #fff;
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, rgb(var(--ed-blue) / 0.15) 0%, transparent 70%),
    linear-gradient(160deg, #0d1117 0%, #1e2530 100%);
}

.login-page::before {
  content: '';
  position: fixed;
  inset: -60px 0 0 -60px;
  background-image:
    linear-gradient(rgb(var(--ed-blue) / 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgb(var(--ed-blue) / 0.08) 1px, transparent 1px);
  background-size: 60px 60px;
  -webkit-mask-image: radial-gradient(ellipse 75% 70% at 50% 45%, #000 20%, transparent 80%);
  mask-image: radial-gradient(ellipse 75% 70% at 50% 45%, #000 20%, transparent 80%);
  animation: ed-grid-drift 24s linear infinite;
  pointer-events: none;
}

.login-page > * {
  position: relative;
  z-index: 1;
}

.login-logo {
  flex-shrink: 0;
  width: 16rem;
  height: 16rem;
  margin-bottom: -1rem;
  filter: drop-shadow(0 0 30px rgb(26 111 196 / 0.35));
}

.login-card {
  flex-shrink: 0;
  width: 20rem;
  max-width: 100%;
  padding: 1.5rem;
  border-radius: 8px;
  background: rgb(22 27 34 / 0.9);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid rgb(var(--ed-blue) / 0.3);
  box-shadow: 0 0 0 1px rgb(46 141 232 / 0.35), 0 8px 28px rgb(26 111 196 / 0.22);
}

.login-title {
  margin: 0 0 1.25rem;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.025em;
  line-height: 1.25;
  color: #fff;
}

.login-title::after {
  content: '';
  display: block;
  width: 44px;
  height: 3px;
  margin-top: 8px;
  border-radius: 2px;
  background: linear-gradient(90deg, #1a6fc4, #2e8de8);
  box-shadow: 0 0 10px rgb(var(--ed-blue-light) / 0.55);
}

.login-message {
  margin: 0 0 1rem;
  padding: 0.75rem;
  border-radius: 4px;
  font-size: 0.875rem;
  color: #e2e8f0;
  background: rgb(var(--ed-blue) / 0.15);
  border: 1px solid rgb(var(--ed-blue) / 0.4);
}

.login-message-danger {
  margin-bottom: 0.5rem;
  padding: 0;
  color: #f87171;
  background: none;
  border: 0;
}

.login-input {
  display: block;
  width: 100%;
  margin-bottom: 0.5rem;
  padding: 0.5rem;
  border: 0;
  border-radius: 4px;
  background: #fff;
  color: #000;
  font-family: inherit;
  font-size: 1rem;
  outline: none;
  transition: box-shadow 0.15s;
}

.login-input-last {
  margin-bottom: 1rem;
}

.login-input:focus {
  box-shadow: 0 0 0 2px #2e8de8, 0 0 14px rgb(46 141 232 / 0.45);
}

.login-button {
  width: 100%;
  padding: 0.5rem;
  border: 0;
  border-radius: 4px;
  background: #2563eb;
  color: #fff;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
}

.login-button:hover {
  background: #2e8de8;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Utilities ────────────────────────────────────────── */
.text-muted {
  color: var(--text-muted);
}

.text-danger {
  color: var(--text-danger);
}

.small {
  font-size: 0.875rem;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

pre.json {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-main);
}

.snapshot + .snapshot {
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

pre.diff .diff-add { color: var(--diff-add); }
pre.diff .diff-del { color: var(--diff-del); }
pre.diff .diff-hunk { color: var(--text-muted); }

/* ── Maintenance calendar ─────────────────────────────── */
table.calendar th,
table.calendar td {
  padding: 0.2rem 0.4rem;
  text-align: center;
  font-size: 0.85rem;
}

table.calendar td.cal-cell a,
table.calendar td.cal-cell a:visited {
  display: block;
  color: var(--text-muted);
  text-decoration: none;
}

table.calendar td.cal-open {
  background: rgb(var(--cal-rgb) / var(--cal-level, 0.3));
}

table.calendar td.cal-open a,
table.calendar td.cal-open a:visited,
table.calendar td.cal-open .cal-slot {
  color: var(--cal-text);
  font-weight: 600;
}

table.calendar td.cal-now {
  outline: 2px solid var(--cal-now);
  outline-offset: -2px;
}

table.calendar td.cal-selected {
  outline: 2px solid var(--text-strong);
  outline-offset: -2px;
}

table.calendar .cal-slot {
  margin-top: 0.15rem;
  padding: 0 0.25rem;
  border-left: 3px solid #a78bfa;
  font-size: 0.7rem;
  white-space: nowrap;
  text-align: left;
  color: var(--text-muted);
}

table.calendar .cal-slot-full {
  border-left-color: #f87171;
}

table.calendar .cal-visit {
  margin-top: 0.15rem;
  padding: 0 0.25rem;
  border-left: 3px solid #34d399;
  font-size: 0.7rem;
  white-space: nowrap;
  text-align: left;
}

table.calendar .cal-visit a,
table.calendar td.cal-open .cal-visit a {
  display: inline;
  color: var(--text-main);
  font-weight: 600;
}

.cal-legend li {
  margin-bottom: 0.4rem;
}

.cal-legend .cal-swatch {
  display: inline-block;
  width: 1.75rem;
  height: 1.25rem;
  line-height: 1.25rem;
  text-align: center;
  vertical-align: middle;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.cal-legend .cal-swatch-open {
  background: rgb(var(--cal-rgb) / 0.6);
  color: var(--cal-text);
  font-weight: 600;
}

.cal-legend .cal-swatch-now {
  outline: 2px solid var(--cal-now);
  outline-offset: -2px;
}

.cal-legend .cal-swatch-selected {
  outline: 2px solid var(--text-strong);
  outline-offset: -2px;
}

.cal-legend .cal-swatch-bar {
  display: inline-block;
  padding: 0 0.25rem;
  font-size: 0.7rem;
}

.cal-legend .cal-slot {
  border-left: 3px solid #a78bfa;
}

.cal-legend .cal-slot-full {
  border-left-color: #f87171;
}

.cal-legend .cal-visit {
  border-left: 3px solid #34d399;
}

td.actions details {
  display: inline-block;
}

td.actions details summary {
  list-style: none;
}

td.actions details[open] {
  display: block;
  margin-top: 0.5rem;
}

@media (prefers-reduced-motion: reduce) {
  .ed-workspace-bg::before,
  .login-page::before { animation: none; }
  .stat-card:hover { transform: none; }
  .activity-status::before,
  .activity-new .activity-row { animation: none; }
}

@media (max-width: 900px) {
  .container {
    padding: 1rem;
  }
}
