:root {
  --bg: #12151c;
  --panel: #1a1e27;
  --line: #2b3140;
  --text: #e7e9ee;
  --muted: #8b93a7;
  --ok: #3cbf7a;
  --warn: #d98a3b;
  --bad: #d45656;
  --accent: #c9a227;
  --face: #1f6b3a;
  --font-body: "B Nazanin", Tahoma, sans-serif;
  --font-title: "B Titr", Tahoma, sans-serif;
}

@font-face {
  font-family: "B Nazanin";
  src: url("/static/fonts/BNazanin.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "B Nazanin";
  src: url("/static/fonts/BNazaninBold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "B Titr";
  src: url("/static/fonts/BTitrBold.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "B Titr";
  src: url("/static/fonts/BTitrBold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
}
.nav-cam {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font: inherit;
}
.cam-link {
  cursor: pointer;
  font: inherit;
}
h1 { margin: 0; font-size: 22px; font-weight: 400; letter-spacing: 0; font-family: var(--font-title); }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
h2, h3, .modal-sec {
  font-family: var(--font-title);
  font-weight: 400;
}
h2 { margin: 0 0 12px; font-size: 15px; color: var(--muted); }

.status-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  border: 1px solid var(--line);
  padding: 4px 10px;
  font-size: 12px;
  background: var(--panel);
}
.pill.on { border-color: var(--ok); color: var(--ok); }
.pill.open { border-color: var(--accent); color: var(--accent); }

.grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 16px;
  padding: 16px 24px 32px;
}
.wide { grid-column: 1 / -1; }
section, .card, .live {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 14px;
}
.panel-head, .row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.actions { display: flex; gap: 8px; }

.viewport {
  margin-top: 10px;
  background: #0b0d12;
  min-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.viewport img { width: 100%; max-height: 480px; object-fit: contain; display: block; }

button, input, select {
  font: inherit;
  color: var(--text);
  background: #12151c;
  border: 1px solid var(--line);
  padding: 8px 10px;
}
button { cursor: pointer; }
button.primary { background: var(--accent); color: #1a1404; border-color: var(--accent); font-weight: 700; }
button.pill {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 400;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
}
label, .inline { display: block; color: var(--muted); font-size: 12px; margin: 8px 0; }
.inline input, .inline select { margin-top: 6px; width: 100%; }
#source { width: 100%; margin: 8px 0; }
.add { display: grid; grid-template-columns: 1.2fr 1fr auto; gap: 8px; margin-bottom: 10px; }
.list { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow: auto; }
.list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.list button { padding: 2px 8px; }

.iran-plate {
  display: flex;
  flex-direction: row;
  direction: ltr;
  height: 96px;
  border: 3px solid #1b1b1b;
  border-radius: 5px;
  overflow: hidden;
  background: #f3f3f3;
  color: #111;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}
.iran-plate.empty { opacity: 0.55; }
.ip-blue {
  width: 12%;
  min-width: 38px;
  background: #163a8a;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 1px;
  padding: 5px 2px 6px;
  font-family: Tahoma, sans-serif;
  font-size: 8px;
  letter-spacing: 0.04em;
  line-height: 1.1;
}
.ip-flag {
  width: 78%;
  height: 16px;
  margin: 0 0 auto;
  background: linear-gradient(to bottom, #239f40 0 33%, #fff 33% 66%, #da0000 66% 100%);
  border: 1px solid rgba(255, 255, 255, 0.35);
}
.ip-serial {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  background: #f7f7f7;
  color: #111;
  font-family: var(--font-title);
  font-size: 34px;
  letter-spacing: 0.02em;
  padding: 0 6px;
}
.ip-serial span { min-width: 0.7em; text-align: center; }
#ip-letter {
  font-family: "B Nazanin", Tahoma, sans-serif;
  font-weight: 700;
  font-size: 46px;
  line-height: 0.9;
  min-width: 1.25em;
  direction: rtl;
  unicode-bidi: isolate;
}
.ip-city {
  width: 22%;
  min-width: 64px;
  background: #efc000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-left: 2px solid #1b1b1b;
  font-family: var(--font-title);
}
.ip-city-top {
  font-size: 12px;
  line-height: 1;
  margin-bottom: 2px;
}
#ip-city { font-size: 30px; line-height: 1; }
.muted { color: var(--muted); font-size: 13px; }
.err { color: var(--bad); min-height: 1.2em; font-size: 13px; }

.table-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.table-tools input[type="search"] { min-width: 240px; }
.table-wrap { overflow-x: auto; }
.event-form {
  display: grid;
  grid-template-columns: 1.1fr 0.8fr 1fr 0.5fr auto;
  gap: 8px;
  margin: 0 0 12px;
  align-items: end;
}
.event-form[hidden] { display: none; }
.event-form .actions { grid-column: 1 / -1; }
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  white-space: nowrap;
}
.check input { width: auto; margin: 0; }
button.danger { color: var(--bad); border-color: #5a2a2a; }
.pager {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 10px;
}
.ev-thumb { width: 92px; }
.ev-thumb-btn {
  padding: 0;
  background: #0b0d12;
  border: 1px solid var(--line);
  display: block;
}
.ev-thumb-btn img {
  display: block;
  height: 40px;
  max-width: 88px;
  object-fit: contain;
}
.ev-pop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.ev-pop[hidden] { display: none; }
.ev-pop-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 8, 12, 0.78);
}
.ev-pop img {
  position: relative;
  max-width: min(920px, 94vw);
  max-height: 86vh;
  object-fit: contain;
  border: 1px solid var(--line);
  background: #0b0d12;
}
tr.selected td { background: rgba(201, 162, 39, 0.12); }
#ev-sel-info { min-width: 7em; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: right; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 400; font-family: var(--font-title); }
.st-allowed { color: var(--ok); }
.st-denied { color: var(--warn); }
.st-blacklist { color: var(--bad); }

.cam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin: 12px 0 20px;
}
.cam-card {
  border: 1px solid var(--line);
  background: #12151c;
  padding: 12px;
}
.cam-card h3 {
  margin: 0 0 6px;
  font-size: 14px;
}
.cam-card .meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  word-break: break-all;
}
.cam-card label { margin: 6px 0 0; }
.cam-card input, .cam-card select { width: 100%; }
.cam-card .actions { margin-top: 10px; }
.cam-card.anpr { border-color: var(--ok); }
.hint-ok { color: var(--ok); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 8, 12, 0.72);
}
.modal-sheet {
  position: relative;
  width: min(1100px, 100%);
  max-height: min(88vh, 860px);
  overflow: auto;
  background: linear-gradient(180deg, #1e2430 0%, #161a22 100%);
  border: 1px solid #3a4254;
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  padding: 0;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding: 20px 22px 12px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: #1e2430;
  z-index: 1;
}
.modal-head h2 {
  margin: 0;
  font-size: 18px;
  color: var(--text);
}
.modal-head-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  padding: 0;
  background: #12151c;
}
.icon-btn:hover,
#btn-cancel-cams:hover,
#btn-cancel-allowed:hover,
#btn-cancel-black:hover,
#btn-cancel-passages:hover { border-color: var(--accent); }
.modal-toolbar {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 14px 22px 0;
  flex-wrap: wrap;
}
.modal-sheet-list { width: min(720px, 100%); }
.modal-sheet-pass {
  width: min(980px, 100%);
  display: flex;
  flex-direction: column;
  max-height: min(90vh, 880px);
}
.modal-sheet-pass .modal-body { padding: 0; }
.pass-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 0;
  min-height: 0;
  flex: 1;
  border-top: 1px solid var(--line);
  margin-top: 14px;
}
.pass-days {
  border-left: 1px solid var(--line);
  overflow: auto;
  max-height: min(62vh, 560px);
  padding: 10px 8px 16px;
  background: rgba(0, 0, 0, 0.12);
}
.pass-day {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  text-align: right;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 10px;
  margin-bottom: 6px;
}
.pass-day:hover { border-color: var(--line); background: #12151c; }
.pass-day.on {
  border-color: var(--accent);
  background: rgba(201, 162, 39, 0.12);
}
.pass-day .d-title { display: block; font-size: 13px; color: var(--text); line-height: 1.45; }
.pass-day .d-hint { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.pass-day .d-count {
  min-width: 1.8em;
  padding: 2px 7px;
  border-radius: 999px;
  background: #12151c;
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--accent);
}
.pass-main {
  overflow: auto;
  max-height: min(62vh, 560px);
  padding: 4px 18px 20px;
}
.pass-main .modal-sec { margin-top: 10px; }
.pass-list { display: flex; flex-direction: column; gap: 8px; }
.pass-row {
  display: grid;
  grid-template-columns: 88px 72px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: #12151c;
  border-radius: 10px;
}
.pass-row .pass-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.pass-row .pass-plate {
  font-family: var(--font-title);
  font-size: 16px;
  letter-spacing: 0.04em;
  direction: ltr;
  unicode-bidi: isolate;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: 0.28em;
}
.pass-row .pass-plate .p-let {
  font-family: "B Nazanin", Tahoma, sans-serif;
  font-size: 18px;
}
#pass-q { min-width: 240px; flex: 1; }
#btn-cancel-passages:hover { border-color: var(--accent); }
@media (max-width: 760px) {
  .pass-layout { grid-template-columns: 1fr; }
  .pass-days {
    border-left: 0;
    border-bottom: 1px solid var(--line);
    max-height: 160px;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .pass-day { min-width: 170px; margin-bottom: 0; }
  .pass-row { grid-template-columns: 72px 1fr auto; }
  .pass-row .pass-clock { display: none; }
}
.modal-add {
  flex: 1;
  margin: 0;
  min-width: 280px;
}
.modal-body .list { max-height: min(48vh, 420px); }
.modal-body { padding: 8px 22px 24px; }
.modal-sec {
  margin: 18px 0 8px;
  font-size: 15px;
  color: var(--accent);
  font-weight: 400;
}
body.modal-open { overflow: hidden; }

.alert-modal { z-index: 80; }
.alert-modal:not([hidden]) .modal-backdrop {
  animation: alertFade 0.18s ease-out;
}
.alert-sheet {
  width: min(420px, 100%);
  text-align: center;
  padding: 28px 26px 22px;
  overflow: visible;
  animation: alertSheet 0.22s ease-out;
}
.alert-mark {
  width: 58px;
  height: 58px;
  margin: 0 auto 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-family: var(--font-title);
  line-height: 1;
}
.alert-modal[data-kind="error"] .alert-mark,
.alert-modal[data-kind="danger"] .alert-mark {
  background: rgba(212, 86, 86, 0.16);
  color: var(--bad);
  box-shadow: 0 0 0 6px rgba(212, 86, 86, 0.08);
}
.alert-modal[data-kind="warn"] .alert-mark {
  background: rgba(217, 138, 59, 0.16);
  color: var(--warn);
  box-shadow: 0 0 0 6px rgba(217, 138, 59, 0.08);
}
.alert-modal[data-kind="ok"] .alert-mark {
  background: rgba(60, 191, 122, 0.16);
  color: var(--ok);
  box-shadow: 0 0 0 6px rgba(60, 191, 122, 0.08);
}
.alert-modal[data-kind="info"] .alert-mark {
  background: rgba(201, 162, 39, 0.16);
  color: var(--accent);
  box-shadow: 0 0 0 6px rgba(201, 162, 39, 0.08);
}
.alert-sheet h2 {
  margin: 0 0 8px;
  font-size: 20px;
  color: var(--text);
}
.alert-sheet #alert-msg {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.75;
  min-height: 1.5em;
}
.alert-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.alert-actions button { min-width: 108px; }
.alert-actions .danger {
  background: var(--bad);
  color: #fff;
  border-color: var(--bad);
}

@keyframes alertFade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes alertSheet {
  from { transform: translateY(12px) scale(0.97); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@media (max-width: 980px) {
  .grid { grid-template-columns: 1fr; }
    .event-form { grid-template-columns: 1fr; }
  .top { flex-wrap: wrap; }
}
