:root {
  --bg: #0d0f13;
  --surface: #14171d;
  --surface-2: #1a1e26;
  --elevated: #222733;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #eceef3;
  --text-2: #a7adba;
  --text-3: #6f7685;
  --accent: #e5484d;
  --accent-soft: rgba(229, 72, 77, 0.14);
  --ok: #3dd68c;
  --ok-soft: rgba(61, 214, 140, 0.14);
  --warn: #f5a524;
  --warn-soft: rgba(245, 165, 36, 0.14);
  --info: #4f9cf9;
  --radius: 10px;
  --radius-sm: 7px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
}

[hidden] { display: none !important; }

.skip {
  position: absolute; left: -999px; top: 8px;
  background: var(--accent); color: #fff; padding: 6px 12px; border-radius: var(--radius-sm);
}
.skip:focus { left: 8px; z-index: 10; }

:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; }

h1, h2 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
.muted { color: var(--text-2); }
.error { color: #ff8a8e; min-height: 1.5em; margin: 0; }

/* ---- controls */
input, select {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font: inherit;
  transition: border-color 160ms var(--ease);
}
input:hover, select:hover { border-color: rgba(255, 255, 255, 0.26); }
input:focus, select:focus { border-color: var(--info); outline: none; }
input[type="date"] { color-scheme: dark; }

label { display: grid; gap: 6px; color: var(--text-2); font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--elevated);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font: inherit; font-weight: 550;
  cursor: pointer;
  transition: background-color 160ms var(--ease), transform 120ms var(--ease);
  white-space: nowrap;
}
.btn:hover { background: #2b3140; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #ee5a5f; }
.btn.danger { background: transparent; border-color: rgba(229, 72, 77, 0.6); color: #ff8a8e; }
.btn.danger:hover { background: var(--accent-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }

/* ---- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%);
  display: grid; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 32px 28px;
  text-align: center;
}
.login-card img { justify-self: center; border-radius: 14px; }
.login-card label { text-align: left; margin-top: 8px; }
.login-card p { margin: 0; }

/* ---- layout */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 32px;
  background: rgba(13, 15, 19, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { border-radius: 8px; }
.brand div { display: grid; line-height: 1.25; }
.brand span { font-size: 12.5px; }
.top-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 28px 32px 64px; display: grid; gap: 20px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; display: grid; gap: 2px;
}
.stat-v { font-size: 28px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-l { color: var(--text-2); font-size: 12.5px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; display: grid; gap: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.card-head input { max-width: 300px; }

.grid-form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px 16px; align-items: end; }
.grid-form .wide { grid-column: span 3; }
.grid-form .form-actions { display: flex; justify-content: flex-end; grid-column: 1 / -1; }

/* ---- table */
.table-wrap { overflow-x: auto; margin: 0 -22px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; font-weight: 550; color: var(--text-3); font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 8px 12px; border-bottom: 1px solid var(--line);
}
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th:first-child, td:first-child { padding-left: 22px; }
th:last-child, td:last-child { padding-right: 22px; }
tbody tr.lic:hover { background: rgba(255, 255, 255, 0.02); }
.mono { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }
.sub { display: block; color: var(--text-3); font-size: 12px; }
.row-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.empty { padding: 12px 22px; margin: 0; }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 99px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.off { background: var(--accent-soft); color: #ff8a8e; }

tr.acts td { background: var(--surface-2); padding-top: 6px; padding-bottom: 10px; }
.act-list { display: grid; gap: 6px; }
.act {
  display: grid; grid-template-columns: minmax(160px, 1.3fr) minmax(130px, 1fr) minmax(130px, 1fr) minmax(120px, 1fr) auto;
  gap: 12px; align-items: center;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
}
.act-none { color: var(--text-3); font-size: 13px; }

/* ---- events */
.events { list-style: none; margin: 0; padding: 0; display: grid; max-height: 360px; overflow: auto; }
.events li {
  display: grid; grid-template-columns: 140px 190px 1fr auto; gap: 12px;
  padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px;
}
.events time { color: var(--text-3); font-variant-numeric: tabular-nums; }

/* ---- dialogs */
.dlg {
  width: min(560px, calc(100% - 32px));
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: 14px;
  padding: 24px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}
.dlg::backdrop { background: rgba(0, 0, 0, 0.6); }
.dlg form { display: grid; gap: 14px; }
.dlg .grid-form { grid-template-columns: 1fr 1fr; }
.dlg .grid-form .wide { grid-column: span 2; }
.dlg p { margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.key {
  display: block; text-align: center;
  font-family: var(--mono); font-size: 20px; letter-spacing: 0.06em;
  background: var(--bg); border: 1px dashed var(--line-strong); border-radius: var(--radius-sm);
  padding: 16px; user-select: all; word-break: break-all;
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px);
  background: var(--elevated); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 10px 16px; opacity: 0; pointer-events: none;
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
  max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { border-color: rgba(229, 72, 77, 0.6); }

@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-form { grid-template-columns: 1fr 1fr; }
  .grid-form .wide { grid-column: span 2; }
  .act { grid-template-columns: 1fr 1fr; }
  .events li { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .top { padding: 10px 16px; flex-wrap: wrap; }
  .wrap { padding: 20px 16px 48px; }
  .grid-form, .dlg .grid-form { grid-template-columns: 1fr; }
  .grid-form .wide, .dlg .grid-form .wide { grid-column: span 1; }
  .card-head { flex-direction: column; align-items: stretch; }
  .card-head input { max-width: none; }
  .table-wrap { margin: 0 -22px; }
  .events li { grid-template-columns: 1fr; gap: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
