:root {
  --navy: #0F1B2D;
  --navy-2: #1B2A41;
  --amber: #E8A33D;
  --amber-dark: #B87A1E;
  --bg: #F5F6F8;
  --card: #FFFFFF;
  --text: #1C2430;
  --muted: #5B6676;
  --line: #DDE1E7;
  --ok: #1E7A46;
  --ok-bg: #E4F4EA;
  --bad: #B3261E;
  --bad-bg: #FBE9E7;
  --warn-bg: #FFF4DF;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
a { color: var(--navy); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .75rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }

/* --- top bar ------------------------------------------------------------------------------- */
.topbar {
  background: var(--navy); color: #fff; height: 56px;
  display: flex; align-items: center; gap: 1rem; padding: 0 1rem;
  position: sticky; top: 0; z-index: 10;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .02em; }
.brand span { color: var(--amber); }
.topbar .who { margin-left: auto; display: flex; align-items: center; gap: .75rem; font-size: .9rem; }
.role-badge {
  background: var(--amber); color: var(--navy); border-radius: 999px;
  padding: .15rem .6rem; font-weight: 600; font-size: .8rem;
}
.topbar form { margin: 0; }
.link-button {
  background: none; border: 1px solid rgba(255,255,255,.35); color: #fff;
  border-radius: 6px; padding: .3rem .7rem; cursor: pointer; font: inherit; font-size: .85rem;
}
.link-button:hover { border-color: var(--amber); color: var(--amber); }
.menu-toggle, .menu-label { display: none; }

/* --- layout -------------------------------------------------------------------------------- */
.layout { display: flex; min-height: calc(100vh - 56px); }
.sidebar { width: 220px; background: var(--navy-2); padding: 1rem 0; flex-shrink: 0; }
.sidebar a {
  display: block; color: #D5DBE5; text-decoration: none; padding: .6rem 1.25rem;
  border-left: 3px solid transparent;
}
.sidebar a:hover { background: rgba(255,255,255,.05); color: #fff; }
.sidebar a.active { border-left-color: var(--amber); color: #fff; background: rgba(232,163,61,.12); }
.content { flex: 1; padding: 1.5rem; max-width: 1200px; min-width: 0; }

@media (max-width: 760px) {
  .menu-label { display: inline-block; color: #fff; cursor: pointer; font-size: 1.4rem; line-height: 1; }
  .sidebar { display: none; position: fixed; top: 56px; left: 0; right: 0; width: auto; z-index: 9; }
  .menu-toggle:checked ~ .layout .sidebar { display: block; }
  .topbar .who .name { display: none; }
  .content { padding: 1rem; }
}

/* --- components ---------------------------------------------------------------------------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1rem;
}
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; }
.stat .value { font-size: 2rem; font-weight: 700; color: var(--navy); }
.stat .label { color: var(--muted); font-size: .9rem; }

.flash, .alert { border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem; }
.flash { background: var(--ok-bg); color: var(--ok); }
.alert-error { background: var(--bad-bg); color: var(--bad); }
.alert-secret { background: var(--warn-bg); border: 1px solid var(--amber); }
.alert-secret code { display: block; margin-top: .5rem; padding: .5rem; background: #fff;
  border-radius: 6px; word-break: break-all; user-select: all; font-size: 1rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
td form { display: inline-flex; gap: .35rem; margin: 0; }

.status { display: inline-flex; align-items: center; gap: .35rem; font-size: .9rem; }
.status::before { content: ""; width: .6rem; height: .6rem; border-radius: 50%; }
.status-ok::before { background: var(--ok); }
.status-off::before { background: #98A2B3; }
.status-bad::before { background: var(--bad); }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
input[type=text], input[type=email], input[type=password], select {
  width: 100%; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 6px;
  font: inherit; background: #fff;
}
input:focus, select:focus { outline: 2px solid var(--amber); outline-offset: 0; border-color: var(--amber); }
.field { margin-bottom: 1rem; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; align-items: end; }
.form-row .field { margin-bottom: 0; }
td select { width: auto; padding: .3rem; }

.btn {
  display: inline-block; background: var(--amber); color: var(--navy); border: none;
  border-radius: 6px; padding: .55rem 1rem; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--amber-dark); color: #fff; }
.btn-small { padding: .3rem .6rem; font-size: .85rem; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: transparent; border: 1px solid var(--bad); color: var(--bad); }
.btn-danger:hover { background: var(--bad); color: #fff; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .85rem; margin-top: .3rem; }

/* --- login --------------------------------------------------------------------------------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: var(--navy); padding: 1rem; }
.login-box { background: #fff; border-radius: 12px; padding: 2rem; width: 100%; max-width: 380px; }
.login-box .brand { color: var(--navy); font-size: 1.4rem; display: block; margin-bottom: .25rem; }
.login-box .btn { width: 100%; margin-top: .5rem; }

/* --- M3: pages ------------------------------------------------------------------------------ */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.actions form { margin: 0; }
.stats-compact .card { padding: .75rem 1rem; margin-bottom: 0; }
.stats-compact .value { font-size: 1.5rem; }
.stats-compact { margin-bottom: 1rem; }

.map { height: 62vh; min-height: 320px; border-radius: var(--radius); border: 1px solid var(--line); background: #e8ecf1; }
.map-small { height: 360px; min-height: 260px; }
.map-layout { display: grid; grid-template-columns: 1fr 300px; gap: 1rem; }
.map-panel { margin: 0; }
@media (max-width: 900px) { .map-layout { grid-template-columns: 1fr; } .map { height: 55vh; } }

.pin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.35); position: relative; }
.pin.status-ok { background: var(--ok); }
.pin.status-bad { background: var(--bad); }
.pin.status-off { background: #98A2B3; }
.pin span { position: absolute; left: 16px; top: -4px; white-space: nowrap; font-size: .75rem; font-weight: 600;
  background: rgba(255,255,255,.9); padding: 0 .3rem; border-radius: 4px; color: var(--navy); }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0 0 1rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.tabs { display: flex; gap: .25rem; border-bottom: 2px solid var(--line); margin: 1.5rem 0 1rem; }
.tabs a { padding: .5rem 1rem; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tabs a.active { color: var(--navy); border-bottom-color: var(--amber); font-weight: 600; }

pre.code { background: var(--navy); color: #E6EDF7; padding: .9rem 1rem; border-radius: var(--radius);
  overflow-x: auto; font-size: .85rem; line-height: 1.45; white-space: pre; }
details summary { cursor: pointer; max-width: 46ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details pre.code { white-space: pre-wrap; max-width: 60ch; }
.nowrap { white-space: nowrap; }
.error-text { color: var(--bad); font-size: .85rem; margin-top: .2rem; }
.table-list { columns: 3 220px; margin: 0; padding-left: 1.1rem; }
.table-list li { margin-bottom: .3rem; }
textarea.sql { width: 100%; padding: .65rem; border: 1px solid var(--line); border-radius: 6px; font-size: .9rem; resize: vertical; }
.data-grid td { white-space: nowrap; max-width: 32ch; overflow: hidden; text-overflow: ellipsis; font-size: .85rem; }
input[type=date] { width: 100%; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
button[disabled] { opacity: .5; cursor: not-allowed; }
td a strong, .mono { white-space: nowrap; }
