/* ========== Theme & Reset ========== */
:root {
  --c-primary: #FFCC00;
  --c-primary-soft: #FFF7D6;
  --c-primary-pale: #FFF0A6;
  --c-text: #222;
  --c-text-light: #888;
  --c-text-muted: #aaa;
  --c-bg: #f5f5f7;
  --c-card: #fff;
  --c-border: #e5e5e7;
  --c-ok: #34c759;
  --c-warn: #ff9500;
  --c-red: #ff3b30;
  --c-off: #c7c7cc;
  --r-radius: 12px;
  --r-radius-sm: 8px;
  --r-shadow: 0 1px 3px rgba(0,0,0,0.05);
  --r-shadow-hover: 0 4px 12px rgba(0,0,0,0.1);
  --p-page: 16px;
  --max-w: 760px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', Helvetica, Arial, sans-serif; color: var(--c-text); background: var(--c-bg); }
body { min-height: 100vh; font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
ul, ol { margin: 0; padding: 0; list-style: none; }

.boot-splash { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 80vh; gap: 12px; }
.boot-logo { font-size: 24px; font-weight: bold; }
.boot-tip { color: var(--c-text-light); font-size: 13px; }

/* ========== App Shell ========== */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.app-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--c-primary); color: #000;
  padding: 12px 16px; display: flex; align-items: center; gap: 8px;
  min-height: 44px; box-shadow: 0 1px 0 rgba(0,0,0,0.05);
}
.app-header .nav-back {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer; user-select: none;
}
.app-header .nav-back:active { background: rgba(0,0,0,0.08); }
.app-header .title { font-weight: 600; font-size: 16px; flex: 1; text-align: center; padding-right: 40px; }
.app-header .right-action { padding-right: 0; }
.app-header.no-back .title { padding-right: 0; padding-left: 0; }

.app-body { flex: 1; padding: 0; max-width: var(--max-w); width: 100%; margin: 0 auto; }
.container { padding: 16px; padding-bottom: 32px; }

/* ========== Cards / Lists ========== */
.card {
  background: var(--c-card); border-radius: var(--r-radius);
  padding: 16px; box-shadow: var(--r-shadow);
}
.card + .card { margin-top: 12px; }
.card.mt { margin-top: 12px; }

.row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; }
.row .label { color: var(--c-text-light); }
.row .value { color: var(--c-text); font-weight: 500; text-align: right; max-width: 60%; }
.row + .row { border-top: 1px solid var(--c-border); }

.muted { color: var(--c-text-light); font-size: 13px; line-height: 1.6; }
.small { font-size: 12px; color: var(--c-text-light); }
.strong { font-weight: 600; }
.mt { margin-top: 12px; }
.mt2 { margin-top: 8px; }
.mt-lg { margin-top: 20px; }
.center { text-align: center; }
.link { color: #0066cc; cursor: pointer; }
.text-red { color: var(--c-red); }
.text-warn { color: var(--c-warn); }
.text-ok { color: var(--c-ok); }

.meal-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.status-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* ========== Tag / Badge ========== */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 12px; font-weight: 500;
  background: var(--c-bg); color: var(--c-text-light);
}
.tag.ok { background: rgba(52,199,89,0.12); color: var(--c-ok); }
.tag.warn { background: rgba(255,149,0,0.12); color: var(--c-warn); }
.tag.red { background: rgba(255,59,48,0.12); color: var(--c-red); }
.tag.off { background: var(--c-bg); color: var(--c-text-muted); }

/* ========== Form / Button ========== */
.input, .picker-input {
  width: 100%; padding: 10px 12px; border-radius: var(--r-radius-sm);
  border: 1px solid var(--c-border); background: #fff; outline: none; font-size: 14px;
}
.input:focus { border-color: var(--c-primary); }
.textarea { width: 100%; padding: 10px 12px; border-radius: var(--r-radius-sm); border: 1px solid var(--c-border); background: #fff; outline: none; font-size: 14px; resize: vertical; min-height: 80px; font-family: inherit; }
.picker-input { display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.picker-input::after { content: '›'; color: var(--c-text-muted); font-size: 16px; transform: rotate(90deg); }

.btn {
  display: block; width: 100%; padding: 12px 16px;
  border-radius: var(--r-radius-sm); border: 0;
  background: var(--c-primary); color: #000;
  font-size: 15px; font-weight: 600; text-align: center;
  cursor: pointer; user-select: none;
  transition: filter 0.1s ease, transform 0.05s ease;
}
.btn:active { transform: scale(0.98); filter: brightness(0.95); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.gray { background: var(--c-bg); color: var(--c-text); border: 1px solid var(--c-border); }
.btn.red { background: var(--c-red); color: #fff; }
.btn.outline { background: transparent; color: var(--c-text); border: 1px solid var(--c-border); }
.btn.small { padding: 6px 12px; font-size: 13px; display: inline-block; width: auto; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.grid4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 8px; }

.field-row { display: flex; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--c-border); gap: 12px; }
.field-row:last-child { border-bottom: 0; }
.field-row .field-label { color: var(--c-text-light); width: 80px; flex-shrink: 0; font-size: 13px; }
.field-row .field-value { flex: 1; }
.field-row .field-value input,
.field-row .field-value select { width: 100%; padding: 6px 0; border: 0; outline: none; background: transparent; font-size: 14px; text-align: right; }

/* ========== Stars / Rating ========== */
.stars { display: inline-flex; align-items: center; gap: 4px; color: var(--c-warn); font-weight: 600; }
.star-input { display: inline-flex; gap: 4px; }
.star-input .star { font-size: 28px; color: var(--c-off); cursor: pointer; }
.star-input .star.on { color: var(--c-warn); }

/* ========== Large Icon ========== */
.large-icon { font-size: 60px; margin-bottom: 12px; }

/* ========== Metric ========== */
.metric-title { color: var(--c-text-light); font-size: 13px; }
.metric-value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.metric-sub { font-size: 12px; color: var(--c-text-light); margin-top: 2px; }

/* ========== Modal ========== */
.review-mask, .modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 100; display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.2s ease;
}
.review-dialog, .modal-dialog {
  background: #fff; width: 100%; max-width: var(--max-w);
  border-top-left-radius: 16px; border-top-right-radius: 16px;
  max-height: 80vh; display: flex; flex-direction: column; overflow: hidden;
  animation: slideUp 0.25s ease;
}
.review-header, .modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid var(--c-border);
}
.review-title, .modal-title { font-size: 16px; font-weight: 600; }
.review-subtitle { font-size: 13px; color: var(--c-text-light); margin-top: 2px; }
.review-close, .modal-close { font-size: 24px; color: var(--c-text-light); cursor: pointer; padding: 0 4px; }
.review-filter-row { display: flex; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--c-border); }
.review-filter { padding: 6px 12px; border: 1px solid var(--c-border); border-radius: 16px; font-size: 13px; background: #fff; cursor: pointer; }
.review-list { flex: 1; overflow-y: auto; padding: 8px 16px; }
.review-item { padding: 12px 0; border-bottom: 1px solid var(--c-border); }
.review-item:last-child { border-bottom: 0; }
.review-item-head { display: flex; justify-content: space-between; margin-bottom: 4px; }
.review-score { font-weight: 600; color: var(--c-warn); }
.review-time { font-size: 12px; color: var(--c-text-light); }
.review-comment { font-size: 14px; line-height: 1.5; }
.review-empty { padding: 40px 0; text-align: center; color: var(--c-text-light); }
.modal-body { padding: 16px; overflow-y: auto; flex: 1; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ========== Toast ========== */
.toast-container { position: fixed; top: 20%; left: 50%; transform: translateX(-50%); z-index: 200; pointer-events: none; }
.toast { background: rgba(0,0,0,0.75); color: #fff; padding: 12px 20px; border-radius: 8px; font-size: 14px; margin-bottom: 8px; animation: toastIn 0.2s ease; max-width: 80vw; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* ========== Loading ========== */
.loading { padding: 40px 0; text-align: center; color: var(--c-text-light); }
.loading::after { content: '...'; animation: dots 1.5s infinite steps(4); }
@keyframes dots { 0%{content:''} 25%{content:'.'} 50%{content:'..'} 75%{content:'...'} }

/* ========== Tabs ========== */
.tabs { display: flex; gap: 0; background: #fff; border-radius: var(--r-radius-sm); padding: 4px; box-shadow: var(--r-shadow); }
.tabs .tab { flex: 1; padding: 8px 12px; text-align: center; cursor: pointer; border-radius: 6px; font-size: 14px; color: var(--c-text-light); }
.tabs .tab.active { background: var(--c-primary); color: #000; font-weight: 600; }

/* ========== Empty State ========== */
.empty-state { padding: 60px 20px; text-align: center; color: var(--c-text-light); }
.empty-state .ico { font-size: 48px; margin-bottom: 16px; }

/* ========== Tables ========== */
.table-wrap { overflow-x: auto; margin-top: 12px; background: #fff; border-radius: var(--r-radius); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--c-border); white-space: nowrap; }
.data-table thead th { background: var(--c-bg); font-weight: 600; }
.data-table tbody tr:hover { background: var(--c-primary-soft); }

/* ========== Vendor order summary (groups) ========== */
.vendor-order-table { background: #fff; border-radius: var(--r-radius); overflow: hidden; }
.vendor-order-head, .vendor-meal-row, .vendor-meal-rows-head {
  display: grid; grid-template-columns: 100px 1.5fr 2fr 80px 60px 60px; gap: 8px;
  padding: 10px 12px; font-size: 13px;
}
.vendor-order-head { background: var(--c-bg); font-weight: 600; }
.vendor-date-group { border-top: 1px solid var(--c-border); }
.vendor-date-cell { padding: 10px 12px; background: var(--c-primary-soft); display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.vendor-date-text { font-weight: 600; }
.vendor-date-sub { color: var(--c-text-light); }
.vendor-meal-row { border-top: 1px solid var(--c-border); }
.vendor-meal-name { font-weight: 500; }
.vendor-meal-content { color: var(--c-text-light); font-size: 12px; }

/* ========== Settlement Detail Table ========== */
.settlement-detail-scroll { background: #fff; border-radius: var(--r-radius); overflow-x: auto; }
.settlement-detail-table { min-width: 800px; }
.settlement-detail-row { display: grid; grid-template-columns: 100px 1.2fr 1.5fr 2fr 80px 80px 80px 120px 120px; gap: 8px; padding: 10px 12px; font-size: 13px; border-bottom: 1px solid var(--c-border); }
.settlement-detail-row:last-child { border-bottom: 0; }
.settlement-detail-head { background: var(--c-bg); font-weight: 600; }

/* ========== Mobile (default <= 768px is mobile) ========== */
@media (max-width: 760px) {
  .vendor-order-head, .vendor-meal-row { grid-template-columns: 90px 1fr 1fr 60px 50px 50px; font-size: 12px; }
  .settlement-detail-row { font-size: 12px; }
  .review-dialog, .modal-dialog { max-height: 90vh; }
}

/* ========== Desktop ========== */
@media (min-width: 761px) {
  body { background: linear-gradient(135deg, #f5f5f7 0%, #ececef 100%); }
  .app-shell { max-width: var(--max-w); margin: 24px auto; min-height: calc(100vh - 48px); background: var(--c-card); border-radius: 16px; box-shadow: 0 8px 32px rgba(0,0,0,0.08); overflow: hidden; }
  .app-header { border-radius: 16px 16px 0 0; }
  .review-mask, .modal-mask { align-items: center; }
  .review-dialog, .modal-dialog { border-radius: 16px; max-width: 520px; }
}

/* ========== QR Image ========== */
.qrcode-image { width: 240px; height: 240px; max-width: 80vw; margin: 0 auto; display: block; image-rendering: pixelated; }
.qrcode-placeholder { font-size: 120px; line-height: 240px; color: var(--c-text-muted); text-align: center; }

/* ========== Section Title ========== */
.section-title { font-size: 14px; font-weight: 600; color: var(--c-text-light); margin: 16px 4px 8px; }

/* ========== Employee Permission Badge ========== */
.perm-chip { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; background: var(--c-primary-soft); color: var(--c-text); margin-right: 4px; }

/* ========== QR Scanner ========== */
#qr-scanner { width: 100%; max-width: 360px; margin: 0 auto; }
#qr-scanner video { width: 100% !important; height: auto !important; border-radius: 8px; }

/* ========== Login Page ========== */
.login-hero { text-align: center; padding: 32px 16px 24px; }
.login-hero .logo { width: 80px; height: 80px; background: var(--c-primary); border-radius: 16px; display: inline-flex; align-items: center; justify-content: center; font-size: 36px; font-weight: bold; margin-bottom: 16px; }
.login-hero h2 { margin: 8px 0 4px; font-size: 22px; }
.login-hero p { color: var(--c-text-light); margin: 0; }
.login-form { padding: 0 16px; }
.login-form .input + .input { margin-top: 12px; }
.login-form .btn { margin-top: 20px; }

/* ========== Role Select Page ========== */
.role-grid { display: grid; gap: 16px; padding: 24px 16px; }
.role-card { background: #fff; border-radius: var(--r-radius); padding: 24px; box-shadow: var(--r-shadow); cursor: pointer; transition: transform 0.1s ease, box-shadow 0.2s ease; }
.role-card:hover { box-shadow: var(--r-shadow-hover); }
.role-card:active { transform: scale(0.99); }
.role-card .ico { font-size: 36px; margin-bottom: 8px; }
.role-card .role-title { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.role-card .role-desc { color: var(--c-text-light); font-size: 13px; }
