/* ==========================================================================
   TuongMinh Payment Approval — Shared Design System (Phase 3 mockups)
   Trustworthy / Efficient / Calm-under-authority / Vietnamese-first
   ========================================================================== */

:root {
  /* ---- Color: brand & neutrals ---- */
  --color-primary: #1E4FD6;
  --color-primary-dark: #16389E;
  --color-primary-light: #E8EEFC;
  --color-ink: #101828;
  --color-text: #1D2939;
  --color-text-secondary: #475467;
  --color-text-muted: #667085;
  --color-border: #E4E7EC;
  --color-border-strong: #D0D5DD;
  --color-background: #F5F7FB;
  --color-surface: #FFFFFF;
  --color-surface-sunken: #F9FAFB;

  /* ---- Color: status (single source of truth for lifecycle states) ---- */
  --status-draft-bg: #F2F4F7;    --status-draft-fg: #475467;    --status-draft-dot:#98A2B3;
  --status-pending-bg:#FEF3C7;   --status-pending-fg:#8A5A00;   --status-pending-dot:#D69E2E;
  --status-approved-bg:#E0F2FE;  --status-approved-fg:#075985;  --status-approved-dot:#0EA5E9;
  --status-unpaid-bg:#EDE9FE;    --status-unpaid-fg:#5B21B6;    --status-unpaid-dot:#8B5CF6;
  --status-inbatch-bg:#CFFAFE;   --status-inbatch-fg:#0E7490;   --status-inbatch-dot:#06B6D4;
  --status-paid-bg:#DCFCE7;      --status-paid-fg:#166534;      --status-paid-dot:#22C55E;
  --status-rejected-bg:#FEE2E2;  --status-rejected-fg:#991B1B;  --status-rejected-dot:#EF4444;

  /* ---- Semantic ---- */
  --color-success: #16A34A;
  --color-warning: #B45309;
  --color-danger: #DC2626;
  --color-info: #0EA5E9;

  /* ---- Spacing (8px unit) ---- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  /* ---- Radius ---- */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  /* ---- Type scale ---- */
  --font-family: 'Be Vietnam Pro', 'Inter', -apple-system, Segoe UI, Roboto, sans-serif;
  --text-h1: 28px;
  --text-h2: 22px;
  --text-h3: 18px;
  --text-body: 15px;
  --text-base: 14px;
  --text-small: 13px;
  --text-label: 12px;

  /* ---- Shadows ---- */
  --shadow-soft: 0 1px 2px rgba(16,24,40,0.06);
  --shadow-card: 0 1px 3px rgba(16,24,40,0.10), 0 1px 2px rgba(16,24,40,0.06);
  --shadow-modal: 0 20px 24px -4px rgba(16,24,40,0.12), 0 8px 8px -4px rgba(16,24,40,0.06);

  /* ---- Layout ---- */
  --sidebar-width: 248px;
  --topbar-height: 60px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-family);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-background);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
table { border-collapse: collapse; width: 100%; }
img { max-width: 100%; display: block; }

::selection { background: var(--color-primary-light); }

/* ---- Focus states (WCAG 2.1 AA keyboard visibility) ---- */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ==========================================================================
   App shell: sidebar + topbar + content
   ========================================================================== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-ink);
  color: #CBD5E1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-4);
  color: #fff;
  font-weight: 700;
  font-size: var(--text-body);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand .mark {
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  background: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #fff;
}
.sidebar-company {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: var(--text-small);
}
.sidebar-company .label { color: #8A94A6; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.sidebar-company .name { color: #fff; font-weight: 600; margin-top: 2px; display: flex; align-items: center; justify-content: space-between; }

.nav-group { padding: var(--space-3) var(--space-2); overflow-y: auto; flex: 1; }
.nav-group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: #6B7688; padding: var(--space-3) var(--space-3) var(--space-1);
}
.nav-item {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-small);
  color: #CBD5E1;
  margin-bottom: 2px;
}
.nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: var(--color-primary); color: #fff; font-weight: 600; }
.nav-item .count {
  margin-left: auto; background: rgba(255,255,255,0.12);
  padding: 1px 7px; border-radius: var(--radius-pill); font-size: 11px;
}
.nav-item.active .count { background: rgba(255,255,255,0.25); }

.sidebar-user {
  padding: var(--space-4); border-top: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-small);
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--color-primary-light);
  color: var(--color-primary-dark); display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; flex-shrink: 0;
}
.sidebar-user .who { min-width: 0; }
.sidebar-user .who .n { color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .who .r { color: #8A94A6; font-size: 11px; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--space-5);
  position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-size: var(--text-h3); font-weight: 700; color: var(--color-ink); }
.topbar-actions { display: flex; align-items: center; gap: var(--space-3); }
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--radius-sm); border: 1px solid var(--color-border);
  background: var(--color-surface); display: flex; align-items: center; justify-content: center;
  position: relative; color: var(--color-text-secondary);
}
.icon-btn:hover { background: var(--color-surface-sunken); }
.icon-btn .dot {
  position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--color-danger); border: 1.5px solid var(--color-surface);
}

.content { padding: var(--space-5); flex: 1; }
.content.narrow { max-width: 880px; margin: 0 auto; width: 100%; }

.breadcrumbs { font-size: var(--text-small); color: var(--color-text-muted); margin-bottom: var(--space-2); }
.breadcrumbs a { color: var(--color-text-muted); }
.breadcrumbs a:hover { color: var(--color-primary); }
.breadcrumbs .sep { margin: 0 var(--space-1); }
.breadcrumbs .current { color: var(--color-text); font-weight: 600; }

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: var(--space-5); gap: var(--space-4); flex-wrap: wrap;
}
.page-header h1 { font-size: var(--text-h1); font-weight: 700; color: var(--color-ink); letter-spacing: -0.01em; }
.page-header .sub { color: var(--color-text-secondary); font-size: var(--text-body); margin-top: 4px; }
.page-actions { display: flex; gap: var(--space-2); flex-shrink: 0; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: 38px; padding: 0 var(--space-4);
  border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: var(--text-small); font-weight: 600;
  white-space: nowrap;
}
.btn-sm { height: 32px; padding: 0 var(--space-3); font-size: 12px; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border-strong); }
.btn-secondary:hover { background: var(--color-surface-sunken); }
.btn-ghost { background: transparent; color: var(--color-text-secondary); }
.btn-ghost:hover { background: var(--color-surface-sunken); }
.btn-danger { background: #fff; color: var(--color-danger); border-color: #FCA5A5; }
.btn-danger:hover { background: #FEF2F2; }
.btn-danger-solid { background: var(--color-danger); color: #fff; }
.btn-success { background: var(--color-success); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-icon { width: 18px; height: 18px; }

/* ==========================================================================
   Cards / stat cards
   ========================================================================== */
.card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-soft);
}
.card-pad { padding: var(--space-5); }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--color-border);
}
.card-header h3 { font-size: var(--text-h3); font-weight: 700; }
.card-header .hint { font-size: var(--text-small); color: var(--color-text-muted); }

.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--space-4); margin-bottom: var(--space-5); }
.stat-card {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md);
  padding: var(--space-4); box-shadow: var(--shadow-soft);
}
.stat-card .label { font-size: var(--text-label); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.stat-card .value { font-size: 28px; font-weight: 800; color: var(--color-ink); margin-top: var(--space-2); letter-spacing: -0.02em; }
.stat-card .delta { font-size: var(--text-label); margin-top: var(--space-2); color: var(--color-text-muted); }
.stat-card.accent-pending { border-top: 3px solid var(--status-pending-dot); }
.stat-card.accent-approved { border-top: 3px solid var(--status-approved-dot); }
.stat-card.accent-unpaid { border-top: 3px solid var(--status-unpaid-dot); }
.stat-card.accent-inbatch { border-top: 3px solid var(--status-inbatch-dot); }
.stat-card.accent-paid { border-top: 3px solid var(--status-paid-dot); }

/* ==========================================================================
   Status badges — single authoritative label per REQ, never color-only
   ========================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 8px; border-radius: var(--radius-pill);
  font-size: var(--text-label); font-weight: 700; white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; }
.badge-draft { background: var(--status-draft-bg); color: var(--status-draft-fg); }
.badge-draft .dot { background: var(--status-draft-dot); }
.badge-pending { background: var(--status-pending-bg); color: var(--status-pending-fg); }
.badge-pending .dot { background: var(--status-pending-dot); }
.badge-approved { background: var(--status-approved-bg); color: var(--status-approved-fg); }
.badge-approved .dot { background: var(--status-approved-dot); }
.badge-unpaid { background: var(--status-unpaid-bg); color: var(--status-unpaid-fg); }
.badge-unpaid .dot { background: var(--status-unpaid-dot); }
.badge-inbatch { background: var(--status-inbatch-bg); color: var(--status-inbatch-fg); }
.badge-inbatch .dot { background: var(--status-inbatch-dot); }
.badge-paid { background: var(--status-paid-bg); color: var(--status-paid-fg); }
.badge-paid .dot { background: var(--status-paid-dot); }
.badge-rejected { background: var(--status-rejected-bg); color: var(--status-rejected-fg); }
.badge-rejected .dot { background: var(--status-rejected-dot); }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 700;
}
.chip-match { background: #DCFCE7; color: #166534; }
.chip-review { background: #FEF3C7; color: #8A5A00; }
.chip-nomatch { background: #FEE2E2; color: #991B1B; }

/* ==========================================================================
   Tables — dense & scannable (accountant screens)
   ========================================================================== */
.table-wrap { overflow-x: auto; }
.table { width: 100%; font-size: var(--text-small); }
.table thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--color-text-muted); font-weight: 700;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-sunken);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  position: sticky; top: 0;
}
.table thead th.num, .table td.num { text-align: right; }
.table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  vertical-align: middle;
}
.table tbody tr:hover { background: var(--color-surface-sunken); }
.table tbody tr:last-child td { border-bottom: none; }
.table .muted { color: var(--color-text-muted); }
.table .mono { font-variant-numeric: tabular-nums; }
.table .id-link { color: var(--color-primary); font-weight: 700; }
.table .row-checkbox { width: 36px; }

.table-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-3) var(--space-4); gap: var(--space-3); flex-wrap: wrap;
  border-bottom: 1px solid var(--color-border);
}
.table-toolbar .left, .table-toolbar .right { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

.table-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-3) var(--space-4); font-size: var(--text-small); color: var(--color-text-muted);
}
.pagination { display: flex; gap: 4px; align-items: center; }
.pagination button {
  min-width: 30px; height: 30px; border-radius: var(--radius-sm); border: 1px solid var(--color-border);
  background: var(--color-surface); font-size: 12px; color: var(--color-text-secondary);
}
.pagination button.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ==========================================================================
   Forms
   ========================================================================== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4) var(--space-5); }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: var(--text-small); font-weight: 600; color: var(--color-text); }
.form-field .req { color: var(--color-danger); margin-left: 2px; }
.form-field .help { font-size: var(--text-label); color: var(--color-text-muted); }
input[type="text"], input[type="number"], input[type="date"], input[type="email"],
input[type="password"], input[type="search"], select, textarea {
  height: 40px; padding: 0 var(--space-3); border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-strong); background: var(--color-surface);
  font-size: var(--text-base); color: var(--color-text); font-family: inherit;
}
textarea { height: auto; padding: var(--space-3); min-height: 84px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #98A2B3; }
input:focus, select:focus, textarea:focus { border-color: var(--color-primary); }
.input-affix { position: relative; display: flex; align-items: center; }
.input-affix .affix { position: absolute; right: var(--space-3); color: var(--color-text-muted); font-size: var(--text-small); }
.input-affix input { padding-right: 34px; width: 100%; }
.select-search { display: flex; align-items: center; gap: var(--space-2); border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); height: 40px; padding: 0 var(--space-3); color: var(--color-text-muted); font-size: var(--text-base); }

.form-section { margin-bottom: var(--space-6); }
.form-section-title { font-size: var(--text-h3); font-weight: 700; margin-bottom: var(--space-1); }
.form-section-desc { font-size: var(--text-small); color: var(--color-text-muted); margin-bottom: var(--space-4); }

.upload-dropzone {
  border: 1.5px dashed var(--color-border-strong); border-radius: var(--radius-md);
  padding: var(--space-6); text-align: center; color: var(--color-text-muted); font-size: var(--text-small);
  background: var(--color-surface-sunken);
}
.upload-dropzone strong { color: var(--color-primary); font-weight: 700; }

.file-row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3); border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  margin-top: var(--space-2); font-size: var(--text-small);
}
.file-row .file-icon { width: 32px; height: 32px; border-radius: var(--radius-sm); background: var(--color-primary-light); color: var(--color-primary-dark); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 10px; flex-shrink: 0; }
.file-row .name { flex: 1; font-weight: 600; }
.file-row .size { color: var(--color-text-muted); }

/* ==========================================================================
   Tabs
   ========================================================================== */
.tabs { display: flex; gap: var(--space-5); border-bottom: 1px solid var(--color-border); margin-bottom: var(--space-5); }
.tab {
  padding: var(--space-3) 2px; font-size: var(--text-small); font-weight: 600;
  color: var(--color-text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

.filter-pills { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.pill {
  padding: 6px 14px; border-radius: var(--radius-pill); border: 1px solid var(--color-border);
  font-size: var(--text-small); font-weight: 600; color: var(--color-text-secondary); background: var(--color-surface);
}
.pill.active { background: var(--color-ink); color: #fff; border-color: var(--color-ink); }

/* ==========================================================================
   Timeline / audit trail
   ========================================================================== */
.timeline { position: relative; padding-left: var(--space-6); }
.timeline::before {
  content: ""; position: absolute; left: 11px; top: 4px; bottom: 4px; width: 2px; background: var(--color-border);
}
.timeline-item { position: relative; padding-bottom: var(--space-5); }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before {
  content: ""; position: absolute; left: -37px; top: 2px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--color-surface); border: 2.5px solid var(--color-primary);
}
.timeline-item.rejected::before { border-color: var(--color-danger); }
.timeline-item.paid::before { border-color: var(--color-success); }
.timeline-item .t-head { display: flex; align-items: baseline; gap: var(--space-2); font-size: var(--text-small); }
.timeline-item .t-actor { font-weight: 700; color: var(--color-ink); }
.timeline-item .t-time { color: var(--color-text-muted); font-size: var(--text-label); margin-left: auto; }
.timeline-item .t-note { margin-top: 4px; font-size: var(--text-small); color: var(--color-text-secondary); }
.timeline-item .t-note.quote { background: var(--color-surface-sunken); border-left: 3px solid var(--color-border-strong); padding: var(--space-2) var(--space-3); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin-top: 6px; }

/* ==========================================================================
   Misc utility
   ========================================================================== */
.text-muted { color: var(--color-text-muted); }
.text-secondary { color: var(--color-text-secondary); }
.mono-amount { font-variant-numeric: tabular-nums; font-weight: 700; }
.divider { height: 1px; background: var(--color-border); margin: var(--space-5) 0; }
.empty-state { text-align: center; padding: var(--space-7) var(--space-4); color: var(--color-text-muted); }
.empty-state .icon { font-size: 32px; margin-bottom: var(--space-3); }
.empty-state h4 { color: var(--color-text); font-size: var(--text-body); margin-bottom: var(--space-1); }
.progress-bar { height: 6px; border-radius: var(--radius-pill); background: var(--color-border); overflow: hidden; }
.progress-bar .fill { height: 100%; background: var(--color-primary); }
.kbd { font-size: 11px; border: 1px solid var(--color-border-strong); border-radius: 4px; padding: 1px 5px; color: var(--color-text-muted); background: var(--color-surface-sunken); }
.checkbox { width: 16px; height: 16px; accent-color: var(--color-primary); }
.two-col { display: grid; grid-template-columns: 1.6fr 1fr; gap: var(--space-5); align-items: start; }
.summary-row { display: flex; justify-content: space-between; padding: var(--space-2) 0; font-size: var(--text-small); }
.summary-row.total { border-top: 1px solid var(--color-border); margin-top: var(--space-2); padding-top: var(--space-3); font-size: var(--text-body); font-weight: 700; }
.banner {
  display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-4);
  border-radius: var(--radius-md); font-size: var(--text-small); margin-bottom: var(--space-5);
}
.banner-info { background: #EFF6FF; color: #1E3A8A; border: 1px solid #BFDBFE; }
.banner-warning { background: #FFFBEB; color: #78350F; border: 1px solid #FDE68A; }

@media (max-width: 1024px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { position: fixed; left: -100%; z-index: 50; }
  .stat-grid { grid-template-columns: 1fr; }
}
