/* ============================================================================
   Asia Techbiz — Purchasing & Supplier Payment Management System
   Design system: ledger-inspired, calm, data-first.
   ============================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* Color */
  --ink:        #16233A;
  --ink-soft:   #4B5A72;
  --bg:         #F3F5F8;
  --surface:    #FFFFFF;
  --border:     #E1E5EB;
  --border-soft:#EDF0F4;
  --brand:      #24466B;
  --brand-dark: #16304C;
  --brand-soft: #E9EFF5;
  --amber:      #B8752B;
  --amber-soft: #FBF1E4;
  --green:      #2E7D5B;
  --green-soft: #E7F4EE;
  --red:        #B3261E;
  --red-soft:   #FBEAE9;
  --slate:      #6B7688;

  /* Type */
  --font-display: 'Space Grotesk', 'Inter', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Layout */
  --sidebar-w: 232px;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow-card: 0 1px 2px rgba(22,35,58,0.05);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0; color: var(--ink); }
p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------------------
   App shell
--------------------------------------------------------------------------- */
#app { display: none; min-height: 100vh; }
#app.ready { display: flex; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--brand-dark);
  color: #DCE6F0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
}
.sidebar-brand {
  padding: 22px 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand .mark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  color: #fff;
  letter-spacing: 0.2px;
}
.sidebar-brand .sub {
  font-size: 11.5px;
  color: #9CB1C7;
}
.sidebar-nav { flex: 1; padding: 14px 10px; overflow-y: auto; }
.sidebar-nav .nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: #C4D3E3;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 2px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.sidebar-nav .nav-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }
.sidebar-nav .nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav .nav-item.active { background: #fff; color: var(--brand-dark); }
.sidebar-nav .nav-item.active svg { opacity: 1; }
.sidebar-foot {
  padding: 14px 18px 18px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 12.5px;
  color: #9CB1C7;
}
.sidebar-foot .who { color: #E4ECF4; font-weight: 600; display: block; margin-bottom: 6px; font-size: 13px;}
.sidebar-foot button {
  background: none; border: 1px solid rgba(255,255,255,0.18); color: #DCE6F0;
  padding: 6px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: 12.5px;
}
.sidebar-foot button:hover { background: rgba(255,255,255,0.08); }

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  height: 60px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { font-size: 18px; }
.topbar .crumb { font-size: 12.5px; color: var(--slate); margin-top: 1px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.menu-toggle { display: none; background: none; border: none; cursor: pointer; padding: 6px; color: var(--ink); }

.content { padding: 22px 24px 60px; max-width: 1280px; width: 100%; }

/* ---------------------------------------------------------------------------
   Buttons
--------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap;
  transition: background .12s ease, border-color .12s ease;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--ink); }
.btn-secondary:hover { border-color: var(--brand); color: var(--brand); }
.btn-ghost { background: none; border-color: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--border-soft); }
.btn-danger { background: #fff; border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------------------------------------------------------------------------
   Cards, grids, KPIs
--------------------------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}
.card-pad { padding: 18px 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 20px; border-bottom: 1px solid var(--border-soft);
}
.card-head h3 { font-size: 14.5px; }
.card-head .link { font-size: 12.5px; color: var(--brand); font-weight: 600; cursor: pointer; text-decoration: none; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-card);
}
.kpi .label { font-size: 12px; color: var(--slate); font-weight: 600; }
.kpi .value { font-family: var(--font-display); font-size: 25px; font-weight: 700; margin-top: 8px; }
.kpi .foot { font-size: 11.5px; color: var(--slate); margin-top: 4px; }
.kpi.accent-amber .value { color: var(--amber); }
.kpi.accent-red .value { color: var(--red); }
.kpi.accent-green .value { color: var(--green); }

.section-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* ---------------------------------------------------------------------------
   Tables
--------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--slate); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
table.data tbody tr:hover { background: #FAFBFC; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data .num-col { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.muted, .muted { color: var(--slate); }
.row-link { cursor: pointer; }
.row-link:hover td:first-child { color: var(--brand); }

.empty-row td { text-align: center; padding: 34px 14px; color: var(--slate); }

/* ---------------------------------------------------------------------------
   Status pills
--------------------------------------------------------------------------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 100px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-slate { background: #EEF1F5; color: var(--slate); }
.pill-brand { background: var(--brand-soft); color: var(--brand); }
.pill-amber { background: var(--amber-soft); color: var(--amber); }
.pill-green { background: var(--green-soft); color: var(--green); }
.pill-red   { background: var(--red-soft); color: var(--red); }

/* ---------------------------------------------------------------------------
   Forms
--------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.field .hint { font-size: 11.5px; color: var(--slate); }
.field input, .field select, .field textarea {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; color: var(--ink); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--brand-soft); }
.field textarea { resize: vertical; min-height: 64px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.field-error { border-color: var(--red) !important; }
.error-text { color: var(--red); font-size: 11.5px; margin-top: -10px; margin-bottom: 12px; }

/* file input */
.file-drop {
  border: 1.5px dashed var(--border); border-radius: var(--radius-sm); padding: 16px;
  text-align: center; font-size: 12.5px; color: var(--slate); cursor: pointer; background: #FAFBFC;
}
.file-drop:hover { border-color: var(--brand); color: var(--brand); }
.file-drop input { display: none; }
.file-preview { font-size: 12.5px; color: var(--ink); margin-top: 8px; display: flex; align-items: center; gap: 8px; }
.file-preview a { color: var(--brand); font-weight: 600; }

/* ---------------------------------------------------------------------------
   Line item editor (PO / GRN)
--------------------------------------------------------------------------- */
.items-table { width: 100%; border-collapse: collapse; margin: 6px 0 4px; }
.items-table th { text-align: left; font-size: 11px; text-transform: uppercase; color: var(--slate); padding: 6px 8px; }
.items-table td { padding: 5px 6px; vertical-align: top; }
.items-table input { padding: 7px 8px; border: 1px solid var(--border); border-radius: 5px; width: 100%; }
.items-table .col-desc { width: 38%; }
.items-table .col-qty, .items-table .col-unit { width: 10%; }
.items-table .col-price { width: 15%; }
.items-table .col-total { width: 15%; text-align: right; padding-top: 12px; font-variant-numeric: tabular-nums; font-weight: 600;}
.items-table .col-del { width: 30px; }
.icon-btn { background: none; border: none; cursor: pointer; color: var(--slate); padding: 6px; border-radius: 5px; }
.icon-btn:hover { background: var(--red-soft); color: var(--red); }
.items-total-row td { padding-top: 12px; font-weight: 700; border-top: 1px solid var(--border); }

/* ---------------------------------------------------------------------------
   Modal / drawer
--------------------------------------------------------------------------- */
.overlay {
  position: fixed; inset: 0; background: rgba(16,24,39,0.45); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto;
}
.overlay.hidden { display: none; }
.modal {
  background: #fff; border-radius: 10px; width: 100%; max-width: 640px;
  box-shadow: 0 20px 50px rgba(16,24,39,0.25);
}
.modal.wide { max-width: 860px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border-soft);
}
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px 22px; max-height: 70vh; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px;
  border-top: 1px solid var(--border-soft);
}
.close-x { background: none; border: none; cursor: pointer; color: var(--slate); padding: 4px; }
.close-x:hover { color: var(--ink); }

/* ---------------------------------------------------------------------------
   Filters / toolbar
--------------------------------------------------------------------------- */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .search {
  position: relative; flex: 1; min-width: 200px; max-width: 320px;
}
.toolbar .search svg { position: absolute; left: 10px; top: 9px; width: 15px; height: 15px; color: var(--slate); }
.toolbar .search input { width: 100%; padding: 8px 10px 8px 32px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.toolbar select { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; }
.toolbar .spacer { flex: 1; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px;}
.page-head h2 { font-size: 19px; }
.page-head .desc { font-size: 12.5px; color: var(--slate); margin-top: 3px; }

/* ---------------------------------------------------------------------------
   Aging report
--------------------------------------------------------------------------- */
.aging-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 20px; }
.aging-card { border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--border); background: #fff; }
.aging-card .label { font-size: 11.5px; font-weight: 600; color: var(--slate); text-transform: uppercase; letter-spacing: .02em;}
.aging-card .value { font-family: var(--font-display); font-size: 20px; font-weight: 700; margin-top: 8px; }
.aging-card.b0 { border-top: 3px solid var(--green); }
.aging-card.b1 { border-top: 3px solid var(--brand); }
.aging-card.b2 { border-top: 3px solid var(--amber); }
.aging-card.b3 { border-top: 3px solid #C9622E; }
.aging-card.b4 { border-top: 3px solid var(--red); }

/* ---------------------------------------------------------------------------
   Auth screen
--------------------------------------------------------------------------- */
#auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--brand-dark), var(--brand) 70%);
  padding: 20px;
}
.auth-card {
  background: #fff; border-radius: 12px; width: 100%; max-width: 380px; padding: 34px 30px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.25);
}
.auth-card .mark { font-family: var(--font-display); font-weight: 700; font-size: 20px; color: var(--brand-dark); }
.auth-card .sub { font-size: 12.5px; color: var(--slate); margin: 4px 0 26px; }
.auth-card .btn { width: 100%; margin-top: 6px; padding: 10px; }
.auth-error { background: var(--red-soft); color: var(--red); padding: 9px 12px; border-radius: 6px; font-size: 12.5px; margin-bottom: 14px; }
.auth-toggle { text-align: center; font-size: 12.5px; color: var(--slate); margin-top: 16px; }
.auth-toggle button { background: none; border: none; color: var(--brand); font-weight: 600; cursor: pointer; }

/* ---------------------------------------------------------------------------
   Toast
--------------------------------------------------------------------------- */
#toast-host { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.2); display: flex; align-items: center; gap: 8px; min-width: 220px;
  animation: toast-in .18s ease;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------------------------------------------------------------------------
   Misc
--------------------------------------------------------------------------- */
.loading-spin {
  width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff;
  border-radius: 50%; animation: spin .6s linear infinite; display: inline-block;
}
.loading-spin.dark { border-color: rgba(22,35,58,0.2); border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, #EEF0F3 25%, #F6F7F9 37%, #EEF0F3 63%); background-size: 400% 100%; animation: shimmer 1.4s infinite; border-radius: 5px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 24px; font-size: 13px; }
.detail-grid .dt { color: var(--slate); font-size: 11.5px; text-transform: uppercase; letter-spacing: .02em; margin-bottom: 3px;}
.detail-grid .dd { font-weight: 600; }
.tag-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
hr.div { border: none; border-top: 1px solid var(--border-soft); margin: 16px 0; }

/* ---------------------------------------------------------------------------
   Mobile
--------------------------------------------------------------------------- */
@media (max-width: 980px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .section-grid { grid-template-columns: 1fr; }
  .aging-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 0 rgba(0,0,0,0); }
  .sidebar.open { transform: translateX(0); box-shadow: 20px 0 40px rgba(0,0,0,0.2); }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 16px 14px 60px; }
  .topbar { padding: 0 14px; }
  .aging-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  #sidebar-scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 30; display: none; }
  #sidebar-scrim.show { display: block; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .aging-grid { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .topbar, .toolbar, .page-head .btn, #toast-host { display: none !important; }
  .main { margin-left: 0 !important; }
  body { background: #fff; }
}
