/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
  --bg: #f8fafc;
  --bg2: #ffffff;
  --bg3: #f1f5f9;
  --border: #e2e8f0;
  --text: #1e293b;
  --text2: #64748b;
  --accent: #3b82f6;
  --sidebar-w: 220px;
  --header-h: 56px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

.dark {
  --bg: #0f172a;
  --bg2: #1e293b;
  --bg3: #334155;
  --border: #334155;
  --text: #f1f5f9;
  --text2: #94a3b8;
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); }

/* ── Login ─────────────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
}
.login-card {
  background: var(--bg2);
  border-radius: 16px;
  padding: 48px 40px;
  width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  text-align: center;
}
.login-logo { font-size: 48px; margin-bottom: 12px; }
.login-card h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-subtitle { color: var(--text2); font-size: 13px; margin-bottom: 28px; }
.login-input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg3);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 12px;
  outline: none;
  transition: border-color .2s;
}
.login-input:focus { border-color: var(--accent); }
.login-error { color: #ef4444; font-size: 13px; margin-bottom: 8px; }
.login-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}
.login-btn:hover:not(:disabled) { background: #2563eb; }
.login-btn:disabled { opacity: .6; cursor: default; }

/* ── Dashboard Layout ──────────────────────────────────────────────────── */
.dashboard { display: flex; flex-direction: column; height: 100vh; }
.body { display: flex; flex: 1; overflow: hidden; }

/* ── Header ────────────────────────────────────────────────────────────── */
.header {
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: var(--shadow);
  z-index: 10;
}
.header-brand { display: flex; align-items: center; gap: 8px; }
.header-logo { font-size: 22px; }
.header-title { font-weight: 700; font-size: 16px; }
.header-right { display: flex; align-items: center; gap: 12px; }
.header-updated { font-size: 12px; color: var(--text2); }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 16px; padding: 4px; }
.btn-logout {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}
.btn-logout:hover { background: var(--bg3); }

/* ── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 0;
  flex-shrink: 0;
  position: relative;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 8px 16px;
}
.sidebar-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  letter-spacing: .08em;
}
.btn-add-dam {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  background: none;
  color: var(--accent);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.btn-add-dam:hover { background: var(--accent); color: white; }
.dam-list { list-style: none; }
.dam-item {
  padding: 10px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background .15s;
}
.dam-item:hover { background: var(--bg3); }
.dam-item.active { border-left-color: var(--accent); background: var(--bg3); }
.dam-item-name { display: block; font-size: 13px; font-weight: 500; }
.dam-item.active .dam-item-name { color: var(--accent); font-weight: 600; }
.dam-item-meta { display: block; font-size: 11px; color: var(--text2); margin-top: 2px; }
.dam-item-empty { padding: 10px 16px; font-size: 12px; color: var(--text2); line-height: 1.6; }
.dam-item-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.btn-remove-dam {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  opacity: 0;
  transition: opacity .15s;
  padding: 2px 4px;
  border-radius: 4px;
  flex-shrink: 0;
}
.dam-item:hover .btn-remove-dam { opacity: 0.5; }
.btn-remove-dam:hover { opacity: 1 !important; background: #fee2e2; }
.add-dam-toast {
  position: absolute;
  bottom: 12px;
  left: 8px;
  right: 8px;
  background: #d1fae5;
  color: #065f46;
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

/* ── Modal ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--bg2);
  border-radius: 12px;
  width: 520px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--text2);
  padding: 4px 8px;
}
.modal-close:hover { color: var(--text); }
.modal-form { padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.form-row { display: flex; flex-direction: column; gap: 4px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.form-row label, .form-row-2 label, .form-row-3 label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
}
.modal-form input, .modal-form select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg3);
  color: var(--text);
  font-size: 13px;
  outline: none;
  width: 100%;
  transition: border-color .2s;
}
.modal-form input:focus, .modal-form select:focus { border-color: var(--accent); }
.form-divider {
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  letter-spacing: .06em;
  text-transform: uppercase;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}
.form-error { color: #ef4444; font-size: 13px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 4px; }
.btn-primary {
  padding: 9px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}
.btn-primary:hover:not(:disabled) { background: #2563eb; }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-secondary {
  padding: 9px 20px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
}
.btn-secondary:hover { background: var(--bg3); }

/* ── Main content ──────────────────────────────────────────────────────── */
.main { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 20px; }
.main-empty { align-items: center; justify-content: center; }

/* ── Alert Banner ──────────────────────────────────────────────────────── */
.alert-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
}
.severity-atencao    { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.severity-alerta     { background: #ffedd5; color: #9a3412; border: 1px solid #fb923c; }
.severity-emergencia { background: #fee2e2; color: #991b1b; border: 1px solid #f87171; }

/* ── Dam header ────────────────────────────────────────────────────────── */
.dam-header { display: flex; align-items: center; gap: 12px; }
.dam-header h2 { font-size: 22px; font-weight: 700; }

/* ── Severity Badge ────────────────────────────────────────────────────── */
.severity-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
}
.badge-normal     { background: #d1fae5; color: #065f46; }
.badge-atencao    { background: #fef3c7; color: #92400e; }
.badge-alerta     { background: #ffedd5; color: #9a3412; }
.badge-emergencia { background: #fee2e2; color: #991b1b; }

/* ── Metric Cards ──────────────────────────────────────────────────────── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}
.metric-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.metric-label { font-size: 12px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.metric-value { font-size: 28px; font-weight: 700; margin-bottom: 10px; }
.metric-bar { height: 6px; background: var(--bg3); border-radius: 99px; overflow: hidden; }
.metric-bar-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width .5s; }

/* ── Tabs ──────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab-btn {
  padding: 10px 18px;
  border: none;
  background: none;
  font-size: 14px;
  cursor: pointer;
  color: var(--text2);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-content { padding: 20px 0; }

/* ── Alerts tab ────────────────────────────────────────────────────────── */
.alert-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  font-size: 14px;
}
.alert-msg  { flex: 1; }
.alert-source { font-size: 12px; color: var(--text2); }

/* ── Briefing content ──────────────────────────────────────────────────── */
.briefing-content {
  font-size: 14px;
  line-height: 1.7;
  max-width: 800px;
}
.briefing-content h1, .briefing-content h2, .briefing-content h3 { margin: 16px 0 8px; }

/* ── Empty state ───────────────────────────────────────────────────────── */
.empty-state { color: var(--text2); font-size: 14px; padding: 32px; text-align: center; }

/* ── Accessibility ─────────────────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}
