:root {
  --paper: #f6f3ee;
  --paper-2: #efeae2;
  --ink: #1a2330;
  --muted: #5f6b78;
  --line: rgba(26, 35, 48, 0.12);
  --navy: #16324f;
  --sea: #1f6f8b;
  --moss: #2f6b4f;
  --moss-soft: rgba(47, 107, 79, 0.14);
  --sand: #d8c3a5;
  --warn: #9a4a1a;
  --warn-soft: rgba(154, 74, 26, 0.12);
  --danger: #8f2f2f;
  --white: #fffcf7;
  --shadow: 0 14px 36px rgba(22, 50, 79, 0.08);
  --radius: 16px;
  --side: 248px;
  --display: "Newsreader", Georgia, serif;
  --body: "Sora", system-ui, sans-serif;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body.cab,
body.prov {
  margin: 0;
  min-height: 100vh;
  font-family: var(--body);
  color: var(--ink);
  background:
    radial-gradient(700px 320px at 0% 0%, rgba(31, 111, 139, 0.1), transparent 60%),
    linear-gradient(180deg, #fbf8f3 0%, var(--paper) 50%, var(--paper-2) 100%);
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }

.brand {
  font-family: var(--display);
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--navy);
}
.brand em, .brand span { font-style: normal; color: var(--sea); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 42px;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 0.86rem;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-sea { background: var(--sea); color: #fff; }
.btn-ghost {
  background: rgba(255, 252, 247, 0.85);
  border-color: var(--line);
  color: var(--navy);
}
.btn-danger {
  background: #fff;
  border-color: rgba(143, 47, 47, 0.28);
  color: var(--danger);
}
.btn-sm { min-height: 36px; padding: 0.4rem 0.8rem; font-size: 0.8rem; }

.login-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: min(420px, 100%);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.6rem;
}
.login-card h1 {
  margin: 0.35rem 0 0.4rem;
  font-family: var(--display);
  font-size: 1.55rem;
  font-weight: 600;
}
.login-card p { margin: 0 0 1.1rem; color: var(--muted); font-size: 0.92rem; }
.login-card a { color: var(--sea); font-weight: 700; text-decoration: underline; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--side) 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 1.1rem 0.9rem;
  border-right: 1px solid var(--line);
  background: rgba(255, 252, 247, 0.88);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sidebar-brand { padding: 0.35rem 0.55rem 0.2rem; }
.sidebar-brand .sub {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  margin-top: 0.15rem;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}
.side-nav button {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 12px;
  padding: 0.72rem 0.8rem;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}
.side-nav button .ico {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(22, 50, 79, 0.06);
  font-size: 0.85rem;
}
.side-nav button.is-active {
  background: rgba(22, 50, 79, 0.08);
  color: var(--navy);
}
.side-nav button.is-active .ico {
  background: rgba(31, 111, 139, 0.16);
  color: var(--sea);
}

.side-foot {
  padding: 0.5rem;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 0.45rem;
}
.who {
  font-size: 0.82rem;
  color: var(--muted);
  padding: 0 0.25rem;
  word-break: break-word;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.85rem 1.2rem;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 248, 243, 0.9);
  backdrop-filter: blur(12px);
}
.topbar h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 600;
}
.topbar-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; }

.menu-btn {
  display: none;
  min-width: 42px;
}

.content {
  padding: 1.15rem 1.2rem 2.2rem;
  width: min(1120px, 100%);
}

.panel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem;
}
.panel + .panel { margin-top: 0.9rem; }
.panel-title {
  margin: 0 0 0.85rem;
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 600;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}
.metrics + .metrics { margin-top: 0.7rem; margin-bottom: 1rem; }
.metric {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: var(--shadow);
}
.metric .label {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}
.metric .value {
  margin-top: 0.25rem;
  font-family: var(--display);
  font-size: 1.7rem;
  font-weight: 600;
  color: var(--navy);
  word-break: break-word;
}

.form input,
.form select,
.form textarea {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 0.5rem 0.75rem;
  background: #fff;
  color: var(--ink);
  width: 100%;
}
.form { display: grid; gap: 0.75rem; }
.form label { display: grid; gap: 0.3rem; font-weight: 600; font-size: 0.86rem; }
.form textarea { min-height: 96px; resize: vertical; }

.hint { color: var(--muted); font-size: 0.84rem; font-weight: 500; }
.msg { padding: 0.75rem 0.9rem; border-radius: 10px; font-size: 0.9rem; }
.msg-ok { background: var(--moss-soft); color: var(--moss); }
.msg-err { background: var(--warn-soft); color: var(--warn); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
table.data th,
table.data td {
  text-align: left;
  padding: 0.78rem 0.5rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.data th {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
table.data tr:hover td { background: rgba(22, 50, 79, 0.02); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  background: var(--moss-soft);
  color: var(--moss);
}
.badge.wait { background: var(--warn-soft); color: var(--warn); }
.badge.off { background: rgba(26, 35, 48, 0.08); color: var(--muted); }

.empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
}
.empty strong {
  display: block;
  color: var(--navy);
  font-family: var(--display);
  font-size: 1.15rem;
  margin-bottom: 0.35rem;
}

.bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 35;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  background: rgba(255, 252, 247, 0.96);
  border-top: 1px solid var(--line);
  padding: 0.35rem 0.25rem calc(0.35rem + env(safe-area-inset-bottom));
}
.bottom-nav button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.4rem 0.15rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  cursor: pointer;
}
.bottom-nav button.is-active { color: var(--navy); }
.bottom-nav .ico { font-size: 1rem; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 300px);
    z-index: 50;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.18);
  }
  body.cab-side-open .sidebar,
  body.prov-side-open .sidebar { transform: translateX(0); }
  body.cab-side-open::before,
  body.prov-side-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(22, 50, 79, 0.4);
    z-index: 40;
  }
  .menu-btn { display: inline-flex; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .content { padding: 1rem 0.9rem 5.5rem; }
  .bottom-nav { display: grid !important; }
}

@media (max-width: 520px) {
  .metrics { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 1.15rem; }
}

.rules-body h3 {
  font-family: var(--display);
  font-size: 1.15rem;
  margin: 1.1rem 0 0.35rem;
  font-weight: 600;
}
.rules-body h3:first-child { margin-top: 0; }
.rules-body p, .rules-body li { color: var(--muted); }
.rules-body ul { padding-left: 1.2rem; margin: 0.35rem 0 0.7rem; }
.rules-body strong { color: var(--danger); font-weight: 600; }
.code-block {
  margin: 0;
  padding: 0.85rem 1rem;
  background: rgba(22, 50, 79, 0.06);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow-x: auto;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.cab code {
  font-size: 0.9em;
  padding: 0.05em 0.3em;
  background: rgba(22, 50, 79, 0.07);
  border-radius: 4px;
}
