:root {
  --bg: #0b1220;
  --panel: #121a2b;
  --panel-2: #172236;
  --text: #eaf0fa;
  --muted: #8fa0bb;
  --accent: #3d9cf0;
  --accent-2: #2f7fc4;
  --ok: #3ecf8e;
  --bad: #f07178;
  --warn: #e6c07b;
  --line: #27344a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  --radius: 14px;
  --nav-w: 240px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { overflow-x: hidden; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(900px 480px at 0% -10%, #1a2740 0%, transparent 60%),
    radial-gradient(700px 420px at 100% 0%, #152033 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

a { color: #8ec7ff; text-decoration: none; }
a:hover { text-decoration: underline; }

.layout {
  display: grid;
  grid-template-columns: var(--nav-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #101727;
  background: color-mix(in srgb, var(--panel) 94%, black);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 30;
}

.brand {
  padding: 8px 10px 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}
.brand strong { display: block; font-size: 1.05rem; letter-spacing: -0.02em; }
.brand span { color: var(--muted); font-size: 0.8rem; }

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.94rem;
}
.nav a:hover { background: var(--panel-2); text-decoration: none; }
.nav a.active {
  background: #1a3350;
  background: color-mix(in srgb, var(--accent) 22%, var(--panel));
  color: #fff;
}
.nav .ico {
  width: 1.35rem;
  text-align: center;
  opacity: 0.9;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
}
.userbox {
  font-size: 0.82rem;
  color: var(--muted);
  padding: 0 8px;
  word-break: break-word;
}

.content {
  padding: 22px 22px 40px;
  max-width: 1100px;
  width: 100%;
  min-width: 0;
}
.card, .panel, .status, .m-item { min-width: 0; overflow-wrap: anywhere; word-break: break-word; }

.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
}
.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
}

.page-title {
  margin: 0 0 6px;
  font-size: clamp(1.25rem, 2.5vw, 1.6rem);
  letter-spacing: -0.02em;
}
.page-sub {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.card {
  background: #111827;
  background: color-mix(in srgb, var(--panel) 92%, black);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.card .label { color: var(--muted); font-size: 0.8rem; }
.card .value { font-size: 1.4rem; font-weight: 700; margin-top: 4px; }

.panel {
  background: #111827;
  background: color-mix(in srgb, var(--panel) 92%, black);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  align-items: center;
}

input, button, select, textarea {
  background: #0f1726;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font: inherit;
  min-height: 42px;
}
input, select, textarea { min-width: 0; flex: 1; }
button {
  background: var(--accent);
  border-color: transparent;
  color: #061018;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
button.secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}
button:disabled { opacity: 0.55; cursor: not-allowed; }

.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; min-width: 560px; }
th, td {
  text-align: left;
  padding: 10px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; }

.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.muted { color: var(--muted); font-size: 0.85rem; }
.tiny { font-size: 0.78rem; color: var(--muted); }
.cap {
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid var(--line);
}
.pill.ok { color: var(--ok); border-color: #2f6b4f; }
.pill.warn { color: var(--warn); border-color: #6b5a2f; }
.pill.bad { color: var(--bad); border-color: #7a3a40; }
.pill.pending { color: var(--accent); border-color: #2a5a8a; }

.status {
  display: none;
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0f1726;
  font-size: 0.92rem;
  line-height: 1.45;
}
.status.show { display: block; }
.status.ok { border-color: #2f6b4f; color: var(--ok); }
.status.bad { border-color: #7a3a40; color: var(--bad); }
.status.warn { border-color: #6b5a2f; color: var(--warn); }

.countdown {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent);
}
.next-card {
  display: grid;
  gap: 4px;
  margin-top: 12px;
  border-color: #2a5a8a;
}
.next-card .countdown { font-size: clamp(1.6rem, 6vw, 2.2rem); }

.panel-title { margin: 0 0 8px; font-size: 1rem; }
.panel > .muted { display: block; margin: 0 0 14px; line-height: 1.45; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 16px;
  margin-bottom: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.field select, .field input { width: 100%; }
.field-check { justify-content: flex-end; }
.hint { font-size: 0.75rem; color: var(--muted); line-height: 1.35; }

.range, .input-unit { display: flex; align-items: center; gap: 8px; min-width: 0; }
.range input, .input-unit input {
  flex: 1 1 0;
  min-width: 64px;
  width: auto;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.sep, .unit { color: var(--muted); font-size: 0.8rem; white-space: nowrap; flex: 0 0 auto; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
}
.check input {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  min-height: 0;
  padding: 0;
  margin: 0;
  accent-color: var(--accent);
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 25;
}
.backdrop.show { display: block; }

/* Mobile cards instead of wide tables */
.mobile-list { display: none; }
.m-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #0f1726;
  margin-bottom: 10px;
}
.m-item .m-title { font-weight: 700; margin-bottom: 4px; word-break: break-word; }
.m-item .m-meta { color: var(--muted); font-size: 0.8rem; line-height: 1.4; }
.m-item .m-actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 22px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 6px; font-size: 1.35rem; }
.login-card p { margin: 0 0 18px; color: var(--muted); font-size: 0.92rem; }
.login-card label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 10px 0 4px;
}
.login-card input { width: 100%; }
.login-card button { width: 100%; margin-top: 16px; }
.login-err { color: var(--bad); font-size: 0.88rem; min-height: 1.2em; margin-top: 10px; }

/* Bottom nav mobile */
.bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: #111a2a;
  background: color-mix(in srgb, var(--panel) 96%, black);
  border-top: 1px solid var(--line);
  padding: 6px 6px calc(6px + var(--safe-b));
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
}
.bottom-nav a {
  text-align: center;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 8px 4px;
  border-radius: 10px;
}
.bottom-nav a .ico { display: block; font-size: 1.05rem; margin-bottom: 2px; }
.bottom-nav a.active {
  color: #fff;
  background: rgba(61, 156, 240, 0.22);
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(82vw, 300px);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .topbar { display: flex; }
  .content {
    padding: 14px 14px calc(86px + var(--safe-b));
  }
  .grid2 { grid-template-columns: 1fr; }
  .bottom-nav { display: grid; }
  table { min-width: 640px; }
  .hide-mobile-table .table-wrap { display: none; }
  .hide-mobile-table .mobile-list { display: block; }
  .cap { max-width: 100%; white-space: normal; }
  .page-title { display: none; }
  .topbar h1 { flex: 1; text-align: center; }
  .topbar > span { width: 42px; }
}

@media (max-width: 480px) {
  .content { padding-left: 12px; padding-right: 12px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stats .card:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .card { padding: 12px; }
  .card .value { font-size: 1.25rem; }
  .actions { display: grid; grid-template-columns: 1fr 1fr; }
  .panel > button { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .actions button:first-child { grid-column: 1 / -1; }
  .bottom-nav a { font-size: 0.62rem; padding: 7px 2px; }
  .row { flex-direction: column; align-items: stretch; }
  .row button, .actions button { width: 100%; }
  input, select, textarea, button { font-size: 16px; } /* prevent iOS zoom */
}
