/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #f1f5f9;
  --sidebar:      #1e293b;
  --card:         #ffffff;
  --border:       #e2e8f0;
  --text:         #0f172a;
  --text-muted:   #64748b;
  --accent:       #2563eb;
  --accent-light: #eff6ff;
  --green:        #059669;
  --red:          #dc2626;
  --yellow:       #d97706;
  --hover:        #f8fafc;
  --input-bg:     #ffffff;
  --sidebar-width: 232px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Layout ───────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.sidebar-logo .logo-text {
  font-size: 17px;
  font-weight: 700;
  color: #f8fafc;
  letter-spacing: -0.3px;
}

.sidebar-logo .logo-sub {
  font-size: 10px;
  color: #94a3b8;
  margin-top: 2px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.sidebar-nav {
  padding: 14px 0;
  flex: 1;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 10px 18px 5px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  color: #94a3b8;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  cursor: pointer;
  border-left: 2px solid transparent;
  margin: 1px 0;
}

.nav-link:hover {
  background: rgba(255,255,255,0.05);
  color: #f1f5f9;
  text-decoration: none;
}

.nav-link.active {
  background: rgba(37,99,235,0.2);
  color: #93c5fd;
  border-left-color: #3b82f6;
}

.nav-link.disabled { opacity: 0.3; cursor: not-allowed; pointer-events: none; }

.nav-icon { font-size: 14px; width: 18px; text-align: center; opacity: 0.75; }

/* ─── Main area ────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Topbar ───────────────────────────────────────────────────────────────── */
.topbar {
  height: 54px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  flex-shrink: 0;
  gap: 16px;
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  letter-spacing: -0.2px;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ─── Page body ────────────────────────────────────────────────────────────── */
.page-body {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
}

/* ─── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.card-title { font-size: 14px; font-weight: 600; color: var(--text); }

/* ─── Stat cards ───────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 22px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  letter-spacing: -0.5px;
}

.stat-value.green { color: var(--green); }
.stat-value.red   { color: var(--red); }
.stat-value.blue  { color: var(--accent); }

/* ─── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  background: var(--card);
}

thead th {
  background: #f8fafc;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid #f1f5f9; transition: background 0.1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

tbody td {
  padding: 11px 16px;
  color: var(--text);
  vertical-align: middle;
}

.cell-muted { color: var(--text-muted); }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s;
  line-height: 1.4;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

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

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { background: #f1f5f9; color: var(--text); border-color: #cbd5e1; }

.btn-danger {
  background: transparent;
  color: var(--red);
  border-color: #fecaca;
}
.btn-danger:hover:not(:disabled) { background: #fef2f2; }

.btn-success {
  background: transparent;
  color: var(--green);
  border-color: #a7f3d0;
}
.btn-success:hover:not(:disabled) { background: #f0fdf4; }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 5px 8px; font-size: 13px; }

.action-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* ─── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
  text-transform: uppercase;
}

.badge-dot { width: 6px; height: 6px; border-radius: 50%; }

.badge-green  { color: #059669; background: #d1fae5; }
.badge-green .badge-dot  { background: #059669; }
.badge-red    { color: #dc2626; background: #fee2e2; }
.badge-red .badge-dot    { background: #dc2626; }
.badge-yellow { color: #d97706; background: #fef3c7; }
.badge-yellow .badge-dot { background: #d97706; }
.badge-blue   { color: #2563eb; background: #dbeafe; }
.badge-blue .badge-dot   { background: #2563eb; }
.badge-grey   { color: #64748b; background: #f1f5f9; }
.badge-grey .badge-dot   { background: #94a3b8; }
.badge-orange { color: #c2410c; background: #ffedd5; }

/* ─── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-label .required { color: var(--red); margin-left: 2px; }

.form-control {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  color: var(--text);
  font-size: 13.5px;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
  font-family: inherit;
}

.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.form-control.error { border-color: var(--red); }

textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control option { background: #fff; color: var(--text); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.form-error { font-size: 12px; color: var(--red); margin-top: 4px; }

/* ─── Modals ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}

.modal-overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.16s ease;
  box-shadow: 0 20px 60px rgba(15,23,42,0.2);
}

.modal-lg { max-width: 680px; }
@keyframes slideUp { from { transform: translateY(14px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 15px; font-weight: 600; color: var(--text); }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 4px;
}
.modal-close:hover { background: #f1f5f9; color: var(--text); }

.modal-body { padding: 18px 22px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--border);
}

/* ─── Toast ────────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 16px;
  font-size: 13.5px;
  font-weight: 500;
  min-width: 220px;
  max-width: 360px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 0.2s ease;
  pointer-events: all;
  box-shadow: 0 8px 24px rgba(15,23,42,0.12);
  color: var(--text);
}

@keyframes toastIn  { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.toast.out { animation: toastOut 0.2s ease forwards; }
@keyframes toastOut { to { transform: translateY(10px); opacity: 0; } }

.toast-icon { font-size: 14px; }
.toast-success { border-left: 3px solid var(--green); }
.toast-error   { border-left: 3px solid var(--red); }
.toast-info    { border-left: 3px solid var(--accent); }
.toast-warning { border-left: 3px solid var(--yellow); }

/* ─── Login page ───────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 4px 24px rgba(15,23,42,0.1);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .logo-name {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.login-logo .logo-tag {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.login-card h2 { font-size: 16px; font-weight: 600; margin-bottom: 22px; }

.login-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  color: var(--red);
  font-size: 13px;
  padding: 9px 13px;
  margin-bottom: 16px;
  display: none;
}

/* ─── Detail / info grid ───────────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px 24px;
  margin-bottom: 8px;
}

.detail-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  margin-bottom: 4px;
}

.detail-value { font-size: 13.5px; color: var(--text); }

.detail-notes {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* ─── Page header ──────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.page-title-lg {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ─── Section ──────────────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title { font-size: 14px; font-weight: 600; color: var(--text); }

/* ─── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 52px 20px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 36px; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 14px; }

/* ─── Breadcrumb ───────────────────────────────────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 18px;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .sep { opacity: 0.4; }
.breadcrumb .current { color: var(--text); }

/* ─── Spinner ──────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid rgba(37,99,235,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Print styles (invoice) ───────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .btn, #toast-container { display: none !important; }
  .main { overflow: visible; }
  .page-body { padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border: none; }
}

/* ─── Misc ─────────────────────────────────────────────────────────────────── */
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-4 { margin-top: 16px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.font-mono { font-family: ui-monospace, 'SF Mono', monospace; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
