/* ============================================================
   Bandwidth Monitor — Dashboard Styles
   Dark industrial theme with clear data hierarchy
============================================================ */

:root {
  --bg:        #0a0e14;
  --surface:   #111720;
  --surface2:  #161e2a;
  --border:    #1e2d3d;
  --accent:    #4fc3f7;
  --accent2:   #00e5ff;
  --text:      #cdd9e5;
  --muted:     #6a8099;
  --ok:        #26a642;
  --warn:      #e3a008;
  --danger:    #e05252;
  --critical:  #9b1c1c;
  --stale:     #5a6a7a;
  --radius:    6px;
  --font:      'Courier New', 'Lucida Console', monospace;
  --font-ui:   system-ui, -apple-system, sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Topbar ── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: .02em;
  color: var(--accent);
}
.brand-icon { font-size: 1.2rem; }
.topbar-nav { display: flex; gap: 8px; align-items: center; }

/* ── Container ── */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface2); border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0a0e14; font-weight: 700; }
.btn-primary:hover { background: var(--accent2); border-color: var(--accent2); color: #0a0e14; }
.btn-ghost { border-color: transparent; }
.btn-ghost:hover { border-color: var(--border); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: rgba(224,82,82,.15); }
.btn-copy { color: var(--accent); }

/* ── Summary cards ── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.summary-card.ok   { border-left: 3px solid var(--ok); }
.summary-card.warn { border-left: 3px solid var(--warn); }
.summary-card.muted{ border-left: 3px solid var(--stale); }
.sum-label { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 4px; }
.sum-value { font-size: 1.8rem; font-weight: 700; font-family: var(--font); color: var(--accent); line-height: 1; }
.sum-value small { font-size: .9rem; color: var(--muted); }

/* ── Server grid ── */
.server-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
  gap: 16px;
}

/* ── Server card ── */
.server-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: border-color .2s;
}
.server-card:hover { border-color: var(--accent); }
.server-card.status-warning  { border-left: 3px solid var(--warn); }
.server-card.status-danger   { border-left: 3px solid var(--danger); }
.server-card.status-critical { border-left: 3px solid var(--critical); background: rgba(155,28,28,.06); }
.server-card.status-stale    { border-left: 3px solid var(--stale); opacity: .85; }
.server-card.status-disabled { opacity: .5; }
.server-card.status-no-data  { border-left: 3px solid var(--stale); }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}
.card-title { display: flex; flex-direction: column; gap: 2px; }
.card-title strong { font-size: 15px; color: var(--text); }
.server-id { font-family: var(--font); font-size: 11px; color: var(--muted); }
.card-badges { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

.card-meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
}
.sep { margin: 0 4px; }

/* ── Progress bar ── */
.usage-row { margin-bottom: 12px; }
.usage-label {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 6px;
  font-family: var(--font);
}
.usage-used { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.usage-limit { color: var(--muted); font-size: .9rem; }
.usage-pct { margin-left: auto; font-size: .85rem; color: var(--muted); }
.progress-bar {
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}
.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .4s ease;
  background: var(--ok);
}
/* Color based on percentage */
.progress-fill[style*="width:7"],
.progress-fill[style*="width:8"] { background: var(--warn); }
/* 70%–84% */
.server-card.status-warning  .progress-fill { background: var(--warn); }
/* 85%–94% */
.server-card.status-danger   .progress-fill { background: var(--danger); }
/* 95%+ */
.server-card.status-critical .progress-fill { background: var(--critical); }
/* No data / stale */
.server-card.status-stale   .progress-fill,
.server-card.status-no-data .progress-fill { background: var(--stale); }

.usage-remain { font-size: 11px; color: var(--muted); text-align: right; }

/* ── Period row ── */
.period-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 12px;
  margin-bottom: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.period-item { display: flex; flex-direction: column; gap: 1px; }
.period-label { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }

/* ── Card actions ── */
.card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.badge-ok       { background: rgba(38,166,66,.2);  color: var(--ok); }
.badge-warning  { background: rgba(227,160,8,.2);  color: var(--warn); }
.badge-danger   { background: rgba(224,82,82,.2);  color: var(--danger); }
.badge-critical { background: rgba(155,28,28,.3);  color: #f87171; }
.badge-stale    { background: rgba(90,106,122,.2); color: var(--stale); }
.badge-no-data  { background: rgba(90,106,122,.15);color: var(--muted); }
.badge-disabled { background: rgba(90,106,122,.1); color: var(--muted); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ── Modals ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(2px);
}
.modal-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}
.modal-wide { max-width: 900px; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.1rem; color: var(--accent); }
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--surface2); color: var(--text); }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* ── Forms ── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 16px;
}
.field { display: flex; flex-direction: column; gap: 4px; }
label { font-size: 12px; color: var(--muted); }
label small { font-size: 10px; }
input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-family: var(--font-ui);
  font-size: 13px;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
input[type="number"] { font-family: var(--font); }
.form-section {
  grid-column: 1 / -1;
  padding-top: 8px;
}
.form-section h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: 10px;
}
.iface-tip {
  grid-column: 1 / -1;
  background: rgba(79,195,247,.07);
  border: 1px solid rgba(79,195,247,.2);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text);
  line-height: 1.6;
  margin-top: 4px;
}
.iface-tip code { font-family: var(--font); color: var(--accent); font-size: 11px; }

/* ── Code blocks / copy boxes ── */
.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-family: var(--font);
  font-size: 12px;
  color: var(--accent);
  white-space: pre-wrap;
  word-break: break-all;
  margin: 8px 0;
  position: relative;
}
.copy-wrap {
  position: relative;
  margin: 8px 0;
}
.copy-wrap .code-block { padding-right: 80px; }
.copy-btn {
  position: absolute;
  right: 8px;
  top: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--accent);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}
.copy-btn:hover { background: var(--accent); color: #0a0e14; }

/* ── Detail modal ── */
.detail-section {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.detail-section:last-child { border-bottom: none; }
.detail-section h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: 12px;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.detail-item { display: flex; flex-direction: column; gap: 2px; }
.detail-label { font-size: 10px; color: var(--muted); text-transform: uppercase; }
.detail-value { font-size: 13px; font-family: var(--font); }

.samples-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-family: var(--font);
}
.samples-table th {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
}
.samples-table td {
  padding: 5px 8px;
  border-bottom: 1px solid rgba(30,45,61,.5);
}
.samples-table tr:last-child td { border-bottom: none; }

/* ── API key display ── */
.api-key-display {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 6px;
}
.api-key-display code {
  font-family: var(--font);
  font-size: 12px;
  color: var(--accent);
  flex: 1;
  word-break: break-all;
}
.hint { font-size: 11px; color: var(--warn); margin-top: 4px; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 9999;
  animation: fadeIn .2s ease;
}
.toast.ok   { border-color: var(--ok);    color: var(--ok); }
.toast.fail { border-color: var(--danger); color: var(--danger); }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

/* ── Settings API key row ── */
.settings-key-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.settings-key-row code {
  font-family: var(--font);
  font-size: 12px;
  color: var(--accent);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  flex: 1;
  word-break: break-all;
}

.loading { color: var(--muted); padding: 20px; text-align: center; }

/* ── Responsive ── */
@media (max-width: 700px) {
  .topbar { padding: 0 12px; }
  .topbar-brand .brand-name { display: none; }
  .container { padding: 12px; }
  .server-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .modal-box { padding: 16px; }
}
