/* WestSteel Telemetry Admin — admin.css */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Brand */
  --navy:          #102234;
  --navy-light:    #1a3349;
  --navy-border:   #1e3d57;
  --accent:        #1a6b4a;
  --accent-hover:  #1e8059;

  /* Status */
  --ok:            #22c55e;
  --ok-bg:         rgba(34,197,94,.12);
  --warn:          #f59e0b;
  --warn-bg:       rgba(245,158,11,.12);
  --critical:      #ef4444;
  --critical-bg:   rgba(239,68,68,.12);
  --unknown:       #6b7280;
  --unknown-bg:    rgba(107,114,128,.12);

  /* UI chrome */
  --bg:            #f0f4f8;
  --surface:       #ffffff;
  --border:        #e2e8f0;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --radius:        8px;
  --sidebar-w:     220px;
  --topbar-h:      52px;
}

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── Auth pages ──────────────────────────────────────────────────────────── */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(140deg, #0b1c2e 0%, #102234 55%, #0a2e1d 100%);
}

.auth-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 24px 64px rgba(0,0,0,.45);
}
.auth-card--wide { max-width: 520px; }

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
  font-size: 16px;
  font-weight: 700;
  color: var(--navy);
}
.logo-icon { width: 36px; height: 36px; flex-shrink: 0; }

.auth-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 6px;
}
.auth-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 24px;
}
.auth-footer {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 24px;
  letter-spacing: .04em;
}
.auth-back {
  display: block;
  text-align: center;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
}
.auth-back:hover { color: var(--text); }

/* ── Form fields ─────────────────────────────────────────────────────────── */

.field { margin-bottom: 20px; }
.modal-body .field { margin-bottom: 22px; }

.field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26,107,74,.14);
}

.field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7' viewBox='0 0 12 7'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 18px;
  cursor: pointer;
  user-select: none;
}
.checkbox-label input { width: auto; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-full  { width: 100%; }
.btn-sm    { padding: 5px 12px; font-size: 12px; }

.btn-primary   { background: var(--accent);  color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary { background: var(--border);  color: var(--text); }
.btn-secondary:hover { background: #d0d7e0; }

.btn-danger    { background: var(--critical); color: #fff; }
.btn-danger:hover { background: #dc2626; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */

.alert {
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 18px;
  border-left: 3px solid transparent;
}
.alert-error  { background: var(--critical-bg); color: #b91c1c; border-color: var(--critical); }
.alert-warn   { background: var(--warn-bg);     color: #92400e; border-color: var(--warn); }
.alert-ok     { background: var(--ok-bg);       color: #15803d; border-color: var(--ok); }
.alert-info   { background: #f1f5f9;            color: var(--navy); border-color: var(--navy-light); }

/* ── TOTP setup ──────────────────────────────────────────────────────────── */

.totp-setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.qr-container {
  padding: 12px;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  line-height: 0;
}
.totp-secret-wrap { text-align: center; }
.totp-secret-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.totp-secret {
  display: inline-block;
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px;
  letter-spacing: .12em;
  background: #f1f5f9;
  padding: 6px 12px;
  border-radius: 4px;
  word-break: break-all;
}

/* ── Dashboard shell ─────────────────────────────────────────────────────── */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* Topbar */
.topbar {
  grid-column: 1 / -1;
  background: var(--navy);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  border-bottom: 1px solid var(--navy-border);
  z-index: 10;
}
.topbar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  flex: 1;
}
.topbar-logo .logo-icon { width: 28px; height: 28px; }
.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  color: rgba(255,255,255,.75);
}
.topbar-user { font-weight: 600; }
.topbar-logout {
  color: rgba(255,255,255,.55);
  text-decoration: none;
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 5px;
  transition: color .15s, border-color .15s;
}
.topbar-logout:hover { color: #fff; border-color: rgba(255,255,255,.5); }

/* Sidebar */
.sidebar {
  background: var(--navy);
  overflow-y: auto;
  padding: 16px 0;
  border-right: 1px solid var(--navy-border);
}
.nav-section { padding: 0 10px; margin-bottom: 6px; }
.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.3);
  padding: 8px 10px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  border-radius: 6px;
  color: rgba(255,255,255,.65);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 2px;
  transition: background .12s, color .12s;
}
.nav-item:hover   { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active  { background: var(--accent); color: #fff; }
.nav-item svg     { width: 15px; height: 15px; flex-shrink: 0; }
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 17px;
  height: 17px;
  border-radius: 9px;
  background: #dc2626;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 0 4px;
  margin-left: auto;
}

/* Content area */
.content {
  overflow-y: auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* Backup banner */
.backup-banner {
  background: #7c2d12;
  color: #fed7aa;
  padding: 10px 24px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #9a3412;
  flex-shrink: 0;
}
.backup-banner a { color: #fdba74; }

/* ── Page layout ─────────────────────────────────────────────────────────── */

.page-header {
  padding: 24px 28px 0;
  margin-bottom: 20px;
}
.page-title   { font-size: 22px; font-weight: 700; color: var(--navy); }
.page-subtitle{ font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.page-body    { padding: 0 28px 28px; flex: 1; }

/* ── Cards ───────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 14px;
}
.card-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

/* ── Status badges ───────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge-ok       { color: var(--ok);      background: var(--ok-bg); }
.badge-warn     { color: var(--warn);    background: var(--warn-bg); }
.badge-critical { color: var(--critical);background: var(--critical-bg); }
.badge-unknown  { color: var(--unknown); background: var(--unknown-bg); }

/* ── Tables ──────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  white-space: nowrap;
}
td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8fafc; }

/* ── Gauge (progress bar) ────────────────────────────────────────────────── */

.gauge-wrap { margin: 6px 0; }
.gauge-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.gauge-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.gauge-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--ok);
  transition: width .4s ease;
}
.gauge-fill.warn     { background: var(--warn); }
.gauge-fill.critical { background: var(--critical); }

/* ── 2FA setup steps ─────────────────────────────────────────────────────── */

.setup-steps { margin-bottom: 20px; }
.setup-step {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
  align-items: flex-start;
}
.step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}
.step-title { font-size: 13px; font-weight: 600; color: var(--navy); margin-bottom: 2px; }
.step-desc  { font-size: 12px; color: var(--text-muted); line-height: 1.5; }

/* ── TOTP code input ─────────────────────────────────────────────────────── */

.totp-input {
  width: 100%;
  padding: 14px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: .3em;
  text-align: center;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--navy);
  transition: border-color .15s, box-shadow .15s;
}
.totp-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26,107,74,.14);
}

/* ── Sign-in hint ────────────────────────────────────────────────────────── */

.sign-in-hint {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 14px;
  line-height: 1.6;
}

/* ── Modal ───────────────────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.5);
}
.modal-box {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.modal-title { font-size: 16px; font-weight: 700; color: var(--navy); }
.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-body   { padding: 28px 28px 8px; }
.modal-footer {
  padding: 20px 28px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ── Form row (two-column grid inside modal) ─────────────────────────────── */

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 20px;
}
@media (max-width: 560px) {
  .form-row { grid-template-columns: 1fr; }
}

/* ── Table action buttons ────────────────────────────────────────────────── */

.row-actions { white-space: nowrap; }
.row-actions .btn + .btn { margin-left: 4px; }

/* ── Field helpers ───────────────────────────────────────────────────────── */

.field-meta {
  font-size: 10px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
  margin-left: 4px;
}

.field-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  margin-bottom: 0;
}

.modal-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 18px;
  margin-bottom: 16px;
  margin-top: 6px;
}

/* ── Inline checkbox group ───────────────────────────────────────────────── */

.check-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
  padding: 4px 0;
}

.checkbox-label.inline {
  margin-bottom: 0;
  font-size: 13px;
  color: var(--text);
}

/* ── Tab bar ─────────────────────────────────────────────────────────────── */

.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}

.tab-btn {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  border-radius: var(--radius) var(--radius) 0 0;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Permission preset cards ─────────────────────────────────────────────── */

.perm-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.perm-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
}

.perm-role-key {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'Courier New', Courier, monospace;
  margin-left: 8px;
}

.perm-groups {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  padding: 4px 0;
}

.perm-group {
  padding: 14px 20px;
  min-width: 180px;
}

.perm-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.perm-checks {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.perm-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.perm-check input { width: auto; }

.perm-save-msg {
  padding: 8px 20px;
  font-size: 12px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
}
.perm-save-ok  { color: #15803d; }
.perm-save-err { color: var(--critical); }

/* ── Status badges (warning / critical / error) ──────────────────────────── */

.badge-warning  { background: var(--warn-bg);     color: #92400e; }
.badge-critical { background: var(--critical-bg); color: #991b1b; }
.badge-error    { background: var(--critical-bg); color: #991b1b; }
.badge-ok       { background: var(--ok-bg);       color: #15803d; }

/* inline gauge label status colours */
.text-status-warn     { color: var(--warn); }
.text-status-critical { color: var(--critical); }

/* ── Infrastructure — check sections ─────────────────────────────────────── */

.check-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.check-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.check-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.check-section-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.check-section-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.check-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.check-message {
  font-size: 12px;
  color: var(--text-muted);
  font-family: monospace;
  background: var(--bg);
  padding: 6px 10px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 14px;
}

/* ── Metric cards (one per metric key) ───────────────────────────────────── */

.metric-cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.metric-card {
  padding: 16px 14px 12px;
  border-radius: var(--radius);
  border: 2px solid var(--unknown);
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  transition: box-shadow .15s, transform .1s;
}
.metric-card:hover, .metric-card:focus-visible {
  box-shadow: 0 3px 10px rgba(0,0,0,.1);
  transform: translateY(-2px);
  outline: none;
}

.metric-card.status-ok       { border-color: var(--ok); }
.metric-card.status-warning  { border-color: var(--warn); }
.metric-card.status-critical,
.metric-card.status-error    { border-color: var(--critical); }

.metric-name {
  font-size: 22px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.metric-value {
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 14px;
  color: var(--text);
}
.metric-value.status-ok       { color: var(--ok); }
.metric-value.status-warning  { color: var(--warn); }
.metric-value.status-critical,
.metric-value.status-error    { color: var(--critical); }

.metric-bar-track {
  height: 6px;
  border-radius: 3px;
  background: var(--bg);
  overflow: hidden;
}

.metric-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .4s ease;
  background: var(--unknown);
}
.metric-bar-fill.status-ok       { background: var(--ok); }
.metric-bar-fill.status-warning  { background: var(--warn); }
.metric-bar-fill.status-critical,
.metric-bar-fill.status-error    { background: var(--critical); }

/* Threshold markers below the bar */
.metric-thresholds {
  position: relative;
  height: 16px;
  margin-top: 3px;
  font-size: 10px;
  font-weight: 700;
}

.metric-threshold-mark {
  position: absolute;
  transform: translateX(-50%);
  line-height: 1;
  color: var(--warn);
}
.metric-threshold-crit {
  color: var(--critical);
}

/* History chart label */
.chart-metric-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* ── Responsive (tablet — manager on iPad in server room) ────────────────── */

@media (max-width: 800px) {
  :root { --sidebar-w: 0px; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .page-header, .page-body { padding-left: 16px; padding-right: 16px; }
}
