/* ===================== Design tokens ===================== */
:root {
  --color-bg: #f4f6fb;
  --color-surface: #ffffff;
  --color-surface-alt: #f0f2f8;
  --color-border: #e2e5ee;
  --color-text: #1c2233;
  --color-text-muted: #6b7280;
  --color-primary: #3454d1;
  --color-primary-hover: #2a44b0;
  --color-primary-soft: #eaeefc;
  --color-success: #1b8a5a;
  --color-success-soft: #e5f6ee;
  --color-danger: #d1373f;
  --color-danger-soft: #fceaec;
  --color-warning: #b9770e;
  --color-warning-soft: #fdf1de;
  --color-info: #2a7de1;
  --color-info-soft: #e7f1fd;
  --shadow-sm: 0 1px 2px rgba(20, 24, 40, 0.06);
  --shadow-md: 0 4px 14px rgba(20, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(20, 24, 40, 0.14);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --sidebar-width: 240px;
  --topbar-height: 60px;
  --font-sans: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
}

:root[data-theme="dark"] {
  --color-bg: #10131c;
  --color-surface: #181d2a;
  --color-surface-alt: #1f2534;
  --color-border: #2a3143;
  --color-text: #e8eaf1;
  --color-text-muted: #9aa1b5;
  --color-primary: #6d87f2;
  --color-primary-hover: #8398f5;
  --color-primary-soft: #232b47;
  --color-success: #3fcf8e;
  --color-success-soft: #163829;
  --color-danger: #f16d75;
  --color-danger-soft: #3a1e22;
  --color-warning: #f2b043;
  --color-warning-soft: #3a2c12;
  --color-info: #6cb0f6;
  --color-info-soft: #182a3d;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #10131c;
    --color-surface: #181d2a;
    --color-surface-alt: #1f2534;
    --color-border: #2a3143;
    --color-text: #e8eaf1;
    --color-text-muted: #9aa1b5;
    --color-primary: #6d87f2;
    --color-primary-hover: #8398f5;
    --color-primary-soft: #232b47;
    --color-success: #3fcf8e;
    --color-success-soft: #163829;
    --color-danger: #f16d75;
    --color-danger-soft: #3a1e22;
    --color-warning: #f2b043;
    --color-warning-soft: #3a2c12;
    --color-info: #6cb0f6;
    --color-info-soft: #182a3d;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

h1, h2, h3, h4 { margin: 0 0 8px; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0 0 8px; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ===================== Buttons ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-hover); }

.btn-outline { background: transparent; border-color: var(--color-border); color: var(--color-text); }
.btn-outline:hover:not(:disabled) { border-color: var(--color-primary); color: var(--color-primary); }

.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(0.92); }

.btn-ghost { background: transparent; color: var(--color-text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--color-surface-alt); color: var(--color-text); }

.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: var(--radius-sm); }

/* ===================== Forms ===================== */
label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 5px;
}
.field { margin-bottom: 14px; }
input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}
textarea { resize: vertical; min-height: 70px; }
.field-error { color: var(--color-danger); font-size: 12px; margin-top: 4px; display: none; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--color-danger); }
.field.has-error .field-error { display: block; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 16px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ===================== Cards / Surfaces ===================== */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 18px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

/* ===================== Badges ===================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 700;
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.badge-cash { background: var(--color-success-soft); color: var(--color-success); }
.badge-wish { background: var(--color-info-soft); color: var(--color-info); }
.badge-not-paid { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-liability { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-return { background: var(--color-surface-alt); color: var(--color-text-muted); }

.badge-pending { background: var(--color-surface-alt); color: var(--color-text-muted); }
.badge-out-for-delivery { background: var(--color-info-soft); color: var(--color-info); }
.badge-delivered { background: var(--color-success-soft); color: var(--color-success); }
.badge-failed-delivery { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-returned { background: var(--color-warning-soft); color: var(--color-warning); }

.badge-admin { background: var(--color-primary-soft); color: var(--color-primary); }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning); text-transform: none; letter-spacing: normal; padding: 5px 12px; }
.badge-employee { background: var(--color-surface-alt); color: var(--color-text-muted); }

/* ===================== Tables ===================== */
.table-wrap { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--color-border); }
table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--color-surface); }
thead th {
  text-align: left;
  padding: 11px 14px;
  background: var(--color-surface-alt);
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
tbody td { padding: 11px 14px; border-top: 1px solid var(--color-border); vertical-align: middle; }
tbody tr:hover { background: var(--color-surface-alt); }
.text-muted { color: var(--color-text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.empty-row td { text-align: center; padding: 30px; color: var(--color-text-muted); }

/* ===================== Modal ===================== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 12, 20, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px;
  max-height: 90vh;
  display: flex; flex-direction: column;
}
.modal-wide { max-width: 820px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--color-border);
}
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-footer {
  padding: 16px 22px; border-top: 1px solid var(--color-border);
  display: flex; justify-content: flex-end; gap: 10px;
}
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--color-text-muted); }

/* ===================== Toasts ===================== */
#toast-container {
  position: fixed; bottom: 22px; right: 22px; z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary);
  box-shadow: var(--shadow-md); border-radius: var(--radius-sm);
  padding: 12px 16px; font-size: 13px; min-width: 240px; max-width: 360px;
  animation: toast-in 0.2s ease;
}
.toast.success { border-left-color: var(--color-success); }
.toast.error { border-left-color: var(--color-danger); }
.toast.info { border-left-color: var(--color-info); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ===================== Utility ===================== */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-gap-8 { display: flex; align-items: center; gap: 8px; }
.flex-gap-12 { display: flex; align-items: center; gap: 12px; }
.flex-wrap { flex-wrap: wrap; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
.spinner-dark { border-color: var(--color-border); border-top-color: var(--color-primary); }
@keyframes spin { to { transform: rotate(360deg); } }

.section-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 16px;
}
.search-input { max-width: 280px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.stat-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.stat-card .stat-label { font-size: 12px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.03em; font-weight: 600; }
.stat-card .stat-value { font-size: 24px; font-weight: 700; margin: 6px 0 8px; }
.stat-card .stat-breakdown { display: flex; gap: 12px; font-size: 12px; color: var(--color-text-muted); }
.stat-card.net-cash-highlight { background: var(--color-success-soft); border-color: var(--color-success); }
.stat-card.net-cash-highlight .stat-label, .stat-card.net-cash-highlight .stat-value { color: var(--color-success); }
