/* Znuny corporate design (www.znuny.com / keycloak-skin tokens):
   Open Sans, dark top bar, purple primary, orange accent, rounded surfaces.
   Light/dark follows prefers-color-scheme; data-theme on <html> overrides it. */

@font-face {
  font-family: 'Open Sans';
  src: url('fonts/OpenSans.woff2') format('woff2');
  font-weight: 300 800;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #f4f5f7;           /* blackish-50 */
  --surface: #ffffff;
  --surface-alt: #f9fafb;
  --text: #212327;         /* blackish-950 */
  --muted: #626d78;        /* blackish-500 */
  --border: #e4e7e9;       /* blackish-100 */
  --border-strong: #ccd1d5;/* blackish-200 */
  --line: #eceef0;
  --line-hour: #d5dade;
  --link: #7f30f7;         /* purple-600 */
  --primary: #8a4fff;      /* purple-500 */
  --primary-hover: #7f30f7;
  --primary-text: #ffffff;
  --accent: #fe8a26;       /* Znuny orange */
  --bar: #212327;
  --bar-text: #ffffff;
  --bar-muted: #a8b0b8;
  --bar-line: #484e56;
  --usage: #8a4fff;        /* purple-500 */
  --maint: #1f9d55;
  --weekend: #f9fafb;
  --error: #be1e4a;
  --focus: 0 0 0 3px rgba(138, 79, 255, .35);
  --shadow: 0 1px 2px rgba(33, 35, 39, .06), 0 8px 32px rgba(33, 35, 39, .06);
  --radius: 16px;
  --radius-sm: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #17181b;
    --surface: #212327;
    --surface-alt: #1b1c20;
    --text: #e4e7e9;
    --muted: #a8b0b8;
    --border: #34373d;
    --border-strong: #484e56;
    --line: #2b2e33;
    --line-hour: #3d4148;
    --link: #a885ff;
    --primary-text: #ffffff;
    --bar: #0f1012;
    --bar-line: #34373d;
    --usage: #9466ff;
    --maint: #2fb46a;
    --weekend: #1d1f23;
    --error: #f08aa5;
    --focus: 0 0 0 3px rgba(168, 133, 255, .45);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 32px rgba(0, 0, 0, .25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #17181b;
  --surface: #212327;
  --surface-alt: #1b1c20;
  --text: #e4e7e9;
  --muted: #a8b0b8;
  --border: #34373d;
  --border-strong: #484e56;
  --line: #2b2e33;
  --line-hour: #3d4148;
  --link: #a885ff;
  --primary-text: #ffffff;
  --bar: #0f1012;
  --bar-line: #34373d;
  --usage: #9466ff;
  --maint: #2fb46a;
  --weekend: #1d1f23;
  --error: #f08aa5;
  --focus: 0 0 0 3px rgba(168, 133, 255, .45);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 32px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.wrap { max-width: 1000px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-bottom: 48px; }
h1 { font-size: 1.85rem; font-weight: 700; letter-spacing: -.02em; margin: 36px 0 8px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.lead { color: var(--muted); max-width: 70ch; margin: 0 0 20px; }
.hint, .muted { color: var(--muted); font-size: .9rem; }
.hint { margin: 8px 0 12px; }
small { color: var(--muted); font-weight: normal; }
a { color: var(--link); }

.topbar { background: var(--bar); color: var(--bar-text); }
.topbar-inner { display: flex; align-items: center; gap: 18px; min-height: 64px; }
.brand { display: flex; align-items: center; gap: 18px; font-size: 1.05rem; font-weight: 600; letter-spacing: -.01em; color: var(--bar-text); text-decoration: none; }
.brand img { width: 112px; height: 28px; display: block; }
.brand span { padding-left: 18px; border-left: 1px solid var(--bar-line); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.langs a { margin-left: 10px; text-decoration: none; color: var(--bar-muted); font-weight: 600; font-size: .85rem; }
.langs a:hover { color: var(--bar-text); }
.langs a.active { color: var(--bar-text); border-bottom: 2px solid var(--accent); }
.theme-toggle { background: transparent; border: 1px solid var(--bar-line); color: var(--bar-muted); padding: 4px 8px; border-radius: 8px; font-size: .8rem; }
.theme-toggle:hover { color: var(--bar-text); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px 24px; margin-bottom: 16px; box-shadow: var(--shadow); }

.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px 16px; align-items: end; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .9rem; }
input, select, textarea {
  font: inherit; font-weight: normal; color: var(--text); background: var(--surface-alt);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 9px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: none; box-shadow: var(--focus); border-color: var(--primary); }
.readonly { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; margin: 0; }
.readonly dt { font-weight: 600; font-size: .85rem; color: var(--muted); }
.readonly dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.notice { margin-top: 8px; }
.tz-info { padding: 8px 0; }

button, .button {
  font: inherit; cursor: pointer; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); padding: 7px 12px; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
}
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; padding: 11px 30px; font-size: 1rem; border-radius: 999px; }
button.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button.ghost, .button.ghost { background: transparent; }
button.small { padding: 3px 8px; font-size: .8rem; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin-bottom: 12px; }
.toolbar label { flex-direction: row; align-items: center; gap: 8px; }
.toolbar select { width: auto; }
.spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg button, .seg .button { border: 0; border-radius: 0; border-right: 1px solid var(--border-strong); }
.seg button:last-child, .seg .button:last-child { border-right: 0; }
.seg button.active, .seg .button.active { background: var(--text); color: var(--surface); }

.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: none; }
.s-usage { background: var(--usage); }
.s-maint { background: var(--maint); }
.s-none { background: transparent; border: 1px dashed var(--muted); }
.legend, .summary { display: flex; flex-wrap: wrap; gap: 6px 20px; font-size: .88rem; color: var(--muted); margin: 0 0 10px; }
.legend > span, .summary > span { display: inline-flex; align-items: center; gap: 6px; }
.summary { margin: 12px 0 0; color: var(--text); }

/* ------------------------------------------------- schedule (ruler style) */
/* Rows = days, columns = 48 half-hour slots. Hour boundaries are solid lines,
   the 30-minute mark a tick from the bottom. */
.sched-scroll { overflow-x: auto; margin: 0 -4px; padding: 0 4px 4px; }
.sched {
  --label-w: 48px;
  --row-h: 44px;
  --tick: var(--border-strong);
  position: relative;
  display: flex; flex-direction: column; gap: 10px;
  min-width: 640px;
  padding: 0 14px 0 0;              /* room for the "24" label */
  user-select: none; -webkit-user-select: none;
}
.day-row, .axis { display: grid; grid-template-columns: var(--label-w) 1fr; align-items: center; }
.day-head {
  border: 0; background: transparent; padding: 0; border-radius: 6px;
  font-weight: 700; font-size: .95rem; color: var(--text); justify-content: flex-start; height: 100%;
}
.day-row.weekend .day-head { color: var(--accent); }
.day-head:hover { color: var(--link); }

.strip {
  display: grid; grid-template-columns: repeat(48, minmax(0, 1fr));
  height: var(--row-h);
  border: 1px solid var(--border-strong); border-radius: 6px; overflow: hidden;
  background: var(--surface); touch-action: none;
}
.day-row.weekend .strip { background: var(--weekend); }
.cell { position: relative; cursor: crosshair; transition: background-color .06s; }
.cell.hour:not(:first-child) { box-shadow: inset 1px 0 0 var(--border-strong); }
.cell.half::before {                  /* 30 min tick */
  content: ""; position: absolute; bottom: 0; left: 0; width: 1px; height: 18px;
  background: var(--tick); pointer-events: none;
}
.cell.usage { background: var(--usage); }
.cell.maint { background: var(--maint); }
.cell.usage, .cell.maint { --tick: rgba(255, 255, 255, .45); }
.cell.usage.hour:not(:first-child), .cell.maint.hour:not(:first-child) { box-shadow: inset 1px 0 0 rgba(255, 255, 255, .35); }
.cell.now { box-shadow: inset 0 0 0 2px var(--accent) !important; }
.sched:not(.painting) .cell:hover { box-shadow: inset 0 0 0 2px var(--text); }
.sched[data-brush="1"]:not(.painting) .cell:not(.usage):hover { background: color-mix(in srgb, var(--usage) 35%, transparent); }
.sched[data-brush="2"]:not(.painting) .cell:not(.maint):hover { background: color-mix(in srgb, var(--maint) 35%, transparent); }

.axis-track { position: relative; height: 26px; display: grid; grid-template-columns: repeat(48, minmax(0, 1fr)); }
.axis-label {
  position: absolute; top: 50%; transform: translate(-50%, -50%);
  font-weight: 700; font-size: .9rem; color: var(--text); pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.col-head { border: 0; border-radius: 4px 4px 0 0; background: transparent; padding: 0; height: 100%; }
.col-head:hover { background: color-mix(in srgb, var(--link) 18%, transparent); }

.grid-hint {
  position: absolute; left: calc(var(--label-w) + 20%); right: 20%; top: 50%; transform: translateY(-50%);
  background: color-mix(in srgb, var(--surface) 88%, var(--link));
  border: 1px solid color-mix(in srgb, var(--border-strong) 60%, var(--link));
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 22px 28px; text-align: center; font-size: 1.05rem; pointer-events: none;
}
.grid-hint[hidden] { display: none; }
.readout { margin-left: auto; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; min-height: 1.4em; }

/* admin heatmaps: same layout, numbers instead of ticks */
.heat-stack { display: grid; gap: 16px; margin-bottom: 16px; }
.heat-stack .card { margin-bottom: 0; }
.heat .cell { cursor: default; font-size: .6rem; line-height: var(--row-h); text-align: center; color: #fff; }
.heat .cell.half::before { display: none; }
.heat { --row-h: 30px; gap: 6px; }
.heat.usage .cell { background: color-mix(in srgb, var(--usage) calc(var(--a) * 100%), transparent); }
.heat.maint .cell { background: color-mix(in srgb, var(--maint) calc(var(--a) * 100%), transparent); }
.heat .day-head { cursor: default; }

table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.table-scroll { overflow-x: auto; }
.nowrap { white-space: nowrap; }
td.comment { max-width: 280px; white-space: pre-wrap; }

.error { color: var(--error); font-weight: 600; }
.thanks { margin-top: 32px; text-align: center; padding: 40px 20px; }

@media (max-width: 600px) {
  .card { padding: 16px 14px; }
  .brand img { width: 96px; height: 24px; }
  .brand span { display: none; }
  .sched { --label-w: 34px; --row-h: 40px; }
  .axis-label.minor { display: none; }
  .grid-hint { left: 10%; right: 10%; padding: 14px; font-size: .95rem; }
}

/* ------------------------------------------------------ environment tabs */
.env-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 8px; }
.env-tab {
  flex-direction: column; align-items: flex-start; gap: 0; padding: 10px 18px; min-width: 180px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-alt);
}
.env-tab .env-name { font-weight: 700; }
.env-tab .env-badge { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.env-tab .env-badge.empty { color: var(--error); }
.env-tab.active { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, var(--surface)); box-shadow: inset 0 -3px 0 var(--primary); }
.saved-note { margin: 10px 0 0; padding: 8px 12px; border-radius: var(--radius-sm); font-size: .9rem;
  background: color-mix(in srgb, var(--maint) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--maint) 35%, var(--border)); }

/* ------------------------------------------------------------- admin */
.admin-nav { display: flex; gap: 6px; margin: 24px 0 0; }
.admin-nav a { padding: 6px 14px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .9rem; }
.admin-nav a.active { background: var(--text); color: var(--surface); }
.admin-nav { align-items: center; flex-wrap: wrap; }
.admin-user { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.admin-logout { margin: 0; }
.list tbody tr { cursor: pointer; }
.list tbody tr:hover { background: var(--surface-alt); }
.list td a.rowlink { color: var(--text); font-weight: 600; text-decoration: none; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.badge.pending { background: color-mix(in srgb, var(--muted) 18%, transparent); color: var(--muted); }
.badge.completed { background: color-mix(in srgb, var(--maint) 18%, transparent); color: var(--maint); }
.badge.update-requested { background: color-mix(in srgb, var(--accent) 20%, transparent); color: color-mix(in srgb, var(--accent) 80%, var(--text)); }
.envmark { display: inline-flex; align-items: center; gap: 4px; margin-right: 10px; font-size: .85rem; white-space: nowrap; }
.envmark .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); }
.envmark.ok .dot { background: var(--maint); }
.ranges { margin: 0; padding: 0; list-style: none; font-variant-numeric: tabular-nums; }
.ranges li { padding: 1px 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.kv dt { color: var(--muted); font-weight: 600; font-size: .88rem; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row button { flex: none; white-space: nowrap; }
.copy-row input { font-family: ui-monospace, Menlo, monospace; font-size: .82rem; }
.env-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px 24px; margin-bottom: 14px; }
.env-cols h3 { margin: 0 0 4px; font-size: .9rem; display: flex; align-items: center; gap: 6px; }
.view .cell { cursor: default; }
.new-inv summary { cursor: pointer; font-weight: 600; }
.new-inv form { margin-top: 12px; }
.danger { color: var(--error); border-color: color-mix(in srgb, var(--error) 50%, var(--border)); }
