:root {
  --bg: #0A0C10;
  --panel: #12151C;
  --panel-2: #171B24;
  --border: #242A36;
  --text: #ECE9E0;
  --muted: #9A9A92;
  --accent: #F2C230;
  --good: #63D2A4;
  --warn: #FF9A6B;
  --offline: #6B7080;
  --radius: 10px;
  --head: "Barlow Condensed", "Arial Narrow", sans-serif;
  --body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--body); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { font-family: var(--head); font-weight: 600; letter-spacing: 0.02em; margin: 0; }
h1 { font-size: 30px; text-transform: uppercase; }
h2 { font-size: 20px; text-transform: uppercase; color: var(--muted); margin-bottom: 12px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

button, input, select { font: inherit; color: inherit; }
input, select {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; width: 100%;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 16px; cursor: pointer;
  font-weight: 500;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); color: #14120A; border-color: var(--accent); font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.ghost { background: transparent; }
button.small { padding: 5px 10px; font-size: 13px; }
.link-button { background: none; border: none; padding: 0; color: var(--muted); font-size: 13px; }
.link-button:hover { color: var(--accent); }

/* Layout */
body.with-sidebar { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
main { padding: 28px 32px; min-width: 0; }
body.bare main { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--border); padding: 20px 14px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font: 600 22px var(--head); text-transform: uppercase; letter-spacing: 0.04em; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 7px; background: var(--accent); color: #14120A;
  font: 700 18px var(--head);
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a { color: var(--text); padding: 8px 10px; border-radius: 7px; }
.sidebar nav a:hover { background: var(--panel-2); text-decoration: none; }
.sidebar nav a.active { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.nav-group { margin: 14px 10px 4px; font: 600 13px var(--head); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.user-chip { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--border); padding-top: 14px; }
.user-name { font-weight: 500; }
.user-role { color: var(--muted); font-size: 12px; }
.menu-toggle { display: none; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.filters { display: flex; gap: 10px; }
.filters input { width: 220px; }
.filters select { width: 160px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.panel.narrow { max-width: 460px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.alert { background: rgba(255, 154, 107, 0.1); border: 1px solid var(--warn); color: var(--warn); padding: 10px 12px; border-radius: 8px; }
.notice { background: rgba(99, 210, 164, 0.08); border: 1px solid var(--good); color: var(--text); padding: 10px 12px; border-radius: 8px; margin-bottom: 18px; }

/* Login */
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font: 600 28px var(--head); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 22px; }

/* Phones grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.card {
  display: block; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; color: var(--text);
  transition: border-color 0.12s, transform 0.12s;
}
a.card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.card.locked { cursor: not-allowed; opacity: 0.8; }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-name { font: 600 24px var(--head); letter-spacing: 0.02em; }
.card-meta { color: var(--muted); font-size: 13px; margin-top: 6px; }
.card .mono { color: var(--muted); display: block; margin-top: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: var(--muted); padding: 24px 0; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 500; border: 1px solid var(--border); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.available { color: var(--good); border-color: rgba(99, 210, 164, 0.4); }
.pill.in_use { color: var(--warn); border-color: rgba(255, 154, 107, 0.4); }
.pill.offline { color: var(--offline); }
.pill.mine { color: var(--accent); border-color: rgba(242, 194, 48, 0.45); }

/* Control page */
.back { font-size: 13px; }
.control-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr) 240px; gap: 18px; align-items: start; }
.tools { display: flex; flex-direction: column; gap: 10px; }
.tool { width: 100%; padding: 12px; }
.done { width: 100%; margin-top: 18px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 4px; }
.screen-wrap { display: flex; justify-content: center; }
.screen {
  position: relative; background: #000; border: 1px solid var(--border); border-radius: 26px; padding: 10px;
  width: min(100%, 380px); aspect-ratio: 440 / 956; touch-action: none; user-select: none;
}
.screen img { display: block; width: 100%; height: 100%; object-fit: contain; border-radius: 18px; cursor: crosshair; visibility: hidden; }
.screen img.live { visibility: visible; }
.overlay {
  position: absolute; inset: 10px; display: grid; place-items: center; text-align: center; padding: 20px;
  background: rgba(10, 12, 16, 0.86); border-radius: 18px; color: var(--muted);
}
.overlay[hidden] { display: none; }
.tap-dot { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; border: 2px solid var(--accent); pointer-events: none; animation: fade 0.45s ease-out forwards; }
@keyframes fade { to { opacity: 0; transform: scale(1.6); } }
.side dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 12px; font-size: 14px; }
.side dt { color: var(--muted); }
.side dd { margin: 0; }

/* Admin */
.row-form { display: grid; grid-template-columns: 1fr 1.3fr 0.9fr auto; gap: 12px; align-items: end; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.05em; padding: 8px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr.disabled td { opacity: 0.5; }
form.inline { display: flex; gap: 8px; align-items: center; }
form.inline select { width: auto; }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
label.check input { width: auto; }

/* Narrow screens: sidebar collapses to a top bar with a menu button. */
@media (max-width: 900px) {
  .control-layout { grid-template-columns: 1fr; }
  .tools { flex-direction: row; flex-wrap: wrap; }
  .tool, .done { width: auto; flex: 1; margin-top: 0; }
  .hint { width: 100%; }
}
@media (max-width: 720px) {
  body.with-sidebar { display: block; }
  main { padding: 18px 16px; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; gap: 10px; }
  .sidebar nav, .user-chip { display: none; width: 100%; }
  body.menu-open .sidebar nav, body.menu-open .user-chip { display: flex; }
  .menu-toggle { display: inline-block; margin-left: auto; padding: 6px 12px; }
  .filters { width: 100%; }
  .filters input, .filters select { width: auto; flex: 1; min-width: 0; }
  .row-form { grid-template-columns: 1fr; }
  .table { display: block; overflow-x: auto; }
}
