:root {
  --bg: #0f141b;
  --bg-sidebar: #161d27;
  --surface: #1c2430;
  --surface-2: #232e3c;
  --border: #2b3848;
  --text: #e6edf3;
  --text-dim: #8b98a9;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, .14);
  --green: #2fbf71;
  --red: #d64545;
  --orange: #e8943a;
  --yellow: #d9b23a;
  --radius: 10px;
  --shadow: 0 4px 18px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.brand-mark { color: var(--accent); font-size: 22px; line-height: 1; }
.brand-name { font-weight: 700; letter-spacing: .4px; font-size: 15px; }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
  display: block; padding: 9px 12px; border-radius: 8px;
  color: var(--text-dim); font-weight: 500;
}
.nav-link:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.nav-link.is-active { background: var(--accent-soft); color: var(--accent); }
.nav-link.logout { margin-left: auto; color: var(--red); text-align: left; }

.sidebar-user { padding: 12px 10px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #6a5cff);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.user-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.user-meta small { color: var(--text-dim); }

/* ---------- main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  padding: 18px 28px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(15, 20, 27, .6);
}
.page-title { margin: 0; font-size: 20px; font-weight: 700; }
.topbar-actions { display: flex; gap: 10px; }

.content { padding: 24px 28px 48px; flex: 1; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-body { padding: 20px; }
.card + .card { margin-top: 20px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat-label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }
.stat-value { font-size: 26px; font-weight: 800; margin-top: 4px; }
.stat-rank { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.stat-rank .stat { flex: 1; min-width: 150px; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; padding: 10px 14px; color: var(--text-dim);
  font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td.actions { white-space: nowrap; text-align: right; }
.actions a, .actions form { display: inline-block; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  font-weight: 600; cursor: pointer; font-size: 13px; line-height: 1.4;
}
.btn:hover { background: #2d3a4c; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #3f7bef; }
.btn-danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: rgba(214, 69, 69, .12); }
.btn-sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn-icon-danger { border-color: transparent; background: transparent; color: var(--red); padding: 4px 6px; }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field.full { grid-column: 1 / -1; }
label { font-size: 13px; font-weight: 600; color: var(--text-dim); }
input, select, textarea {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 12px; font-size: 14px; font-family: inherit;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 100px; resize: vertical; }
.form-actions { margin-top: 18px; display: flex; gap: 10px; }

/* ---------- alerts / badges ---------- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; border: 1px solid transparent; }
.alert-success { background: rgba(47, 191, 113, .12); border-color: var(--green); color: #7fddab; }
.alert-error, .alert-danger { background: rgba(214, 69, 69, .12); border-color: var(--red); color: #f0a1a1; }
.alert-warning { background: rgba(232, 148, 58, .12); border-color: var(--orange); color: #f0b87f; }
.alert-info { background: rgba(79, 140, 255, .12); border-color: var(--accent); color: #9cc0ff; }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.4;
}
.badge-active, .badge-open, .badge-available, .badge-assigned, .badge-running { background: rgba(47, 191, 113, .15); color: #7fddab; }
.badge-pending, .badge-maintenance, .badge-in_progress, .badge-medium, .badge-paused { background: rgba(232, 148, 58, .15); color: #f0b87f; }
.badge-disabled, .badge-retired, .badge-disposed, .badge-closed, .badge-resolved, .badge-low, .badge-stopped, .badge-destroyed { background: rgba(139, 152, 169, .18); color: #b7c1ce; }
.badge-urgent, .badge-high, .badge-critical, .badge-full { background: rgba(214, 69, 69, .15); color: #f0a1a1; }
.badge-inactive, .badge-provisioning { background: rgba(79, 140, 255, .15); color: #9cc0ff; }

/* ---------- misc ---------- */
.empty { text-align: center; color: var(--text-dim); padding: 40px 20px; }
.muted { color: var(--text-dim); }
.text-right { text-align: right; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 24px; }
.detail-grid .detail { border-bottom: 1px dashed var(--border); padding: 8px 0; }
.detail-grid .detail dt { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.detail-grid .detail dd { margin: 2px 0 0; font-weight: 600; }

.avatar-lg {
  width: 72px; height: 72px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), #6a5cff);
  display: inline-flex; align-items: center; justify-content: center; font-size: 28px; font-weight: 800; color: #fff;
}
.profile-head { display: flex; align-items: center; gap: 16px; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 20% 0%, #1a2b3d66, transparent), var(--bg); padding: 20px; }
.auth-box { width: 100%; max-width: 420px; }
.auth-card { padding: 32px; }
.auth-title { margin: 0 0 6px; font-size: 22px; }
.auth-sub { color: var(--text-dim); margin: 0 0 22px; }
.auth-link { text-align: center; margin-top: 16px; color: var(--text-dim); }