:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-soft: #475569;
  --ink-mute: #94a3b8;
  --border: #e2e8f0;
  --accent: #0f172a;
  --accent-2: #2563eb;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 12px rgba(15,23,42,.04);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 15px; line-height: 1.4;
  overscroll-behavior-y: contain;
}

#app { max-width: 640px; margin: 0 auto; padding: 0 0 90px; min-height: 100vh; }

.appbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 14px 16px; display: flex; align-items: center; gap: 12px;
}
.appbar .title { font-weight: 600; font-size: 16px; flex: 1; }
.appbar .sub { color: var(--ink-mute); font-size: 12px; }
.appbar .back { background: transparent; border: 0; padding: 6px; color: var(--ink-soft); cursor: pointer; font-size: 18px; }
.appbar .action { background: transparent; border: 0; color: var(--accent-2); font-weight: 500; cursor: pointer; font-size: 14px; padding: 6px 8px; }

.page { padding: 16px; }

/* Login */
.login-wrap {
  min-height: calc(100vh - 40px); display: flex; flex-direction: column; justify-content: center; padding: 24px;
}
.brand { text-align: center; margin-bottom: 32px; }
.brand-mark {
  width: 56px; height: 56px; border-radius: 14px; margin: 0 auto 12px;
  background: var(--ink); color: white; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 22px; letter-spacing: -0.5px;
}
.brand h1 { margin: 0; font-size: 22px; font-weight: 600; }
.brand p { margin: 4px 0 0; color: var(--ink-mute); font-size: 13px; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px;
}

label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; font-weight: 500; }
select, input[type="text"], input[type="number"], input[type="password"], input[type="file"] {
  width: 100%; padding: 12px 14px; font-size: 16px; border: 1px solid var(--border);
  border-radius: 10px; background: white; color: var(--ink); outline: none;
  font-family: inherit;
}
select:focus, input:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
input[readonly] { background: #f8fafc; color: var(--ink-mute); }

.field { margin-bottom: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 18px; border-radius: 10px; border: 0; cursor: pointer;
  font-family: inherit; font-size: 15px; font-weight: 500;
  transition: transform .05s ease, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: white; }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-outline { background: white; color: var(--ink); border: 1px solid var(--border); }
.btn-block { width: 100%; }
.btn-danger { background: var(--danger); color: white; }
.btn-ok { background: var(--ok); color: white; }
.btn-sm { padding: 8px 12px; font-size: 13px; }

.tabs { display: flex; gap: 4px; padding: 4px; background: #e2e8f0; border-radius: 10px; margin-bottom: 14px; }
.tabs button {
  flex: 1; padding: 8px 10px; border: 0; background: transparent; border-radius: 8px;
  font-family: inherit; font-size: 14px; color: var(--ink-soft); cursor: pointer; font-weight: 500;
}
.tabs button.active { background: white; color: var(--ink); box-shadow: var(--shadow); }

/* Session list */
.session-row {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; margin-bottom: 10px; cursor: pointer;
  display: flex; align-items: center; gap: 12px;
}
.session-row:active { background: #f8fafc; }
.session-row .info { flex: 1; min-width: 0; }
.session-row .title { font-weight: 600; margin-bottom: 4px; }
.session-row .meta { color: var(--ink-mute); font-size: 12px; }
.session-row .progress {
  min-width: 54px; text-align: center; padding: 6px 10px; border-radius: 8px;
  background: var(--ok-bg); color: var(--ok); font-size: 12px; font-weight: 600;
}
.session-row .progress.mid { background: var(--warn-bg); color: var(--warn); }
.session-row .progress.low { background: #f1f5f9; color: var(--ink-soft); }

.empty { text-align: center; padding: 60px 20px; color: var(--ink-mute); }
.empty .em { font-size: 44px; margin-bottom: 8px; }

/* Item list */
.search-bar {
  position: sticky; top: 62px; z-index: 10; background: var(--bg);
  padding: 10px 16px; margin: 0 -16px 8px;
}
.search-bar input { padding: 10px 14px; }

.progress-bar {
  height: 4px; background: #e2e8f0; border-radius: 2px; overflow: hidden; margin-bottom: 12px;
}
.progress-bar > div { height: 100%; background: var(--ok); transition: width .3s; }

.item-row {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 8px; cursor: pointer;
  display: flex; align-items: center; gap: 12px;
}
.item-row .name { font-size: 14px; font-weight: 500; margin-bottom: 3px; }
.item-row .sku { font-size: 12px; color: var(--ink-mute); font-family: ui-monospace, monospace; }
.item-row .info { flex: 1; min-width: 0; }
.item-row .info .name, .item-row .info .sku {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item-row .status {
  min-width: 66px; text-align: right; font-size: 12px; color: var(--ink-mute);
}
.item-row.counted .status { color: var(--ok); font-weight: 500; }
.item-row.counted-neg { background: #fef2f2; border-color: #fecaca; }
.item-row.counted-neg .status { color: var(--danger); }

/* Count card modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 30;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadein .15s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--card); width: 100%; max-width: 640px;
  border-radius: 20px 20px 0 0; padding: 20px 20px 24px; max-height: 92vh; overflow-y: auto;
  animation: slideup .2s ease;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal .grabber { width: 40px; height: 4px; background: #cbd5e1; border-radius: 2px; margin: 0 auto 14px; }
.modal h3 { margin: 0 0 4px; font-size: 17px; }
.modal .sub { color: var(--ink-mute); font-size: 13px; margin-bottom: 16px; font-family: ui-monospace, monospace; }
.modal .sys-qty { background: #f1f5f9; padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center; }
.modal .sys-qty .num { font-size: 22px; font-weight: 600; }
.modal .counted-by { font-size: 12px; color: var(--warn); background: var(--warn-bg); padding: 8px 12px; border-radius: 8px; margin-bottom: 12px; }

.count-row { display: flex; gap: 8px; align-items: stretch; }
.count-row input { flex: 1; text-align: center; font-size: 20px; font-weight: 600; }
.count-row .btn { white-space: nowrap; }

/* Bottom bar */
.bottom-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 15;
  background: var(--card); border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex; gap: 8px;
  max-width: 640px; margin: 0 auto;
}

/* Staff / settings */
.staff-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.staff-item:last-child { border-bottom: 0; }
.staff-item .name { flex: 1; font-weight: 500; }
.staff-item .role { font-size: 12px; padding: 3px 8px; border-radius: 6px; }
.role.manager { background: #ede9fe; color: #6d28d9; }
.role.staff { background: #dbeafe; color: #1e40af; }

.log-item {
  padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.log-item .when { color: var(--ink-mute); font-size: 12px; }
.log-item .who { font-weight: 500; }
.log-item .what { color: var(--ink-soft); }

.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: white; padding: 12px 18px; border-radius: 10px;
  z-index: 50; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.2);
  animation: fadein .2s ease;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

.section-title { font-size: 13px; color: var(--ink-mute); text-transform: uppercase; letter-spacing: 0.4px; margin: 20px 0 10px; font-weight: 600; }

.hstack { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }

@media (max-width: 400px) {
  body { font-size: 14px; }
  .modal .sys-qty .num { font-size: 20px; }
}
