/* styles.css — Giao diện CH Mai Phương — Phiếu Tạm Tính
   Bảng màu: Teal Market (chính), Mango Pop (giá tiền/CTA), Coral Spark (nhấn phụ) */

:root {
  --primary: #0e7c66;
  --primary-dark: #0a5c4c;
  --primary-darker: #073f34;
  --primary-light: #e3f5ef;
  --primary-light2: #cdf0e3;
  --accent: #f2994a;
  --accent-dark: #d97f2e;
  --accent-light: #fff1e2;
  --coral: #ff6f61;
  --coral-light: #ffe9e6;
  --danger: #e5484d;
  --success: #1e9e6b;
  --warn: #d97706;
  --bg: #f6f9f7;
  --card-bg: #ffffff;
  --border: #e3ebe7;
  --text: #16201d;
  --text-muted: #6b7b76;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --tab-height: 60px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  overscroll-behavior-y: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: -webkit-fill-available;
}

/* ---------- Header ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(120deg, var(--primary-darker) 0%, var(--primary) 55%, #169c80 100%);
  color: white;
  padding: calc(12px + var(--safe-top)) 16px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 14px rgba(10, 60, 50, 0.22);
  border-radius: 0 0 18px 18px;
}

.header-titles {
  display: flex;
  align-items: center;
  gap: 10px;
}

.shop-badge {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(145deg, var(--accent) 0%, var(--coral) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  color: white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
  letter-spacing: 0.2px;
}

.app-header .shop-name {
  font-size: 17px;
  font-weight: 800;
  margin: 0;
  letter-spacing: 0.1px;
  line-height: 1.15;
}

.app-header .header-sub {
  font-size: 12px;
  opacity: 0.88;
  font-weight: 500;
  margin-top: 1px;
}

/* ---------- Main scroll area ---------- */

.app-main {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px calc(20px + var(--tab-height) + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}

.screen { display: none; }
.screen.active { display: block; animation: fadeIn 0.15s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Cards ---------- */

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 2px 10px rgba(14, 124, 102, 0.06);
  border: 1px solid var(--border);
}

.card-title {
  font-size: 12.5px;
  font-weight: 800;
  color: var(--primary-dark);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  padding-left: 10px;
  border-left: 4px solid var(--accent);
  line-height: 1.3;
}

/* ---------- Form elements ---------- */

label.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 600;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="search"],
textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  font-size: 16px;
  background: #fbfbfc;
  color: var(--text);
  font-family: inherit;
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px var(--primary-light);
}

.field-row { margin-bottom: 12px; }
.field-row:last-child { margin-bottom: 0; }
.field-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.readonly-pill {
  background: var(--primary-light);
  border: 1.5px solid var(--primary-light2);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--primary-dark);
  min-height: 20px;
}

/* ---------- Buttons ---------- */

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  border-radius: 11px;
  font-size: 15px;
  font-weight: 700;
  width: 100%;
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  box-shadow: 0 3px 8px rgba(14, 124, 102, 0.28);
}
.btn-primary:active { filter: brightness(0.95); }

.btn-accent {
  background: linear-gradient(135deg, var(--accent) 0%, var(--coral) 100%);
  color: white;
  box-shadow: 0 3px 10px rgba(242, 153, 74, 0.35);
}
.btn-accent:active { filter: brightness(0.95); }

.btn-outline {
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1.5px solid var(--primary-light2);
  box-shadow: none;
}

.btn-danger { background: var(--danger); color: white; }

.btn-secondary { background: #eef2f0; color: var(--text); box-shadow: none; }

.btn-sm { padding: 7px 12px; font-size: 13px; width: auto; }

.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row .btn { flex: 1; }

.icon-btn {
  background: transparent;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 18px;
}
.icon-btn:active { background: var(--primary-light); }

/* ---------- Search-select component ---------- */

.search-select { position: relative; }

.search-select .selected-display {
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary-light2) 100%);
  border: 1.5px solid var(--primary-light2);
  border-radius: 11px;
  padding: 11px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.selected-display .selected-info b { display: block; font-size: 14.5px; color: var(--primary-dark); }
.selected-display .selected-info span { font-size: 12.5px; color: var(--text-muted); }

.search-results {
  margin-top: 6px;
  border-radius: 11px;
  overflow: hidden;
  border: 1px solid var(--border);
  max-height: 280px;
  overflow-y: auto;
  background: white;
  box-shadow: 0 4px 14px rgba(14, 124, 102, 0.1);
}

.search-result-item {
  padding: 10px 12px;
  border-bottom: 1px solid #f0f3f1;
  display: flex;
  flex-direction: column;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:active { background: var(--primary-light); }

.search-result-item .r-title { font-weight: 700; font-size: 14.5px; }
.search-result-item .r-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.search-result-item .r-price { font-size: 13px; color: var(--accent-dark); font-weight: 800; margin-top: 2px; }

.search-empty {
  padding: 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
}

/* ---------- Cart table ---------- */

.cart-list { display: flex; flex-direction: column; gap: 8px; }

.cart-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: #fbfdfc;
  border-left: 3px solid var(--primary-light2);
}

.cart-item-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.cart-item-name { font-weight: 700; font-size: 14.5px; line-height: 1.3; }
.cart-item-unit { font-size: 12px; color: var(--text-muted); }

.cart-item-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 6px;
}

.cart-item-field { display: flex; flex-direction: column; gap: 3px; }
.cart-item-field label { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.cart-item-field input { padding: 8px 9px; font-size: 14.5px; }

.cart-item-sub {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

.cart-item-sub .sub-amount { font-weight: 800; color: var(--accent-dark); font-size: 15px; }

.empty-state {
  text-align: center;
  padding: 30px 16px;
  color: var(--text-muted);
}
.empty-state .empty-icon {
  font-size: 32px;
  margin-bottom: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--primary-light);
}
.empty-state .empty-text { font-size: 14px; }

/* ---------- Totals ---------- */

.totals-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  font-size: 15px;
  background: linear-gradient(135deg, var(--primary-darker) 0%, var(--primary) 100%);
  border-radius: 12px;
  margin: -2px -2px 2px -2px;
}
.totals-box .total-label { font-weight: 700; color: rgba(255,255,255,0.85); }
.totals-box .total-amount { font-weight: 800; font-size: 23px; color: #ffd9a8; }

/* ---------- Bottom tab bar ---------- */

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tab-height) + var(--safe-bottom));
  padding: 6px 8px var(--safe-bottom);
  background: white;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 4px;
  z-index: 30;
  box-shadow: 0 -2px 10px rgba(14, 124, 102, 0.06);
}

.tab-btn {
  flex: 1;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  border-radius: 12px;
  margin: 2px 0;
}

.tab-btn .tab-icon { font-size: 19px; }
.tab-btn.active {
  color: var(--primary-dark);
  background: var(--primary-light);
}

/* ---------- List rows (history, customers, products) ---------- */

.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--card-bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
  border-left: 3px solid var(--primary-light2);
}

.list-row .lr-main b { display: block; font-size: 14.5px; }
.list-row .lr-main span { font-size: 12.5px; color: var(--text-muted); }
.list-row .lr-right { text-align: right; }
.list-row .lr-right .lr-amount { font-weight: 800; color: var(--accent-dark); font-size: 14.5px; }
.list-row .lr-right .lr-date { font-size: 11.5px; color: var(--text-muted); }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 50;
  display: none;
  align-items: flex-end;
}
.modal-overlay.active { display: flex; }

.modal-sheet {
  background: white;
  width: 100%;
  max-height: 88vh;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }

.modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 16px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
}

/* ---------- Print / invoice preview ---------- */

.invoice-preview { font-size: 14px; }
.invoice-preview .ip-row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed #eee; }
.invoice-preview .ip-head { text-align: center; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 2px solid var(--primary-light2); }
.invoice-preview .ip-head .ip-company { font-weight: 800; font-size: 17px; color: var(--primary-dark); }
.invoice-preview table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 12px 0; }
.invoice-preview th { color: var(--primary-dark); text-transform: uppercase; font-size: 11px; letter-spacing: 0.3px; }
.invoice-preview th, .invoice-preview td { border-bottom: 1px solid #eee; padding: 6px 4px; text-align: left; }
.invoice-preview th:last-child, .invoice-preview td:last-child { text-align: right; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: calc(var(--tab-height) + var(--safe-bottom) + 14px);
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #1a1d23;
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  z-index: 60;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  max-width: 90%;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-error { background: var(--danger); }
.toast.toast-success { background: var(--success); }

/* ---------- Print mode ---------- */

@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area {
    display: block !important;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 20px;
  }
}

.header-icon-btn {
  color: white;
  font-size: 19px;
  background: rgba(255,255,255,0.12);
}
.header-icon-btn:active { background: rgba(255,255,255,0.22); }

/* ---------- Sticky search header for list screens ---------- */

.sticky-search-card {
  position: sticky;
  top: -1px;
  z-index: 10;
}

.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}

/* ---------- Segmented control ---------- */

.segmented {
  display: flex;
  border: 1.5px solid var(--border);
  border-radius: 11px;
  overflow: hidden;
}
.segmented-opt {
  flex: 1;
  background: #fbfbfc;
  padding: 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
}
.segmented-opt:last-child { border-right: none; }
.segmented-opt.active {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
}

/* ---------- List row delete action ---------- */

.list-row { position: relative; padding-right: 44px; }
.list-row .btn-delete-row {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  color: #c4c8cf;
}
.list-row .btn-delete-row:active { color: var(--danger); background: #fdecec; }
.list-row.tappable:active { background: #f7f8fa; }

/* ---------- Price input with reset button ---------- */

.price-input-row { display: flex; gap: 6px; align-items: center; }
.price-input-row input { flex: 1; }
.price-input-row .btn-reset-price {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 8px;
  font-size: 17px;
}

.modal-footer .btn.mt-0 { margin-bottom: 10px; }

/* ---------- Misc ---------- */

.muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 800;
  background: var(--primary);
  color: white;
  letter-spacing: 0.2px;
  vertical-align: middle;
}

.badge-warn { background: var(--coral); }

hr.sep { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

@media (min-width: 700px) {
  .app-main { max-width: 560px; margin: 0 auto; width: 100%; }
  .tab-bar { max-width: 560px; left: 50%; transform: translateX(-50%); }
}
