:root {
  --primary: #1a4d3a;
  --primary-light: #2d6b52;
  --primary-dark: #0f2e21;
  --accent: #e8a020;
  --accent-light: #f5c842;
  --danger: #e53e3e;
  --warning: #dd6b20;
  --success: #2f855a;
  --info: #2b6cb0;
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1a202c;
  --text-sub: #718096;
  --border: #e2e8f0;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', sans-serif; background: var(--bg); color: var(--text); font-size: 15px; }

/* ── Layout ── */
#app { display: flex; flex-direction: column; height: 100%; }
.view { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.view.active { display: flex; }
.scroll-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 14px 80px; }

/* ── Top bar ── */
.topbar { background: var(--primary); color: #fff; padding: 48px 16px 14px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 100; }
.topbar h1 { font-size: 17px; font-weight: 600; }
.topbar .sub { font-size: 12px; opacity: .75; }
.topbar-right { display: flex; gap: 10px; align-items: center; }
.topbar .icon-btn { background: none; border: none; color: #fff; font-size: 20px; cursor: pointer; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 8px; }
.topbar .icon-btn:active { background: rgba(255,255,255,.15); }

/* ── Bottom nav ── */
.bottom-nav { background: #fff; border-top: 1px solid var(--border); display: flex; padding: 6px 0 env(safe-area-inset-bottom,6px); position: sticky; bottom: 0; z-index: 100; }
.nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; cursor: pointer; border: none; background: none; color: var(--text-sub); font-size: 10px; transition: color .15s; }
.nav-item .icon { font-size: 22px; line-height: 1; }
.nav-item.active { color: var(--primary); }
.nav-item .badge { position: relative; }
.nav-item .badge::after { content: attr(data-badge); position: absolute; top: -4px; right: -10px; background: var(--danger); color: #fff; font-size: 9px; padding: 1px 4px; border-radius: 10px; line-height: 1.4; display: none; }
.nav-item .badge[data-badge]:not([data-badge=""])::after { display: block; }

/* ── Cards ── */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 12px; overflow: hidden; }
.card-header { padding: 14px 16px 10px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 14px; font-weight: 600; color: var(--text); }
.card-body { padding: 14px 16px; }
.card-link { font-size: 13px; color: var(--primary); cursor: pointer; }

/* ── Stats row ── */
.stats-row { display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; margin-bottom: 12px; }
.stats-row.col3 { grid-template-columns: repeat(3,1fr); }
.stat-card { background: var(--card); border-radius: var(--radius-sm); padding: 14px 12px; box-shadow: var(--shadow); text-align: center; }
.stat-card .val { font-size: 22px; font-weight: 700; color: var(--primary); line-height: 1.2; }
.stat-card .val.accent { color: var(--accent); }
.stat-card .val.danger { color: var(--danger); }
.stat-card .val.success { color: var(--success); }
.stat-card .lbl { font-size: 11px; color: var(--text-sub); margin-top: 4px; }
.stat-card .trend { font-size: 11px; margin-top: 2px; }
.trend.up { color: var(--success); }
.trend.dn { color: var(--danger); }

/* ── Order list items ── */
.order-item { padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .1s; }
.order-item:last-child { border-bottom: none; }
.order-item:active { background: #f7faf9; }
.order-item .row1 { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.order-item .title { font-size: 14px; font-weight: 600; flex: 1; line-height: 1.3; }
.order-item .row2 { display: flex; gap: 6px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.order-item .store-tag { font-size: 11px; background: #e8f5f0; color: var(--primary); padding: 1px 7px; border-radius: 20px; }
.order-item .time-tag { font-size: 11px; color: var(--text-sub); }
.order-item .amount-tag { font-size: 11px; font-weight: 600; color: var(--accent); }

/* ── Badges / Tags ── */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-urgent  { background: #fff5f5; color: #c53030; }
.badge-high    { background: #fffaf0; color: #c05621; }
.badge-normal  { background: #f0f4ff; color: #2b4ac8; }
.badge-low     { background: #f0fdf4; color: #276749; }
.badge-new           { background: #ebf8ff; color: #2c5282; }
.badge-parsing       { background: #faf5ff; color: #553c9a; }
.badge-clarify       { background: #fffaf0; color: #7b341e; }
.badge-dispatched    { background: #e9f5ff; color: #1a56a4; }
.badge-in_progress   { background: #e6fffa; color: #1d4044; }
.badge-pending_approval { background: #fffde7; color: #7b5e00; }
.badge-approved      { background: #f0fff4; color: #22543d; }
.badge-rejected      { background: #fff5f5; color: #742a2a; }
.badge-pending_verify { background: #faf5ff; color: #44337a; }
.badge-closed        { background: #f7fafc; color: #718096; }
.badge-R5 { background: #fff5f5; color: #c53030; }
.badge-R4 { background: #fffaf0; color: #c05621; }
.badge-R3 { background: #fffff0; color: #7b6000; }
.badge-R2 { background: #f0fff4; color: #276749; }
.badge-R1 { background: #f7fafc; color: #718096; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 18px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; border: none; cursor: pointer; transition: all .15s; }
.btn:active { opacity: .85; transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-accent  { background: var(--accent); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-ghost   { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--border); }
.btn-row .btn { flex: 1; }

/* ── FAB ── */
.fab { position: fixed; bottom: 76px; right: 18px; width: 52px; height: 52px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 26px; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 16px rgba(26,77,58,.4); cursor: pointer; border: none; z-index: 200; transition: transform .15s; }
.fab:active { transform: scale(.92); }

/* ── Forms ── */
.form-group { margin-bottom: 14px; }
.form-label { font-size: 13px; color: var(--text-sub); margin-bottom: 5px; display: block; }
.form-label .req { color: var(--danger); }
.form-control { width: 100%; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; background: #fff; color: var(--text); transition: border .15s; outline: none; }
.form-control:focus { border-color: var(--primary); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23718096' d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

/* ── Modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 500; display: flex; align-items: flex-end; opacity: 0; pointer-events: none; transition: opacity .2s; }
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal-sheet { background: #fff; border-radius: 20px 20px 0 0; width: 100%; max-height: 90vh; display: flex; flex-direction: column; transform: translateY(100%); transition: transform .25s cubic-bezier(.4,0,.2,1); }
.modal-overlay.open .modal-sheet { transform: translateY(0); }
.modal-handle { width: 40px; height: 4px; background: var(--border); border-radius: 2px; margin: 10px auto 4px; flex-shrink: 0; }
.modal-header { padding: 8px 16px 12px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 22px; color: var(--text-sub); cursor: pointer; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; }
.modal-body { flex: 1; overflow-y: auto; padding: 16px; }

/* ── Login screen ── */
.login-screen { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; background: linear-gradient(160deg, var(--primary-dark) 0%, var(--primary) 60%, var(--primary-light) 100%); padding: 30px 24px; }
.login-logo { font-size: 48px; margin-bottom: 10px; }
.login-title { color: #fff; font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.login-sub { color: rgba(255,255,255,.7); font-size: 14px; margin-bottom: 36px; }
.login-card { background: #fff; border-radius: 20px; padding: 24px; width: 100%; max-width: 360px; box-shadow: 0 8px 40px rgba(0,0,0,.25); }
.login-card h2 { font-size: 16px; font-weight: 700; margin-bottom: 16px; color: var(--text); }
.user-pick-item { display: flex; align-items: center; padding: 11px 12px; border-radius: 10px; cursor: pointer; transition: background .1s; border: 1.5px solid transparent; margin-bottom: 8px; }
.user-pick-item:hover, .user-pick-item:active { background: #f0fff4; border-color: var(--primary); }
.user-pick-item .avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 700; margin-right: 12px; flex-shrink: 0; }
.user-pick-item .info .name { font-size: 14px; font-weight: 600; }
.user-pick-item .info .meta { font-size: 12px; color: var(--text-sub); margin-top: 1px; }
.role-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.role-tab { flex: 1; padding: 6px; text-align: center; border-radius: 8px; font-size: 12px; font-weight: 600; cursor: pointer; border: 1.5px solid var(--border); color: var(--text-sub); background: #fff; transition: all .15s; }
.role-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Timeline / activities ── */
.timeline { padding: 8px 0; }
.timeline-item { display: flex; gap: 12px; padding: 0 0 16px; }
.timeline-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); flex-shrink: 0; margin-top: 4px; position: relative; }
.timeline-dot::after { content:''; position: absolute; left: 4px; top: 10px; width: 2px; height: calc(100% + 6px); background: var(--border); }
.timeline-item:last-child .timeline-dot::after { display: none; }
.timeline-content .action { font-size: 13px; font-weight: 600; }
.timeline-content .detail { font-size: 12px; color: var(--text-sub); margin-top: 2px; }
.timeline-content .t { font-size: 11px; color: var(--text-sub); margin-top: 2px; }

/* ── Section heading ── */
.section-title { font-size: 13px; font-weight: 700; color: var(--text-sub); text-transform: uppercase; letter-spacing: .05em; margin: 16px 0 8px; }

/* ── Health score ring ── */
.score-ring { display: flex; align-items: center; gap: 14px; }
.ring-wrap { position: relative; width: 64px; height: 64px; flex-shrink: 0; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-val { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 700; }

/* ── Chat / parse area ── */
.parse-input-area { padding: 12px 14px; background: #fff; border-bottom: 1px solid var(--border); }
.parse-hint { font-size: 12px; color: var(--text-sub); margin-bottom: 8px; }
.parse-result-item { padding: 12px 14px; background: var(--card); border-radius: var(--radius-sm); margin-bottom: 10px; border-left: 4px solid var(--primary); box-shadow: var(--shadow); }
.parse-result-item.urgent { border-color: var(--danger); }
.parse-result-item.high   { border-color: var(--warning); }
.parse-result-item .pr-title { font-size: 14px; font-weight: 700; }
.parse-result-item .pr-meta  { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0; }
.parse-result-item .pr-ai    { font-size: 12px; color: var(--text-sub); line-height: 1.5; }
.parse-result-item .pr-suggestion { font-size: 12px; color: var(--primary); font-weight: 600; margin-top: 5px; }
.parse-result-item .pr-missing { font-size: 12px; color: var(--warning); margin-top: 4px; }
.parse-actions { display: flex; gap: 8px; margin-top: 8px; }

/* ── Admin PC layout ── */
.admin-layout { display: flex; height: 100%; }
.admin-sidebar { width: 200px; background: var(--primary-dark); color: #fff; flex-shrink: 0; display: flex; flex-direction: column; }
.admin-sidebar .logo { padding: 20px 16px; font-size: 16px; font-weight: 700; border-bottom: 1px solid rgba(255,255,255,.1); }
.admin-nav-item { display: flex; align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer; font-size: 14px; color: rgba(255,255,255,.7); transition: all .15s; }
.admin-nav-item:hover, .admin-nav-item.active { background: var(--primary); color: #fff; }
.admin-main { flex: 1; overflow-y: auto; background: var(--bg); }
.admin-topbar { background: #fff; border-bottom: 1px solid var(--border); padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; }
.admin-content { padding: 24px; }
.admin-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.admin-table th { background: #f7fafc; font-size: 12px; font-weight: 700; color: var(--text-sub); text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.admin-table td { padding: 11px 14px; font-size: 13px; border-bottom: 1px solid var(--border); }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: #f7faf9; }

/* ── Report card ── */
.report-block { margin-bottom: 14px; }
.report-block h3 { font-size: 13px; font-weight: 700; color: var(--text-sub); margin-bottom: 8px; }
.report-list li { font-size: 13px; padding: 5px 0; border-bottom: 1px solid var(--border); display: flex; gap: 8px; align-items: flex-start; }
.report-list li::before { content: '·'; color: var(--primary); font-size: 18px; line-height: 1; flex-shrink: 0; }
.report-list li:last-child { border-bottom: none; }

/* ── Store cards ── */
.store-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.store-card-mini { background: var(--card); border-radius: var(--radius-sm); padding: 12px; box-shadow: var(--shadow); cursor: pointer; transition: box-shadow .15s; }
.store-card-mini:active { box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.store-card-mini .scm-name { font-size: 14px; font-weight: 700; }
.store-card-mini .scm-manager { font-size: 12px; color: var(--text-sub); margin-top: 2px; }
.store-card-mini .scm-score { font-size: 24px; font-weight: 700; color: var(--primary); margin-top: 8px; }
.store-card-mini .scm-orders { font-size: 11px; color: var(--text-sub); margin-top: 2px; }

/* ── Decision card ── */
.decision-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; overflow: hidden; }
.decision-card .dc-head { padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; }
.decision-card .dc-amount { font-size: 20px; font-weight: 800; color: var(--accent); flex-shrink: 0; }
.decision-card .dc-title { font-size: 14px; font-weight: 600; }
.decision-card .dc-meta { font-size: 12px; color: var(--text-sub); margin-top: 3px; }
.decision-card .dc-ai { font-size: 12px; color: var(--text-sub); background: #f7faf9; padding: 8px 14px; line-height: 1.6; }

/* ── Misc ── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-sub); }
.empty-state .icon { font-size: 48px; margin-bottom: 10px; }
.empty-state p { font-size: 14px; }
.loading { display: flex; align-items: center; justify-content: center; padding: 30px; color: var(--text-sub); gap: 8px; }
.spinner { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.divider { height: 1px; background: var(--border); margin: 10px 0; }
.chip { display: inline-block; padding: 3px 10px; background: #e8f5f0; color: var(--primary); border-radius: 20px; font-size: 12px; font-weight: 600; }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-accent  { color: var(--accent); }
.text-sub     { color: var(--text-sub); }
.fw-bold      { font-weight: 700; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mb-12 { margin-bottom: 12px; }

/* ── Approval actions ── */
.approval-action-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border); }
.approval-action-bar .btn-ghost-sm { padding: 8px; font-size: 12px; border-radius: 8px; font-weight: 600; border: 1.5px solid; cursor: pointer; text-align: center; }
.approval-action-bar .approve { background: #f0fff4; color: var(--success); border-color: var(--success); }
.approval-action-bar .reject  { background: #fff5f5; color: var(--danger); border-color: var(--danger); }
.approval-action-bar .cond    { background: #fffaf0; color: var(--warning); border-color: var(--warning); }
.approval-action-bar .more    { background: #f7fafc; color: var(--info); border-color: var(--info); }

/* ── Notification toast ── */
#toast { position: fixed; top: 60px; left: 50%; transform: translateX(-50%) translateY(-20px); background: rgba(30,30,30,.9); color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 13px; z-index: 9999; opacity: 0; transition: all .25s; pointer-events: none; white-space: nowrap; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Responsive (admin PC) ── */
@media (max-width: 600px) {
  .admin-sidebar { width: 56px; }
  .admin-sidebar .logo, .admin-nav-item span { display: none; }
  .admin-nav-item { justify-content: center; padding: 14px; }
  .admin-content { padding: 14px; }
  .store-grid { grid-template-columns: 1fr; }
}
