/* ===================================================================
   POS Service AC - Mobile-first stylesheet
   =================================================================== */
:root {
  --primary: #0284c7;
  --primary-dark: #0369a1;
  --primary-light: #e0f2fe;
  --accent: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

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

a { color: inherit; text-decoration: none; }

/* ---------- Layout shell ---------- */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.topbar h1 {
  font-size: 1.1rem;
  margin: 0;
  font-weight: 700;
}

.topbar .sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.icon-btn {
  background: var(--primary-light);
  color: var(--primary-dark);
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
}

.main-content {
  flex: 1;
  padding: 14px 14px calc(env(safe-area-inset-bottom, 0px) + 90px);
  overflow-y: auto;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 6px 4px calc(env(safe-area-inset-bottom, 0px) + 6px);
  z-index: 30;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px;
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 0.65rem;
  cursor: pointer;
  border: none;
  background: none;
}

.nav-item .nav-icon { font-size: 1.25rem; }

.nav-item.active {
  color: var(--primary);
  font-weight: 600;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}

.card-title {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.stat-card .label {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-card .value {
  font-size: 1.25rem;
  font-weight: 800;
}

.stat-card.accent .value { color: var(--accent); }
.stat-card.warning .value { color: var(--warning); }
.stat-card.primary .value { color: var(--primary); }

/* ---------- Lists ---------- */
.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  cursor: pointer;
}

.list-item .avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

.list-item .info { flex: 1; min-width: 0; }
.list-item .info .title { font-weight: 600; font-size: 0.92rem; }
.list-item .info .desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge.pending { background: #fef3c7; color: #92400e; }
.badge.scheduled { background: #dbeafe; color: #1e40af; }
.badge.in_progress { background: #e0e7ff; color: #4338ca; }
.badge.completed { background: #dcfce7; color: #166534; }
.badge.cancelled { background: #fee2e2; color: #991b1b; }
.badge.unpaid { background: #fee2e2; color: #991b1b; }
.badge.partial { background: #fef3c7; color: #92400e; }
.badge.paid { background: #dcfce7; color: #166534; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.form-row { display: flex; gap: 10px; }
.form-row .form-group { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 13px 16px;
  border-radius: 12px;
  border: none;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: var(--primary-light); color: var(--primary-dark); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-outline { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-sm { padding: 8px 12px; font-size: 0.82rem; width: auto; }
.btn-block-row { display: flex; gap: 10px; }
.btn-block-row .btn { flex: 1; }

.fab {
  position: fixed;
  right: calc((100vw - min(560px, 100vw)) / 2 + 18px);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 78px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 1.6rem;
  border: none;
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.4);
  cursor: pointer;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Sheet / modal ---------- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 50;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.sheet-overlay.open { display: flex; }

.sheet {
  background: var(--surface);
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(env(safe-area-inset-bottom, 0px) + 18px);
  overflow-y: auto;
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  margin: 0 auto 14px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sheet-header h2 { font-size: 1.05rem; margin: 0; }

/* ---------- Utility ---------- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state .emoji { font-size: 2.5rem; margin-bottom: 8px; }

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 12px;
}

.search-bar input {
  border: none;
  flex: 1;
  background: transparent;
}
.search-bar input:focus { outline: none; }

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
}

.tab-chip {
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
}

.tab-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.section-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 18px 0 8px;
}

.section-title:first-child { margin-top: 0; }

.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.85rem;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show { opacity: 1; }

.spinner {
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  animation: spin 0.7s linear infinite;
  margin: 30px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

.divider { height: 1px; background: var(--border); margin: 14px 0; }

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.82rem; }
.text-lg { font-size: 1.1rem; }
.font-bold { font-weight: 700; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }

/* ---------- Login page ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
  max-width: 420px;
  margin: 0 auto;
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .emoji { font-size: 3rem; }
.login-logo h1 { font-size: 1.4rem; margin: 8px 0 2px; }
.login-logo p { color: var(--text-muted); font-size: 0.85rem; margin: 0; }

.error-msg {
  background: #fee2e2;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.82rem;
  margin-bottom: 12px;
  display: none;
}

.error-msg.show { display: block; }

/* ---------- Print invoice ---------- */
.invoice-preview {
  background: #fff;
  color: #000;
  padding: 16px;
  border-radius: 10px;
  font-family: 'Courier New', monospace;
  font-size: 0.82rem;
  border: 1px dashed var(--border);
}

.invoice-preview .center { text-align: center; }
.invoice-preview hr { border: none; border-top: 1px dashed #999; margin: 8px 0; }
.invoice-preview .row { display: flex; justify-content: space-between; gap: 8px; }

@media print {
  body * { visibility: hidden; }
  #printArea, #printArea * { visibility: visible; }
  #printArea {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
  }
}
