:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #6b7686;
  --line: #e3e8f0;
  --brand: #2f6df4;
  --brand-dark: #1f55cc;
  --green: #1f9d62;
  --green-bg: #e7f7ee;
  --red: #d23c3c;
  --red-bg: #fbe8e8;
  --amber: #d98a00;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 26, 48, .08), 0 4px 16px rgba(16, 26, 48, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Top bar / nav ---- */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 16px; min-height: 60px;
}
.brand { font-weight: 700; font-size: 1.2rem; color: var(--ink); }
.brand:hover { text-decoration: none; }
.nav { margin-left: auto; display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.nav a {
  color: var(--ink); padding: 8px 12px; border-radius: 8px; font-size: .95rem;
}
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.cta {
  background: var(--brand); color: #fff;
}
.nav a.cta:hover { background: var(--brand-dark); }
.nav a.logout { color: var(--muted); }

/* ---- Login page ---- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--bg);
}
.login-card { width: 100%; max-width: 380px; }
.login-brand { margin: 0 0 2px; font-size: 1.5rem; }
.nav-toggle {
  display: none; margin-left: auto; background: none; border: 1px solid var(--line);
  border-radius: 8px; font-size: 1.3rem; padding: 4px 10px; cursor: pointer;
}

/* ---- Layout ---- */
.container { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
.footer { text-align: center; color: var(--muted); padding: 32px 16px; font-size: .85rem; }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 18px;
}
.page-head h1 { margin: 0; font-size: 1.6rem; }
.page-head .sub { color: var(--muted); margin: 4px 0 0; }

/* ---- Cards & grid ---- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

.stat { text-align: left; }
.stat .num { font-size: 2rem; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: .9rem; }

/* ---- Buttons ---- */
.btn {
  display: inline-block; border: 1px solid var(--line); background: #fff;
  color: var(--ink); padding: 9px 14px; border-radius: 8px; cursor: pointer;
  font-size: .95rem; font-family: inherit;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { color: var(--red); border-color: #f0c6c6; }
.btn-danger:hover { background: var(--red-bg); }
.btn-sm { padding: 5px 10px; font-size: .85rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- Forms ---- */
form .field { margin-bottom: 14px; }
label { display: block; font-weight: 600; margin-bottom: 5px; font-size: .9rem; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 1rem; font-family: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(47,109,244,.15);
}
textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg); }

/* ---- Badges ---- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; background: var(--bg); color: var(--muted);
}
.badge.single { background: #eef3ff; color: var(--brand-dark); }
.badge.double { background: #f3eafe; color: #7a3fc0; }
.badge.free { background: var(--green-bg); color: var(--green); }
.badge.full { background: var(--red-bg); color: var(--red); }

/* ---- Flash ---- */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; }
.flash-success { background: var(--green-bg); color: var(--green); }
.flash-error { background: var(--red-bg); color: var(--red); }

/* ---- Tension chart ---- */
.tension { display: flex; gap: 3px; align-items: flex-end; overflow-x: auto; padding-bottom: 8px; }
.tbar { flex: 1; min-width: 16px; text-align: center; }
.tbar .bar {
  width: 100%; border-radius: 4px 4px 0 0; background: var(--line);
  transition: height .2s; position: relative;
}
.tbar.low .bar { background: #9ad6b4; }
.tbar.medium .bar { background: #f2c14e; }
.tbar.high .bar { background: #e8893b; }
.tbar.full .bar { background: var(--red); }
.tbar.empty .bar { background: var(--line); }
.tbar .wk { font-size: .65rem; color: var(--muted); margin-top: 4px; white-space: nowrap; }
.tbar .val { font-size: .7rem; font-weight: 600; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: 10px; }
.legend span::before {
  content: ""; display: inline-block; width: 12px; height: 12px;
  border-radius: 3px; margin-right: 5px; vertical-align: -1px;
}
.legend .l-low::before { background: #9ad6b4; }
.legend .l-medium::before { background: #f2c14e; }
.legend .l-high::before { background: #e8893b; }
.legend .l-full::before { background: var(--red); }

/* ---- Misc ---- */
.muted { color: var(--muted); }
.mb { margin-bottom: 16px; }
.mt { margin-top: 16px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.pill-occ { display: inline-flex; gap: 4px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; background: var(--line); }
.dot.on { background: var(--brand); }
.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.msgbox {
  width: 100%; min-height: 260px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: .92rem; white-space: pre-wrap;
}
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.inline-form { display: inline; }

/* ---- Responsive ---- */
@media (max-width: 820px) {
  .nav {
    display: none; position: absolute; top: 60px; left: 0; right: 0;
    background: #fff; flex-direction: column; align-items: stretch;
    border-bottom: 1px solid var(--line); padding: 8px;
  }
  body.nav-open .nav { display: flex; }
  .nav-toggle { display: block; }
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: 1fr; }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; }
}
