:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* Login */
#login-view { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 320px;
}
.login-card h1 { font-size: 1.25rem; text-align: center; margin-bottom: 0.5rem; }
.login-card input { padding: 0.6rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.login-card button { padding: 0.6rem; border-radius: var(--radius); border: none; background: var(--accent); color: #0f172a; font-weight: 600; cursor: pointer; }
.sso-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.8rem; margin: 4px 0; }
.sso-divider::before, .sso-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.sso-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 0.6rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text); text-decoration: none; font-weight: 600; font-size: 0.9rem;
  transition: background 0.15s, border-color 0.15s;
}
.sso-btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.sso-logo { width: 20px; height: 20px; color: var(--accent); flex-shrink: 0; }
.error { color: var(--bad); font-size: 0.85rem; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
.nav-links { display: flex; gap: 1rem; flex: 1; }
.nav-links a { color: var(--muted); text-decoration: none; padding: 0.25rem 0.5rem; border-radius: var(--radius); }
.nav-links a.active { color: var(--text); background: var(--bg-hover); }
.user-label { color: var(--muted); font-size: 0.85rem; }
.btn-link { background: none; border: none; color: var(--accent); cursor: pointer; }

main { padding: 1.5rem; max-width: 1200px; margin: 0 auto; }

/* Cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.card h3 { font-size: 1rem; margin-bottom: 0.75rem; }
.card .muted { color: var(--muted); font-size: 0.85rem; }

.device-card { cursor: pointer; transition: transform 0.1s; }
.device-card:hover { transform: translateY(-2px); }
.device-card .status-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 0.5rem; }
.dot-ok { background: var(--ok); }
.dot-bad { background: var(--bad); }
.dot-warn { background: var(--warn); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 1rem; font-size: 0.85rem; }
.kv dt { color: var(--muted); }
.kv dd { text-align: right; }

/* Detail */
.detail-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.detail-header h2 { font-size: 1.5rem; }
.back { color: var(--accent); text-decoration: none; }

.metric-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.metric-box { flex: 1; min-width: 120px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; text-align: center; }
.metric-box .value { font-size: 1.5rem; font-weight: 700; }
.metric-box .label { color: var(--muted); font-size: 0.8rem; margin-top: 0.25rem; }

.section { margin-top: 1.5rem; }
.section h3 { margin-bottom: 0.75rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }

canvas { width: 100%; max-height: 200px; }
.chart-wrap { width: 100%; }

/* --- Graphique style MikroTik --- */
.mt-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.mt-stats { display: flex; gap: 24px; margin: 8px 0 12px 0; font-family: ui-monospace, 'JetBrains Mono', monospace; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.mt-stats b { font-weight: 600; color: var(--text); margin-left: 4px; }
.mt-stats .mt-stat-val b { color: var(--accent); }
.mt-chart-wrap { width: 100%; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px; box-sizing: border-box; position: relative; }
.mt-chart-wrap .mt-grid line { stroke: var(--border); stroke-dasharray: 2,2; stroke-width: 1; }
.mt-chart-wrap .mt-line { stroke: var(--accent); stroke-width: 1.5; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.mt-chart-wrap .mt-area { fill: var(--accent); fill-opacity: 0.15; stroke: none; }
.mt-chart-wrap .mt-crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3,3; pointer-events: none; opacity: 0.6; }
.mt-tooltip {
  position: absolute; pointer-events: none; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px;
  font-size: 11px; line-height: 1.5; white-space: nowrap; z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3); display: none;
}
.mt-tooltip .mt-tt-time { color: var(--muted); margin-bottom: 2px; }
.mt-tooltip .mt-tt-val { color: var(--accent); }
.mt-axis { display: flex; justify-content: space-between; margin-top: 4px; font-size: 10px; color: var(--muted); font-family: ui-monospace, monospace; }
.mt-rangebar { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; margin-bottom: 10px; }
.mt-range-btn { border: none; border-radius: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 4px 12px; font-size: 12px; }
.mt-range-btn:hover { background: var(--bg-hover); }
.mt-range-btn.active { background: var(--accent); color: #0f172a; font-weight: 600; }
.mt-chart-body h4 { margin-bottom: 8px; }

.empty { color: var(--muted); padding: 1rem; text-align: center; }

.badge { padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.75rem; }
.badge-ok { background: rgba(34,197,94,0.15); color: var(--ok); }
.badge-bad { background: rgba(239,68,68,0.15); color: var(--bad); }

.action-row { display: flex; align-items: center; gap: 0.75rem; }
.btn {
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-hover);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
}
.btn:hover { background: var(--border); }
.btn-danger { border-color: rgba(239,68,68,0.4); color: var(--bad); }
.btn-danger:hover { background: rgba(239,68,68,0.15); }
.action-status { font-size: 0.85rem; }
