:root {
  --bg: #0f1420;
  --panel: #161d2e;
  --panel-2: #1d2740;
  --border: #2a3452;
  --text: #e6ebf5;
  --muted: #8b96b3;
  --accent: #4f8cff;
  --accent-2: #2dd4bf;
  --warn: #f59e0b;
  --danger: #ef4444;
  --admin: #f59e0b;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
h1 { margin: 0; font-size: 19px; font-weight: 600; }
.mode-badge {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 20px;
}
.mode-badge.view { background: rgba(79,140,255,0.15); color: var(--accent); }
.mode-badge.admin { background: rgba(245,158,11,0.18); color: var(--admin); }

nav.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
nav.tabs a.tab {
  padding: 7px 14px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 13.5px;
}
nav.tabs a.tab:hover { color: var(--text); text-decoration: none; }
nav.tabs a.tab.active {
  color: var(--text);
  background: var(--panel);
}
.btn {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 13.5px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #08101f; font-weight: 600; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 12.5px; }

main { padding: 20px 24px 60px; max-width: 1200px; margin: 0 auto; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
#search, input[type=text], input[type=date], select.filter, textarea {
  padding: 9px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
#search { flex: 1; min-width: 220px; }
.result-count { color: var(--muted); font-size: 13px; white-space: nowrap; }

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 68vh;
}
table { border-collapse: collapse; width: 100%; font-size: 13px; }
thead th {
  position: sticky; top: 0;
  background: var(--panel-2);
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
thead th:hover { color: var(--accent); }
.arrow { color: var(--accent); margin-left: 4px; }
tbody td { padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:hover { background: var(--panel); cursor: pointer; }
tbody tr:nth-child(even) { background: rgba(255,255,255,0.02); }
.empty-cell { color: var(--muted); }
.no-results { padding: 30px; text-align: center; color: var(--muted); }

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.client-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
}
.client-card:hover { border-color: var(--accent); }
.client-card .name { font-weight: 600; margin-bottom: 4px; }
.client-card .count { color: var(--muted); font-size: 13px; }

.crumb { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.crumb a { color: var(--muted); }
.crumb a:hover { color: var(--accent); }

.device-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.device-header h2 { margin: 0 0 4px; font-size: 22px; }
.device-header .id { color: var(--muted); font-family: ui-monospace, SFMono-Regular, monospace; font-size: 13px; }
.device-actions { display: flex; gap: 8px; }

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}
.field label {
  display: block;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 5px;
}
.field .value { font-size: 14.5px; }
.field .value.empty { color: var(--muted); }
.field input, .field textarea { width: 100%; }
.field textarea { resize: vertical; min-height: 40px; }

.form-actions { margin-top: 18px; display: flex; gap: 10px; }
.msg { padding: 10px 14px; border-radius: 8px; font-size: 13.5px; margin-bottom: 14px; }
.msg.error { background: rgba(239,68,68,0.12); color: #fca5a5; border: 1px solid rgba(239,68,68,0.3); }
.msg.success { background: rgba(45,212,191,0.12); color: var(--accent-2); border: 1px solid rgba(45,212,191,0.3); }

.errors-list { display: flex; flex-direction: column; gap: 10px; }
.error-row {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.error-row .main { flex: 1; min-width: 240px; }
.error-row .main .title { font-weight: 600; margin-bottom: 3px; }
.error-row .main .meta { color: var(--muted); font-size: 13px; }
.error-row .actions { display: flex; gap: 6px; align-items: flex-start; }

footer { padding: 10px 24px 30px; color: var(--muted); font-size: 12px; text-align: center; }
