:root {
  --bg: #f4f5f7; --card: #fff; --text: #1f2933; --muted: #6b7280; --border: #e5e7eb;
  --side: #111827; --side-text: #cbd5e1; --side-active: #1f2937;
  --primary: #2563eb; --primary-h: #1d4ed8; --danger: #dc2626; --ok: #16a34a; --warn: #d97706;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 1rem; }
.muted { color: var(--muted); }

/* Layout */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 220px; flex-shrink: 0; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; }
.brand { padding: 1rem 1.25rem; font-weight: 700; font-size: 1.1rem; color: #fff; border-bottom: 1px solid #1f2937; }
.nav { padding: .75rem; flex: 1; }
.nav p { margin: 1rem .5rem .25rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: #6b7280; }
.nav a { display: block; padding: .45rem .75rem; border-radius: 6px; color: var(--side-text); }
.nav a:hover { background: var(--side-active); color: #fff; }
.nav a.active { background: var(--side-active); color: #fff; font-weight: 600; }
.me { padding: .9rem 1.25rem; border-top: 1px solid #1f2937; font-size: .85rem; }
.me strong { color: #fff; display: block; }
.me form { margin-top: .5rem; }
.me button { background: none; border: 1px solid #374151; color: var(--side-text); padding: .25rem .6rem; border-radius: 6px; cursor: pointer; }
.main { flex: 1; min-width: 0; padding: 1.5rem 2rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }

/* Cards, tables */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .6rem .8rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafafa; }
tr:last-child td { border-bottom: none; }
td.actions { white-space: nowrap; text-align: right; }
.empty { text-align: center; color: var(--muted); padding: 2rem; }
.logo-thumb { width: 40px; height: 40px; object-fit: contain; vertical-align: middle; margin-right: .5rem; background: #f3f4f6; border-radius: 4px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }
.tags span { display: inline-block; background: #eef2ff; color: #3730a3; border-radius: 10px; padding: 0 .5rem; margin: 1px; font-size: .78rem; }

/* Badges */
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 10px; font-size: .75rem; font-weight: 600; background: #e5e7eb; color: #374151; }
.badge.on, .badge.active { background: #dcfce7; color: #166534; }
.badge.off, .badge.blocked, .badge.revoked { background: #fee2e2; color: #991b1b; }
.badge.suspended, .badge.defective, .badge.inactive { background: #fef3c7; color: #92400e; }
.badge.new { background: #dbeafe; color: #1e40af; }

/* Buttons */
.btn { display: inline-block; border: 1px solid transparent; background: var(--primary); color: #fff; padding: .45rem .9rem; border-radius: 6px; cursor: pointer; font: inherit; font-weight: 500; }
.btn:hover { background: var(--primary-h); }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: #f9fafb; }
.btn.danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.sm { padding: .2rem .6rem; font-size: .8rem; }
.htmx-request .btn[type=submit], .btn.htmx-request { opacity: .6; pointer-events: none; }

/* Forms */
.field { margin-bottom: .9rem; }
.field label { display: block; font-weight: 600; margin-bottom: .25rem; font-size: .85rem; }
.field .hint { font-size: .78rem; color: var(--muted); margin: .2rem 0 0; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: .45rem .6rem; border: 1px solid #d1d5db; border-radius: 6px; font: inherit; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
input[readonly] { background: #f3f4f6; }
select[multiple] { min-height: 7rem; }
.check { display: flex; align-items: center; gap: .4rem; font-weight: 500; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 1rem; }
.err { color: var(--danger); font-size: .8rem; margin: .2rem 0 0; }
.has-err input, .has-err select { border-color: var(--danger); }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; }
.filters input { width: 260px; }
.filters select { width: 160px; }

/* Flash, alerts */
.flash { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; padding: .6rem 1rem; border-radius: 6px; margin-bottom: 1rem; transition: opacity .6s; }
.flash.fade { opacity: 0; }
.alert { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; padding: .6rem 1rem; border-radius: 6px; margin-bottom: 1rem; }
.note { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; padding: .6rem 1rem; border-radius: 6px; margin-bottom: 1rem; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(17, 24, 39, .55); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 1rem; overflow-y: auto; z-index: 50; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 640px; padding: 1.5rem; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.modal-head h2 { margin: 0; }
.close { background: none; border: none; font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--muted); }

/* Dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; }
.stat .label { color: var(--muted); font-size: .8rem; }
.stat .value { font-size: 1.7rem; font-weight: 700; }
.stat .sub { color: var(--muted); font-size: .78rem; }
.stat.ok .value { color: var(--ok); } .stat.warn .value { color: var(--warn); } .stat.crit .value { color: var(--danger); }
.rows { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.kv { display: flex; justify-content: space-between; padding: .35rem 0; border-bottom: 1px dashed var(--border); }
.kv:last-child { border-bottom: none; }
.bar { height: 6px; background: #e5e7eb; border-radius: 3px; margin-top: .5rem; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); }
.bar progress { width: 100%; }

/* Pager */
.pager { display: flex; justify-content: space-between; align-items: center; padding: .75rem .25rem; color: var(--muted); }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login { width: 100%; max-width: 380px; }
.login h1 { text-align: center; margin-bottom: 1rem; }
.login .btn { width: 100%; }

/* Audit */
details summary { cursor: pointer; color: var(--primary); }
pre { white-space: pre-wrap; word-break: break-word; background: #f9fafb; border: 1px solid var(--border); padding: .5rem; border-radius: 6px; max-height: 18rem; overflow: auto; font-size: .78rem; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; }
  .nav { display: flex; flex-wrap: wrap; gap: .25rem; }
  .nav p { display: none; }
  .main { padding: 1rem; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .filters input, .filters select { width: 100%; }
}
