:root {
  --blue: #1d4ed8;
  --blue-dark: #1e3a8a;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --border: #e2e8f0;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; font-size: 16px; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--blue-dark), var(--blue));
  padding: 16px;
}
.login-card {
  background: white;
  border-radius: 16px;
  padding: 32px 24px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0,0,0,.25);
}
.login-card h1 { margin: 0 0 8px; color: var(--blue-dark); }
.login-card p { color: var(--muted); margin-top: 0; }
.login-card input {
  width: 100%;
  padding: 14px;
  font-size: 20px;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: 10px;
  margin-bottom: 12px;
  letter-spacing: 2px;
}
.login-card button {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: var(--blue);
  color: white;
  font-size: 16px;
  font-weight: 600;
}
.error-text { color: var(--red); font-weight: 600; }

/* ---------- Shell ---------- */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  background: var(--blue-dark);
  color: white;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; }
.brand span { font-weight: 400; opacity: .8; }
.status-bar { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot-offline { background: var(--red); box-shadow: 0 0 6px var(--red); }
.badge {
  background: var(--amber);
  color: white;
  border-radius: 999px;
  padding: 2px 9px;
  font-weight: 700;
  font-size: 12px;
  margin-left: 4px;
}

.tabs {
  display: flex;
  background: white;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 49px;
  z-index: 9;
}
.tab {
  flex: 1;
  padding: 14px 8px;
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 3px solid transparent;
}
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }

main { flex: 1; padding: 16px; max-width: 720px; margin: 0 auto; width: 100%; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-header { display: flex; gap: 8px; margin-bottom: 8px; }
.panel-header input[type=search] {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.sync-note { color: var(--muted); font-size: 12px; margin: 4px 0 12px; }

button.btn-secondary {
  padding: 12px 14px;
  border: 1px solid var(--blue);
  background: white;
  color: var(--blue);
  border-radius: 10px;
  font-weight: 600;
  white-space: nowrap;
}
button.btn-primary {
  padding: 12px 16px;
  border: none;
  background: var(--blue);
  color: white;
  border-radius: 10px;
  font-weight: 700;
}
button.btn-large { width: 100%; padding: 16px; font-size: 16px; margin-top: 16px; }
button.btn-link { border: none; background: none; color: var(--blue); font-weight: 600; padding: 4px; }

.card-list { display: flex; flex-direction: column; gap: 8px; }
.card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
}
.card .card-title { font-weight: 700; margin-bottom: 2px; }
.card .card-sub { color: var(--muted); font-size: 13px; }
.card .card-row { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.stock-ok { color: var(--green); font-weight: 600; }
.stock-low { color: var(--amber); font-weight: 600; }
.stock-zero { color: var(--red); font-weight: 600; }
.pending-tag {
  background: #fef3c7;
  color: var(--amber);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
}

.order-block { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.order-block h2 { font-size: 15px; margin: 0 0 10px; color: var(--blue-dark); }
.picked-box { display: flex; justify-content: space-between; align-items: center; background: #eff6ff; border-radius: 10px; padding: 10px 12px; }
#order-customer-search, #order-item-search { width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 10px; }
.results-list { max-height: 220px; overflow-y: auto; margin-top: 6px; }
.result-item { padding: 10px; border-bottom: 1px solid var(--border); cursor: pointer; }
.result-item:hover, .result-item:active { background: #f1f5f9; }
.result-item .r-sub { color: var(--muted); font-size: 12px; }

.item-add-row { display: flex; gap: 8px; }
.item-add-row input[type=search] { flex: 2; }
.item-add-row input[type=number] { flex: 1; padding: 12px; border: 1px solid var(--border); border-radius: 10px; width: 80px; }

.order-items-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
.order-items-table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 4px 4px; }
.order-items-table td { padding: 8px 4px; border-top: 1px solid var(--border); }
.order-total { text-align: right; font-size: 16px; margin-top: 10px; }
.remove-btn { color: var(--red); border: none; background: none; font-size: 18px; font-weight: 700; }
.qty-warning { color: var(--amber); font-size: 11px; display: block; }

textarea#order-notes { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 10px; resize: vertical; }

.feedback-text { text-align: center; font-weight: 600; margin-top: 10px; padding: 10px; border-radius: 10px; }
.feedback-ok { background: #dcfce7; color: var(--green); }
.feedback-pending { background: #fef3c7; color: var(--amber); }
.feedback-error { background: #fee2e2; color: var(--red); }

.modal {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal-content { background: white; border-radius: 14px; padding: 20px; max-width: 400px; width: 100%; }
.modal-content h2 { margin-top: 0; }
.modal-content label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); font-weight: 600; }
.modal-content input { width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 10px; margin-top: 4px; font-weight: 400; color: var(--text); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: white; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; z-index: 100; max-width: 90%; text-align: center;
}

@media (min-width: 600px) {
  .item-add-row, .panel-header { flex-wrap: nowrap; }
}
