/* ============================================
   BASE — reset, typography, utilities
   ============================================ */

* , *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background var(--med) var(--ease), color var(--med) var(--ease);
}

h1, h2, h3, h4, h5 {
  font-family: var(--font-display);
  color: var(--text);
  margin: 0 0 0.4em;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

p { margin: 0 0 1em; color: var(--text-muted); }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
ul { margin: 0; padding: 0; list-style: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

::selection { background: var(--secondary); color: #1E293B; }

/* Focus visibility */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--secondary);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* Container */
.container {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Utility */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.text-success { color: var(--success) !important; }
.text-pending { color: var(--pending) !important; }
.text-overdue { color: var(--overdue) !important; }
.text-muted { color: var(--text-muted) !important; }
.flex { display: flex; }
.hidden { display: none !important; }

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  border: 1px solid transparent;
  transition: all var(--fast) var(--ease);
  white-space: nowrap;
  line-height: 1;
}
.btn i, .btn svg { font-size: 14px; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: var(--shadow); }

.btn-accent {
  background: var(--secondary);
  color: #1E293B;
  box-shadow: var(--shadow-sm);
}
.btn-accent:hover { background: var(--secondary-dark); color: #fff; transform: translateY(-1px); box-shadow: var(--shadow); }

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

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

.btn-danger-ghost { background: transparent; color: var(--overdue); }
.btn-danger-ghost:hover { background: var(--overdue-bg); }

.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-icon {
  width: 36px; height: 36px; padding: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-muted); border: 1px solid var(--border);
}
.btn-icon:hover { background: var(--surface-alt); color: var(--primary); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none !important; }

/* ============================================
   FORMS
   ============================================ */
.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.field .hint { font-size: 12px; color: var(--text-faint); margin-top: 5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.input, select.input, textarea.input {
  width: 100%;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  transition: border-color var(--fast), box-shadow var(--fast);
}
.input::placeholder { color: var(--text-faint); }
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.14);
}
[data-theme="dark"] .input:focus { box-shadow: 0 0 0 3px rgba(76, 110, 245, 0.22); }

textarea.input { resize: vertical; min-height: 90px; }

.input-icon-wrap { position: relative; }
.input-icon-wrap i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-faint); font-size: 14px; }
.input-icon-wrap .input { padding-left: 40px; }

.file-drop {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  background: var(--surface-alt);
  cursor: pointer;
  transition: border-color var(--fast), background var(--fast);
}
.file-drop:hover { border-color: var(--secondary); background: var(--secondary-tint); }
.file-drop i { font-size: 22px; color: var(--secondary); margin-bottom: 8px; display: block; }

/* ============================================
   BADGES
   ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-pending { background: var(--pending-bg); color: var(--pending); }
.badge-overdue { background: var(--overdue-bg); color: var(--overdue); }
.badge-neutral { background: var(--surface-alt); color: var(--text-muted); }
.badge-primary { background: var(--primary-tint); color: var(--primary); }

/* ============================================
   CARDS
   ============================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }

/* ============================================
   TABLE
   ============================================ */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--surface); }
table.data-table { width: 100%; border-collapse: collapse; min-width: 640px; }
table.data-table thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-faint);
  font-weight: 700;
  padding: 14px 18px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data-table tbody td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  color: var(--text);
  vertical-align: middle;
}
table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table tbody tr { transition: background var(--fast); }
table.data-table tbody tr:hover { background: var(--surface-alt); }
.cell-muted { color: var(--text-muted); }
.cell-strong { font-weight: 600; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
tr.row-editing { background: var(--primary-tint); }
.input-cell { padding: 7px 10px; font-size: 13px; min-width: 120px; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary-tint); color: var(--primary);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12.5px; flex-shrink: 0;
}
.name-cell { display: flex; align-items: center; gap: 10px; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-muted);
}
.empty-state i { font-size: 34px; color: var(--text-faint); margin-bottom: 14px; display: block; }
.empty-state h4 { color: var(--text); margin-bottom: 6px; }
.empty-state p { max-width: 340px; margin: 0 auto 18px; }

/* ============================================
   MODAL
   ============================================ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 15, 30, 0.55);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity var(--med) var(--ease);
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 520px;
  max-height: 88vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateY(14px) scale(.98);
  transition: transform var(--med) var(--ease);
  border: 1px solid var(--border);
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }
.modal.modal-lg { max-width: 780px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 10px; }
.modal-header h3 i { color: var(--secondary); }
.modal-close { background: none; border: none; color: var(--text-faint); font-size: 18px; width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.modal-close:hover { background: var(--surface-alt); color: var(--text); }
.modal-body { padding: 22px 24px; overflow-y: auto; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0; }

/* Toast */
.toast-stack { position: fixed; bottom: 22px; right: 22px; z-index: 1100; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  border-radius: var(--radius); padding: 13px 18px; display: flex; align-items: center; gap: 10px;
  font-size: 13.5px; font-weight: 500; color: var(--text);
  animation: toast-in .28s var(--ease);
  border-left: 3px solid var(--success);
  min-width: 240px;
}
.toast i { color: var(--success); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Theme toggle switch */
.theme-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface-alt); border: 1px solid var(--border);
  border-radius: var(--radius-full); padding: 4px; cursor: pointer;
  position: relative; width: 56px; height: 30px;
}
.theme-toggle .knob {
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 11px;
  transition: transform var(--med) var(--ease), background var(--med);
}
[data-theme="dark"] .theme-toggle .knob { transform: translateX(26px); background: var(--secondary); color: #1E293B; }
