:root {
  --navy: #111a3a;
  --indigo: #2b3a8c;
  --accent: #ff7a1a;
  --accent-dark: #e56505;
  --bg: #f2f4fa;
  --card: #ffffff;
  --text: #17203a;
  --muted: #6b7591;
  --line: #e3e7f2;
  --ok: #129a5b;
  --danger: #d6323a;
  --radius: 16px;
  --shadow: 0 6px 20px rgba(17, 26, 58, .08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
}
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
h2 { font-size: 20px; margin: 4px 0 14px; }
h3 { font-size: 16px; margin: 0 0 10px; }

/* ---------- top bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(120deg, var(--navy), var(--indigo));
  color: #fff;
  box-shadow: 0 2px 12px rgba(17, 26, 58, .3);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand-mark {
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 800; letter-spacing: 1px;
  padding: 6px 8px; border-radius: 9px;
}
.user-chip {
  background: rgba(255, 255, 255, .14); padding: 6px 12px; border-radius: 999px;
  font-size: 13px; max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- layout ---------- */
#view {
  max-width: 760px; margin: 0 auto;
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
}
.made-by { text-align: center; color: var(--muted); font-size: 12px; margin: 28px 0 4px; letter-spacing: .3px; }
.made-by b { color: var(--indigo); }

/* ---------- bottom nav ---------- */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around; align-items: flex-end;
  background: #fff; border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 18px rgba(17, 26, 58, .06);
}
#nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--muted); padding: 6px 0; border-radius: 12px;
}
#nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#nav a.active { color: var(--indigo); font-weight: 600; }
#nav a.nav-new svg {
  width: 48px; height: 48px; padding: 12px; margin-top: -22px;
  background: var(--accent); color: #fff; border-radius: 50%;
  box-shadow: 0 6px 16px rgba(255, 122, 26, .45); stroke-width: 2.6;
}

/* ---------- cards, forms, buttons ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
label.field { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; font-weight: 600; }
input[type=text], input[type=password], input[type=search], input[type=date] {
  display: block; width: 100%; margin-top: 6px;
  font: inherit; color: var(--text);
  padding: 13px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff;
  outline: none;
}
input:focus { border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(43, 58, 140, .12); }
input.mono { font-family: ui-monospace, Consolas, monospace; letter-spacing: 1.5px; text-transform: uppercase; font-size: 17px; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 12px 16px; border-radius: 12px; border: 1.5px solid var(--line);
  background: #fff; color: var(--text); min-height: 46px;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 6px 16px rgba(255, 122, 26, .3); }
.btn.dark { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.danger { color: var(--danger); border-color: #f3c7c9; background: #fff5f5; }
.btn.block { width: 100%; }
.btn.sm { padding: 8px 12px; min-height: 38px; font-size: 13px; border-radius: 10px; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > .btn { flex: 1; }

/* ---------- login ---------- */
.login-wrap { min-height: calc(100vh - 32px); display: flex; flex-direction: column; justify-content: center; max-width: 400px; margin: 0 auto; }
.login-hero {
  background: linear-gradient(140deg, var(--navy), var(--indigo)); color: #fff;
  border-radius: 24px 24px 0 0; padding: 34px 24px 46px; text-align: center;
}
.login-hero .brand-mark { font-size: 20px; padding: 12px 16px; border-radius: 16px; display: inline-block; margin-bottom: 14px; }
.login-hero h1 { margin: 0; font-size: 26px; }
.login-hero p { margin: 6px 0 0; opacity: .8; font-size: 14px; }
.login-card { margin-top: -22px; border-radius: 22px; padding: 22px; }
.err { color: var(--danger); font-size: 14px; margin: 0 0 12px; }

/* ---------- list ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.stat { background: linear-gradient(135deg, var(--navy), var(--indigo)); color: #fff; border-radius: var(--radius); padding: 14px 16px; }
.stat.alt { background: linear-gradient(135deg, var(--accent), #ffa24d); }
.stat b { display: block; font-size: 26px; line-height: 1.1; }
.stat span { font-size: 12px; opacity: .85; }
.search { position: sticky; top: calc(58px + env(safe-area-inset-top)); z-index: 5; margin-bottom: 12px; }
.search input { margin: 0; box-shadow: var(--shadow); border-color: transparent; }
.vlist { display: grid; gap: 10px; }
@media (min-width: 640px) { .vlist { grid-template-columns: 1fr 1fr; } }
.vcard { display: flex; gap: 12px; align-items: center; background: #fff; border-radius: 14px; padding: 10px; box-shadow: var(--shadow); }
.vthumb { width: 62px; height: 62px; border-radius: 10px; object-fit: cover; background: #dfe4f1; flex: none; }
.vinfo { min-width: 0; flex: 1; }
.vch { font-family: ui-monospace, Consolas, monospace; font-weight: 700; font-size: 15px; letter-spacing: .5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vmeta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #fff1e5; color: var(--accent-dark); }
.badge.ok { background: #e4f6ec; color: var(--ok); }
.badge.off { background: #fde8e9; color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.skeleton { height: 82px; border-radius: 14px; background: linear-gradient(90deg, #e6eaf4 25%, #f3f5fb 50%, #e6eaf4 75%); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- photo slots ---------- */
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 6px 0 16px; }
@media (max-width: 460px) { .slots { grid-template-columns: 1fr; } }
.slot { background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 10px; }
.slot-prev {
  position: relative; aspect-ratio: 4 / 3; border-radius: 10px; overflow: hidden;
  background: #eef1f8; border: 2px dashed #c9d0e3;
  display: flex; align-items: center; justify-content: center; color: #9aa4c0; cursor: pointer;
}
.slot.has .slot-prev { border-style: solid; border-color: var(--ok); }
.slot-prev img { width: 100%; height: 100%; object-fit: cover; }
.slot-prev svg { width: 38px; height: 38px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.slot-title { font-weight: 700; font-size: 14px; margin: 8px 0 2px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.slot-sub { font-size: 12px; color: var(--muted); min-height: 17px; margin-bottom: 8px; }
.slot .row { gap: 6px; }

/* ---------- detail ---------- */
.dhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.dch { font-family: ui-monospace, Consolas, monospace; font-size: 19px; font-weight: 800; letter-spacing: 1px; word-break: break-all; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--indigo); font-weight: 600; font-size: 14px; margin-bottom: 10px; }

/* ---------- admin ---------- */
.tabs { display: flex; background: #e4e8f3; border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.tabs a { flex: 1; text-align: center; padding: 9px 4px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); }
.tabs a.active { background: #fff; color: var(--indigo); box-shadow: 0 2px 6px rgba(17, 26, 58, .1); }
.urow { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.urow:first-child { border-top: 0; }
.urow .uinfo { flex: 1; min-width: 140px; }
.urow .uname { font-weight: 700; }
.urow .uid { font-size: 12px; color: var(--muted); }
.bar { height: 14px; background: #e4e8f3; border-radius: 999px; overflow: hidden; margin: 10px 0 6px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--ok), #5cc98f); border-radius: 999px; }
.bar.warn i { background: linear-gradient(90deg, var(--accent), #ffa24d); }
.bar.full i { background: linear-gradient(90deg, var(--danger), #f0787e); }
.log { font-size: 13px; padding: 9px 0; border-top: 1px solid var(--line); }
.log:first-child { border-top: 0; }
.log small { color: var(--muted); display: block; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- overlays ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--navy); color: #fff; padding: 11px 18px; border-radius: 12px; font-size: 14px;
  max-width: 90vw; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.bad { background: var(--danger); }
#toast.good { background: var(--ok); }
#busy, #modal { position: fixed; inset: 0; z-index: 50; background: rgba(17, 26, 58, .55); display: flex; align-items: center; justify-content: center; padding: 20px; }
.busy-box { background: #fff; border-radius: 18px; padding: 24px 28px; text-align: center; min-width: 200px; max-width: 320px; }
.spinner { width: 38px; height: 38px; border: 4px solid #e4e8f3; border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 12px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.modal-box { background: #fff; border-radius: 18px; padding: 20px; width: 100%; max-width: 380px; }
.modal-box p { color: var(--muted); margin: 0 0 14px; font-size: 14px; }
#viewer { position: fixed; inset: 0; z-index: 70; background: #000; display: flex; align-items: center; justify-content: center; }
#viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
#viewer button { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 12px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .2); color: #fff; font-size: 28px; line-height: 1; }
