:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1c2333;
  --text-muted: #6b7280;
  --accent: #2f6fed;
  --accent-soft: #e8effc;
  --ok: #22c55e;
  --radius: 12px;
}

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

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

/* ── Top bar ─────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; }

.logo {
  color: var(--accent);
  font-size: 20px;
}

.brand-name {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.02em;
}

.server-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #d1d5db;
}

.server-status.online .dot { background: var(--ok); }
.server-status.offline .dot { background: #ef4444; }

/* ── Content ─────────────────────────────── */
.content {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.module-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.module-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 6px 18px rgba(28, 35, 51, 0.08);
}

.module-card .module-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  font-size: 20px;
}

.module-card h2 { font-size: 16px; }
.module-card p { font-size: 13px; color: var(--text-muted); }

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

.empty-icon { font-size: 44px; margin-bottom: 14px; }

.empty-state h1 {
  font-size: 20px;
  margin-bottom: 8px;
}

.empty-state p {
  color: var(--text-muted);
  max-width: 440px;
  margin: 0 auto;
  line-height: 1.55;
}

/* ── Footer ──────────────────────────────── */
.footer {
  padding: 14px 24px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ── Login screen ────────────────────────── */
.login-screen {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 10px 30px rgba(28, 35, 51, 0.06);
}

.login-card .logo { font-size: 28px; text-align: center; }
.login-card h1 { text-align: center; font-size: 22px; }
.login-sub { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 12px; }

.login-card label { font-size: 13px; font-weight: 600; margin-top: 6px; }

.login-card input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}

.login-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.login-card button {
  margin-top: 14px;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.login-card button:hover { filter: brightness(1.05); }

.login-error {
  color: #dc2626;
  font-size: 13px;
  min-height: 18px;
  text-align: center;
  margin-top: 4px;
}

/* ── Topbar extras ───────────────────────── */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.current-user {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.logout-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-muted);
  cursor: pointer;
}

.logout-btn:hover {
  border-color: #ef4444;
  color: #ef4444;
}

.hidden { display: none !important; }

.db-line { margin-top: 12px; font-size: 13px; }

/* ── Module pages ────────────────────────── */
.module-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 20px;
}

.module-head h1 { font-size: 24px; }
.module-desc { color: var(--text-muted); font-size: 14px; margin-top: 4px; }

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

.card h2 { font-size: 16px; margin-bottom: 12px; }

.form-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.form-row input,
.form-row select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

.form-row input:focus,
.form-row select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primary {
  padding: 9px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.btn-primary:hover { filter: brightness(1.05); }

.user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.user-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}

.user-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.user-table tr:last-child td { border-bottom: none; }

.col-actions { text-align: right; white-space: nowrap; }

.btn-small {
  padding: 5px 10px;
  font-size: 12px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  margin-left: 6px;
}

.btn-small:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger:hover { border-color: #ef4444; color: #ef4444; }

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

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  margin-left: 6px;
}

.badge-admin {
  background: #fef3c7;
  color: #b45309;
}

/* ── Modal ──────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(28, 35, 51, 0.45);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 50;
}

.modal-box {
  width: 100%;
  max-width: 420px;
  margin: 0;
}

.form-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-col label {
  font-size: 13px;
  font-weight: 600;
  margin-top: 8px;
  display: block;
}

.form-col input,
.form-col select,
.form-col textarea {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}

/* Two-column rows (e.g. Industry/VAT, Lat/Lng): each half stacks its own
   label above its input instead of putting them side by side. */
.form-col .form-row > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.form-col input:focus,
.form-col select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.btn-ghost {
  padding: 9px 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}

.btn-ghost:hover { border-color: var(--text-muted); }

/* ── Filter chips ───────────────────────── */
.filter-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.filter-chip {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.row-done td { opacity: 0.55; }
.row-done strong { text-decoration: line-through; }

.muted { color: var(--text-muted); font-size: 13px; font-weight: 400; }

textarea {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ── Chat ───────────────────────────────── */
.chat-layout { max-width: 800px; }

.chat-box { display: flex; flex-direction: column; height: calc(100vh - 180px); min-height: 400px; padding: 0; overflow: hidden; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg {
  max-width: 75%;
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px 14px 14px 4px;
  padding: 9px 13px;
}

.chat-msg.mine {
  align-self: flex-end;
  background: var(--accent-soft);
  border-color: var(--accent);
  border-radius: 14px 14px 4px 14px;
}

.chat-msg-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 3px; }
.chat-msg-body { font-size: 14px; line-height: 1.45; word-wrap: break-word; white-space: pre-wrap; }

.chat-input-row {
  display: flex;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--border);
}

.chat-input-row input {
  flex: 1;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}

.chat-input-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ── Calendar ───────────────────────────── */
.cal-nav { display: flex; align-items: center; gap: 14px; }
.cal-nav h1 { font-size: 22px; min-width: 200px; text-align: center; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.cal-dow {
  background: var(--surface);
  padding: 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.cal-cell {
  background: var(--surface);
  min-height: 90px;
  padding: 6px;
  cursor: pointer;
  transition: background 0.1s;
}

.cal-cell:hover { background: var(--accent-soft); }
.cal-cell.empty { cursor: default; }
.cal-cell.empty:hover { background: var(--surface); }
.cal-cell.today { box-shadow: inset 0 0 0 2px var(--accent); }

.cal-daynum { font-size: 13px; font-weight: 600; margin-bottom: 4px; }

.cal-event {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  border-radius: 4px;
  padding: 2px 6px;
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cal-more { font-size: 11px; color: var(--text-muted); }

.event-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.event-row:last-child { border-bottom: none; }
.event-when { font-size: 13px; color: var(--text-muted); min-width: 150px; }
.event-title { flex: 1; font-weight: 600; }
.event-actions { white-space: nowrap; }

/* ── Settings toggles ───────────────────── */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-child { border-bottom: none; }

.setting-info { display: flex; align-items: center; gap: 14px; }

.role-toggles {
  display: flex;
  gap: 22px;
  align-items: center;
}

.role-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.role-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 999px;
  transition: background 0.15s;
  cursor: pointer;
}

.slider::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
}

.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* ── Clients module extras ──────────────── */
.modal-wide { max-width: 640px; }

.contacts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.contacts-head h3 { font-size: 14px; }

.contact-row {
  margin-top: 10px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.contact-row .form-row { gap: 6px; }
.contact-row input { flex: 1; min-width: 80px; }

#contactsList > .muted { margin-top: 8px; display: block; }

/* ── Map picker ─────────────────────────── */
.map-modal-box { max-width: 720px; }

.map-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.map-head h2 { font-size: 16px; }

.map-canvas {
  height: 380px;
  border: 1px solid var(--border);
  border-radius: 10px;
  z-index: 0;
}

/* Leaflet needs its own stacking context inside the modal */
#mapModal .modal-box { z-index: 60; }
#mapModal .map-canvas { position: relative; }

/* ── International Links module ─────────── */
.link-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.link-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid #d1d5db;
  border-radius: var(--radius);
  padding: 16px;
}

.link-card.status-ok   { border-left-color: var(--ok); }
.link-card.status-warn { border-left-color: #f59e0b; }
.link-card.status-down { border-left-color: #ef4444; }

.link-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.link-name { font-weight: 700; font-size: 15px; }
.link-status { margin-left: auto; }

.link-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin: 4px 0 10px;
}

.link-stats {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

.link-stats strong { color: var(--text); font-weight: 600; }

.latency { font-variant-numeric: tabular-nums; }

.util-row { margin: 6px 0 2px; }

.util-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.util-bar {
  height: 8px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.6s ease;
}

.bar-fill.in  { background: #3b82f6; }
.bar-fill.out { background: #8b5cf6; }

.sparkline { margin-top: 10px; }

.sparkline-svg {
  display: block;
  width: 100%;
  height: 34px;
}

.sparkline-svg polyline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
}

.sparkline-svg .spark-dot {
  fill: var(--accent);
}

.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  background: #d1d5db;
  color: #374151;
}

.status-pill.ok      { background: #dcfce7; color: #15803d; }
.status-pill.warn    { background: #fef3c7; color: #b45309; }
.status-pill.down    { background: #fee2e2; color: #b91c1c; }
.status-pill.unknown { background: var(--bg); color: var(--text-muted); }

.probe-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.probe-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.demo-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
