:root {
  --primary: #0b5fa5;
  --primary-dark: #08477c;
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --border: #e1e5eb;
  --text: #1f2937;
  --text-muted: #6b7280;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 24px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.page-header h1 { font-size: 22px; margin: 0; }

.toolbar { display: flex; gap: 10px; margin-bottom: 16px; }
.toolbar input[type="text"] {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}

.btn {
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e5e7eb; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 12px; }

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; }
thead { background: #f9fafb; }
th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
tbody tr:hover { background: #f9fafb; }
.actions { display: flex; gap: 6px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #eef2ff;
  color: var(--primary-dark);
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay.open { display: flex; }

.modal {
  background: #fff;
  border-radius: var(--radius);
  width: 480px;
  max-width: 92vw;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 20px; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.form-group input, .form-group textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

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

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 18px;
  border-radius: var(--radius);
  color: #fff;
  font-size: 14px;
  z-index: 2000;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.25s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

.empty-state { padding: 40px; text-align: center; color: var(--text-muted); }

/* Autocomplete picker */
.autocomplete-wrap { position: relative; }
.autocomplete-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  display: none;
}
.autocomplete-results.open { display: block; }
.autocomplete-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: #f4f6f9; }
.autocomplete-item .sub { font-size: 12px; color: var(--text-muted); }
.selected-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #eef2ff;
  color: var(--primary-dark);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
}
.selected-chip button {
  background: none; border: none; cursor: pointer; color: var(--primary-dark);
  font-weight: bold; font-size: 14px;
}

/* Line items */
.items-table input {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 13px;
}
.items-table td { vertical-align: middle; }
.totals-box {
  margin-left: auto;
  width: 280px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: #f9fafb;
}
.totals-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; }
.totals-row.grand { font-weight: 700; font-size: 16px; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 10px; }

.section-title { font-size: 14px; font-weight: 700; margin: 24px 0 10px; color: var(--text); }
