:root {
  --orange: #f39200;
  --orange-dark: #d97e00;
  --ink: #1d1d1b;
  --gray: #6b7280;
  --line: #e5e7eb;
  --bg: #f5f6f8;
  --card: #ffffff;
  --input-bg: #ffffff;
  --ok: #16a34a;
  --err: #dc2626;
  --badge-ok-bg: #dcfce7;
  --badge-err-bg: #fee2e2;
  --dir-vhod-bg: #dcfce7;
  --dir-izhod-bg: #ffedd5;
  --switch-off: #cccccc;
  --switch-knob: #ffffff;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e8e9ec;
  --gray: #9aa1ad;
  --line: #2c3038;
  --bg: #121419;
  --card: #1d2129;
  --input-bg: #14171c;
  --ok: #34d27b;
  --err: #f06363;
  --badge-ok-bg: #14361f;
  --badge-err-bg: #3a1a1a;
  --dir-vhod-bg: #14361f;
  --dir-izhod-bg: #3a2a12;
  --switch-off: #444a55;
  --switch-knob: #e8e9ec;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Arial, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  min-height: 100%;
}
header {
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  max-width: 880px; margin: 0 auto; padding: 14px 18px;
  display: flex; align-items: center; justify-content: space-between;
}
header .brand { font-weight: bold; font-size: 18px; }
header .brand b { color: var(--orange); }
header .who { font-size: 13px; color: var(--gray); }
header .who a { color: var(--orange); cursor: pointer; text-decoration: none; margin-left: 10px; }
main { flex: 1; width: 100%; max-width: 880px; margin: 0 auto; padding: 22px 18px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 18px;
}
h2 { margin: 0 0 14px; font-size: 16px; }
label { display: block; font-size: 13px; color: var(--gray); margin: 10px 0 4px; }
input[type=text], input[type=password], input[type=number], input[type=tel], textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 15px;
  background: var(--input-bg); color: var(--ink);
}
button {
  font-family: inherit; cursor: pointer; border: none; border-radius: 8px;
  padding: 10px 16px; font-size: 15px; font-weight: bold; color: #fff;
  background: var(--orange);
}
button:hover { background: var(--orange-dark); }
button.secondary { background: var(--card); color: var(--ink); border: 1px solid var(--line); font-weight: normal; }
button.danger { background: var(--err); }
button:disabled { opacity: .5; cursor: not-allowed; }

.gate { text-align: center; padding: 28px 20px; }
.gate .name { font-size: 20px; font-weight: bold; margin-bottom: 4px; }
.gate .sim { font-size: 13px; color: var(--gray); margin-bottom: 22px; }
.open-btn {
  width: 220px; height: 220px; border-radius: 50%; font-size: 26px;
  box-shadow: 0 8px 24px rgba(243,146,0,.35);
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform .08s;
}
.open-btn:active { transform: scale(.96); }

.msg { margin-top: 16px; font-size: 15px; min-height: 22px; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--err); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--gray); font-weight: normal; }
.badge { padding: 1px 8px; border-radius: 999px; font-size: 12px; }
.badge.ok { background: var(--badge-ok-bg); color: var(--ok); }
.badge.err { background: var(--badge-err-bg); color: var(--err); }

.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > div { flex: 1; min-width: 140px; }
.muted { color: var(--gray); font-size: 13px; }
.hidden { display: none !important; }
.login-wrap { max-width: 360px; margin: 8vh auto; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.menu-wrap { position: relative; }
.menu-toggle { display: none; width: 100%; text-align: left; background: var(--card); color: var(--ink); border: 1px solid var(--line); font-weight: bold; font-size: 17px; padding: 13px 16px; border-radius: 8px; margin-bottom: 12px; }
.tabs button { background: var(--card); color: var(--gray); border: 1px solid var(--line); font-weight: normal; }
.tabs button.active { background: var(--orange); color: #fff; border-color: var(--orange); }
footer { text-align: center; padding: 14px; color: var(--gray); font-size: 12px; }

/* Zasedenost (glavni podatek) */
.occ-hero {
  background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--orange);
  border-radius: 12px; padding: 18px 22px; margin-bottom: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.occ-num { font-size: 44px; font-weight: bold; line-height: 1; color: var(--orange); }
.occ-lbl { font-size: 14px; color: var(--gray); margin-top: 4px; }
.occ-reset { font-size: 13px; padding: 8px 12px; }

/* Statistika */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; text-align: center; }
.stat .num { font-size: 28px; font-weight: bold; }
.stat .num.err { color: var(--err); }
.stat .lbl { font-size: 12px; color: var(--gray); margin-top: 2px; }

/* Rampe (vhod + izhod) */
.gates { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.gates .gate { margin-bottom: 0; }
.gates .open-btn { width: 150px; height: 150px; font-size: 20px; }

/* Smer */
.dir { padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: bold; }
.dir.vhod { background: var(--dir-vhod-bg); color: var(--ok); }
.dir.izhod { background: var(--dir-izhod-bg); color: var(--orange); }

/* Izbirnik / iskanje */
.sel, input[type=text]#mem-search { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; background: var(--input-bg); color: var(--ink); }
input#mem-search { width: 100%; }

/* Stikalo (aktiven) */
.sw { position: relative; display: inline-block; width: 40px; height: 22px; }
.sw input { opacity: 0; width: 0; height: 0; }
.sw span { position: absolute; inset: 0; background: var(--switch-off); border-radius: 999px; cursor: pointer; transition: .2s; }
.sw span::before { content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px; background: var(--switch-knob); border-radius: 50%; transition: .2s; }
.sw input:checked + span { background: var(--ok); }
.sw input:checked + span::before { transform: translateX(18px); }

.gatecfg { padding: 12px 0; border-bottom: 1px solid var(--line); }
.gatecfg:last-child { border-bottom: none; }

/* Grafi (statistika) */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 180px; overflow-x: auto; padding-top: 6px; }
.bar-col { flex: 1 0 auto; min-width: 14px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar-stack, .bar-single { width: 70%; min-height: 2px; border-radius: 3px 3px 0 0; display: flex; flex-direction: column; }
.bar-single { background: var(--orange); }
.bar-stack { overflow: hidden; }
.seg-vhod { background: var(--ok); }
.seg-izhod { background: var(--orange); }
.bar-lbl { font-size: 10px; color: var(--gray); margin-top: 4px; white-space: nowrap; }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--gray); margin-top: 8px; }
.chart-legend span::before { content: "■ "; }
.lg-vhod::before { color: var(--ok); }
.lg-izhod::before { color: var(--orange); }

/* Top uporabniki */
.urow { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.urow-name { flex: 0 0 38%; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.urow-bar { flex: 1; background: var(--line); border-radius: 999px; height: 14px; overflow: hidden; }
.urow-bar > div { height: 100%; background: var(--orange); border-radius: 999px; }
.urow-c { flex: 0 0 auto; font-size: 13px; font-weight: bold; min-width: 70px; text-align: right; }

/* Naročninski paketi */
.plan-edit { border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 14px; }
.days { display: flex; flex-wrap: wrap; gap: 6px; }
.daybox { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--ink); background: var(--input-bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; margin: 0; }

/* Admin: nastavitve ramp + uporabniki drug ob drugem */
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.admin-grid .card { margin-bottom: 0; }

@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .gates { grid-template-columns: 1fr; }
  .admin-grid { grid-template-columns: 1fr; }
  /* zavihki v hamburger meni — odpre se PREKO vsebine (overlay) */
  .menu-toggle { display: block; }
  .tabs { display: none; }
  .tabs.open {
    display: flex; flex-direction: column; gap: 6px;
    position: absolute; top: calc(100% - 6px); left: 0; right: 0; z-index: 100;
    background: var(--card); border: 1px solid var(--line); border-radius: 10px;
    padding: 8px; box-shadow: 0 12px 32px rgba(0,0,0,.35);
  }
  .tabs button { width: 100%; text-align: left; padding: 12px 16px; font-size: 16px; }
  /* obrazci v vrstici se zložijo navpično (!important preglasi inline flex:0) */
  .row > div { flex: 1 1 100% !important; min-width: 0 !important; }
  .gatecfg .row [data-mode], .gatecfg .row input { width: 100% !important; }
  .gatecfg .row button { width: 100%; }
  /* tabele drsijo znotraj kartice, ne celotne strani */
  .card table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  main { padding: 16px 12px; }
}
html, body { overflow-x: hidden; }

/* Logo */
.brand-logo { height: 22px; display: inline-block; vertical-align: middle; }
.brand .sep { color: var(--gray); font-weight: normal; margin: 0 4px; }
.logo-dark { display: none; }
:root[data-theme="dark"] .logo-light { display: none; }
:root[data-theme="dark"] .logo-dark { display: inline-block; }

/* Preklop teme */
.theme-toggle {
  background: transparent; border: 1px solid var(--line); color: var(--ink);
  width: 34px; height: 34px; padding: 0; border-radius: 8px; font-size: 16px; font-weight: normal;
  display: inline-flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { background: var(--card); }
.who { display: inline-flex; align-items: center; gap: 12px; }
