:root {
  --bg: #0a0a0b;
  --panel: #121214;
  --raised: #17171a;
  --field: #1b1b1e;
  --border: #2c2c31;
  --border-strong: #3a3a40;
  --text: #ededef;
  --muted: #8b8b93;
  --dim: #5c5c64;
  --accent: #ededef;
  --accent-text: #0a0a0b;
  --radius: 8px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- controls ---------- */
input, select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  outline: none;
}
input:focus, select:focus { border-color: #9a9aa2; }
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.7); }
label { display: block; margin-bottom: 14px; }
label > span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }

.btn {
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--field);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: #9a9aa2; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: #fff; }
.btn.ghost { background: transparent; }
.icon-btn {
  width: 32px; height: 32px;
  border: 0; border-radius: var(--radius);
  background: transparent; color: var(--muted);
  font-size: 20px; cursor: pointer;
}
.icon-btn:hover { background: var(--field); color: var(--text); }

.form-error { min-height: 18px; margin: 10px 0 0; color: var(--text); font-size: 13px; }
.form-error:not(:empty)::before { content: "! "; color: var(--muted); }
.hint { color: var(--dim); font-size: 12px; margin: -4px 0 0; }

/* ---------- sign in ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; position: relative; }
.login-card {
  width: 100%; max-width: 360px;
  padding: 32px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.login-card h1 { margin-bottom: 28px; }
.login-card .btn { width: 100%; height: 42px; margin-top: 10px; }
.login .lang-select { position: absolute; top: 16px; right: 16px; width: auto; height: 32px; }

/* ---------- app shell ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: 56px; padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 600; font-size: 15px; }
.brand span { color: var(--muted); font-weight: 400; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar .lang-select { width: auto; height: 32px; }
.content { max-width: 1200px; margin: 0 auto; padding: 24px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .value { font-size: 22px; font-weight: 600; margin-top: 2px; }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; }
.toolbar .search { flex: 1; height: 36px; }
.toolbar .filter { width: 160px; height: 36px; }

/* ---------- table ---------- */
.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--muted);
  padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--raised); }
.table td:last-child { text-align: right; width: 1%; white-space: nowrap; }
.user-name { font-weight: 500; }
.empty { padding: 28px; text-align: center; color: var(--muted); margin: 0; }

.badge {
  display: inline-block; padding: 2px 8px;
  border: 1px solid var(--border); border-radius: 999px;
  font-size: 12px; color: var(--muted); white-space: nowrap;
}
.badge.on { color: var(--text); border-color: var(--border-strong); }
.badge.off { color: var(--dim); text-decoration: line-through; }
.badge.warn { color: var(--text); border-style: dashed; }

/* ---------- row menu ---------- */
.menu {
  position: fixed; z-index: 30; min-width: 180px; padding: 4px;
  background: var(--raised); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
}
.menu button {
  display: block; width: 100%; text-align: left;
  padding: 8px 10px; border: 0; border-radius: 6px;
  background: transparent; color: var(--text); font: inherit; cursor: pointer;
}
.menu button:hover { background: var(--field); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* ---------- drawer ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 10; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 20;
  width: min(440px, 100%);
  display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--border);
}
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.drawer-section { padding: 18px 24px; border-bottom: 1px solid var(--border); }
.drawer-section.grow { flex: 1; overflow-y: auto; border-bottom: 0; }
.drawer .big { font-size: 18px; font-weight: 600; margin-top: 4px; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0 16px; }
.quick .btn { padding: 0 6px; }
.grant { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grant .btn { grid-column: 1 / -1; height: 38px; }

.license-list { list-style: none; margin: 10px 0 0; padding: 0; }
.license-list li {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.license-list li:last-child { border-bottom: 0; }
.license-list .range { font-weight: 500; }
.license-list .meta { grid-column: 1; color: var(--muted); font-size: 12px; }
.license-list .btn { grid-row: 1 / span 2; grid-column: 2; height: 30px; font-size: 12px; }

/* ---------- dialogs ---------- */
.dialog {
  width: min(420px, calc(100% - 32px));
  padding: 24px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 12px;
}
.dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dialog h2 { margin-bottom: 18px; }
.dialog.small h2 { margin-bottom: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.with-btn { display: flex; gap: 8px; }
.with-btn .btn { height: 40px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 40; display: grid; gap: 8px; pointer-events: none; }
.toast {
  padding: 10px 14px; max-width: 360px;
  background: var(--raised); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  animation: toast-in .15s ease-out;
}
.toast.error { border-style: dashed; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  #me-name { display: none; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { flex-wrap: wrap; }
  .toolbar .search { flex-basis: 100%; }
  .toolbar .filter { flex: 1; width: auto; }
  .table th:nth-child(5), .table td:nth-child(5) { display: none; }
}
