:root {
  --bg: #0f1115;
  --surface: #181b20;
  --surface2: #1f2229;
  --border: #2a2d35;
  --text: #e5e7eb;
  --text-dim: #9ca3af;
  --accent: #3b82f6;
  --green: #10b981;
  --yellow: #f59e0b;
  --red: #ef4444;
  --orange: #f97316;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, sans-serif;
  font-size: 14px;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
input, select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 14px; border-radius: 8px; border: none; cursor: pointer;
  font-weight: 600; font-size: 13px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-sm { padding: 7px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; }

.login-screen {
  min-height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
  background: radial-gradient(circle at top, #1a2332 0%, var(--bg) 55%);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
}
.login-brand { font-size: 20px; font-weight: 800; color: #fff; }
.login-sub { color: var(--text-dim); font-size: 12px; margin: 6px 0 18px; }
.fld { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 12px; font-weight: 600; }
.fld input { margin-top: 6px; }
.err { color: var(--red); font-size: 12px; margin-bottom: 10px; }

.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  background: rgba(24,27,32,0.96);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.top-title { font-weight: 800; color: #fff; font-size: 15px; }
.top-user { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.tabs {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; padding: 10px 12px;
  position: sticky; top: 58px; z-index: 15;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.tab {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  color: var(--text-dim);
  font-weight: 700;
}
.tab.active {
  color: #fff;
  border-color: rgba(59,130,246,0.5);
  background: rgba(59,130,246,0.15);
}

.content { padding: 12px; padding-bottom: 40px; }

.filters {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}
.filters-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.filters label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  font-weight: 700;
}
.filters label > * { margin-top: 4px; }
.filters .span2 { grid-column: span 2; }
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.preset {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 700;
}
.preset.active { color: #fff; border-color: var(--accent); background: rgba(59,130,246,0.18); }

.meta-line {
  display: flex; justify-content: space-between; align-items: center;
  color: var(--text-dim); font-size: 12px; margin: 8px 0 10px;
}
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
}
.card:active { transform: scale(0.99); }
.card img {
  width: 100%; height: 110px; object-fit: cover; background: #0b0d11; display: block;
}
.card-body { padding: 8px 9px 10px; }
.card-title { font-weight: 800; color: #fff; font-size: 13px; font-family: ui-monospace, monospace; }
.card-meta { color: var(--text-dim); font-size: 11px; margin-top: 2px; line-height: 1.35; }
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 7px; border-radius: 999px;
  font-size: 10px; font-weight: 700;
}
.badge-red { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-yellow { background: rgba(245,158,11,0.15); color: var(--yellow); }
.badge-blue { background: rgba(59,130,246,0.15); color: var(--accent); }
.badge-gray { background: rgba(107,114,128,0.2); color: var(--text-dim); }
.badge-green { background: rgba(16,185,129,0.15); color: var(--green); }

.loading, .empty, .error {
  text-align: center; padding: 28px 12px; color: var(--text-dim);
}
.error { color: var(--red); }

.pager {
  display: flex; gap: 8px; justify-content: center; margin-top: 14px;
}

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.72);
  display: flex; align-items: flex-end; justify-content: center;
}
.overlay-sheet {
  width: 100%; max-width: 720px;
  max-height: 92vh;
  overflow: auto;
  background: var(--surface);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  border: 1px solid var(--border);
  padding: 14px;
}
.ov-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
  margin-bottom: 12px; position: sticky; top: 0; background: var(--surface); z-index: 2; padding-bottom: 8px;
}
.ov-title { font-size: 18px; font-weight: 800; color: #fff; font-family: ui-monospace, monospace; }
.img-row { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 12px; }
.img-block { flex: 0 0 auto; width: 42%; min-width: 130px; }
.img-block .lbl { font-size: 10px; color: var(--text-dim); font-weight: 700; text-transform: uppercase; margin-bottom: 4px; }
.img-block img {
  width: 100%; height: 120px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border); background: #0b0d11; cursor: zoom-in;
}
.info-table { width: 100%; font-size: 13px; border-collapse: collapse; margin-bottom: 14px; }
.info-table td { padding: 6px 0; vertical-align: top; }
.info-table td:first-child {
  width: 100px; color: var(--text-dim); font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.section-label {
  font-size: 11px; font-weight: 800; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.06em; margin: 10px 0 8px;
}
.sight-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.sight-table th {
  text-align: left; color: var(--text-dim); font-size: 10px; text-transform: uppercase;
  padding: 6px 4px; border-bottom: 1px solid var(--border);
}
.sight-table td { padding: 7px 4px; border-bottom: 1px solid rgba(255,255,255,0.04); vertical-align: middle; }
.sight-table tr { cursor: pointer; }
.sight-table img { height: 34px; border-radius: 4px; }

.img-viewer {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
}
.img-viewer img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }

.dir-in { color: var(--green); font-weight: 800; }
.dir-out { color: var(--red); font-weight: 800; }

@media (min-width: 720px) {
  .overlay { align-items: center; }
  .overlay-sheet { border-radius: 16px; max-height: 88vh; }
  .grid-cards { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

/* equal-height filter controls */
.filters input.ctrl,
.filters select.ctrl,
.filters input[type="datetime-local"] {
  min-height: 44px;
  height: 44px;
  padding: 0 12px;
  line-height: 42px;
  border-radius: 8px;
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}
.filters select.ctrl {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%), linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 16px) calc(50% - 3px), calc(100% - 11px) calc(50% - 3px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
}
.preset-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  margin-bottom: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}
.preset {
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 8px 6px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.preset.active { color: #fff; border-color: var(--accent); background: rgba(59,130,246,0.18); }
.custom-range {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}
.custom-range label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  font-weight: 700;
}
.custom-range label > * { margin-top: 4px; }

/* no-ios-zoom: iOS Safari zooms focused inputs if font-size < 16px */
input, select, textarea {
  font-size: 16px !important;
}
.filters input.ctrl,
.filters select.ctrl,
.filters input[type="datetime-local"],
.login-card input,
#pw-screen input {
  font-size: 16px !important;
  line-height: normal;
  min-height: 44px;
  height: 44px;
}
