:root {
  --teal-700: #0f766e;
  --teal-600: #0d9488;
  --teal-500: #14b8a6;
  --teal-100: #ccfbf1;
  --teal-50: #f0fdfa;
  --yellow-400: #facc15;
  --yellow-500: #eab308;
  --yellow-100: #fef9c3;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --green-500: #22c55e;
  --green-600: #16a34a;
  --gray-900: #111827;
  --gray-800: #1f2937;
  --gray-700: #374151;
  --gray-600: #4b5563;
  --gray-500: #6b7280;
  --gray-400: #9ca3af;
  --gray-300: #d1d5db;
  --gray-200: #e5e7eb;
  --gray-100: #f3f4f6;
  --gray-50: #f9fafb;
  --white: #ffffff;
  --black: #000000;

  --bg-body: var(--gray-100);
  --bg-card: var(--white);
  --bg-sidebar: var(--teal-700);
  --bg-sidebar-hover: rgba(255, 255, 255, 0.1);
  --bg-input: var(--white);
  --text-primary: var(--gray-900);
  --text-secondary: var(--gray-600);
  --text-muted: var(--gray-500);
  --text-inverse: var(--white);
  --border-color: var(--gray-300);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --radius: 0.5rem;
}

.dark {
  --bg-body: var(--gray-900);
  --bg-card: var(--gray-800);
  --bg-sidebar: #134e4a;
  --bg-sidebar-hover: rgba(255, 255, 255, 0.08);
  --bg-input: var(--gray-700);
  --text-primary: var(--gray-100);
  --text-secondary: var(--gray-300);
  --text-muted: var(--gray-400);
  --text-inverse: var(--gray-100);
  --border-color: var(--gray-600);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -4px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-primary);
  height: 100%;
  line-height: 1.5;
}

a {
  color: var(--teal-600);
  text-decoration: none;
}

/* ---------- Login ---------- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-container {
  width: 100%;
  max-width: 420px;
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2rem;
}

.login-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-logo .logo-img {
  display: block;
  width: 240px;
  max-width: 100%;
  height: auto;
  margin: 0 auto 0.75rem;
}

.login-logo h1 {
  margin: 0;
  font-size: 1.75rem;
  color: var(--teal-700);
}

.dark .login-logo h1 {
  color: var(--teal-500);
}

.login-subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.login-form .form-group {
  margin-bottom: 1rem;
}

.login-footer {
  margin-top: 1.5rem;
  text-align: center;
}

/* ---------- App shell ---------- */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  position: relative;
  width: 260px;
  min-width: 180px;
  max-width: 30vw;
  background: var(--bg-sidebar);
  color: var(--text-inverse);
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease;
  z-index: 100;
}

.sidebar.collapsed {
  transform: translateX(-100%);
  position: absolute;
  height: 100%;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.logo-img {
  display: block;
  height: 40px;
  width: auto;
  flex-shrink: 0;
}

.app-title {
  font-weight: 700;
  font-size: 1.1rem;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0;
}

.nav-section {
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 0.5rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: rgba(255, 255, 255, 0.9);
  transition: background 0.15s;
}

.nav-link:hover,
.nav-link.active {
  background: var(--bg-sidebar-hover);
  color: var(--white);
}

.nav-link.active {
  border-left: 4px solid var(--yellow-400);
}

.nav-icon {
  font-size: 1.1rem;
  width: 24px;
  text-align: center;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.user-info {
  font-size: 0.875rem;
  margin: 0.75rem 0;
  color: rgba(255, 255, 255, 0.85);
  word-break: break-word;
}

.sidebar-resizer {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  background: rgba(255, 255, 255, 0.1);
  z-index: 101;
}

.sidebar-resizer:hover {
  background: var(--yellow-400);
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow);
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-primary);
  cursor: pointer;
}

.page-title {
  margin: 0;
  font-size: 1.5rem;
  color: var(--teal-700);
}

.dark .page-title {
  color: var(--teal-500);
}

.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--teal-600);
  color: var(--white);
}

.btn-primary:hover {
  background: var(--teal-700);
}

.btn-secondary {
  background: var(--gray-200);
  color: var(--gray-800);
}

.dark .btn-secondary {
  background: var(--gray-700);
  color: var(--gray-100);
}

.btn-success {
  background: var(--green-600);
  color: var(--white);
}

.btn-success:hover {
  background: var(--green-500);
}

.btn-danger {
  background: var(--red-600);
  color: var(--white);
}

.btn-danger:hover {
  background: var(--red-500);
}

.btn-warning {
  background: var(--yellow-500);
  color: var(--gray-900);
}

.btn-warning:hover {
  background: var(--yellow-400);
}

.btn-outline-danger {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.5);
  color: var(--white);
}

.btn-outline-danger:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
}

.btn-block {
  width: 100%;
}

.btn-icon-only {
  padding: 0.5rem 0.625rem;
  min-width: 38px;
}

/* ---------- Forms ---------- */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.375rem;
  font-weight: 500;
  color: var(--text-primary);
}

.form-control {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.95rem;
}

.form-control:focus {
  outline: none;
  border-color: var(--teal-500);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.2);
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
}

textarea.form-control {
  min-height: 120px;
  resize: vertical;
}

textarea.form-control.persona-textarea {
  min-height: 500px;
  max-height: 70vh;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
  line-height: 1.6;
}

.persona-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border, rgba(0, 0, 0, 0.1));
  padding-bottom: 0.75rem;
}

.persona-tab {
  padding: 0.5rem 1.25rem;
  border: 1px solid var(--border, rgba(0, 0, 0, 0.1));
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  font-weight: 600;
  color: inherit;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.persona-tab:hover {
  border-color: var(--teal-600, #0d9488);
}

.persona-tab.active {
  background: var(--teal-600, #0d9488);
  border-color: var(--teal-600, #0d9488);
  color: #fff;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.view-field {
  margin-bottom: 1rem;
}

.view-field label {
  font-weight: 600;
  color: var(--teal-700);
  margin-bottom: 0.25rem;
}

.dark .view-field label {
  color: var(--teal-500);
}

.view-value {
  padding: 0.625rem 0.75rem;
  background: var(--gray-50);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--text-primary);
  min-height: 42px;
}

.dark .view-value {
  background: var(--gray-700);
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
}

.btn-icon-search {
  background: var(--yellow-500);
  color: var(--gray-900);
}

.btn-icon-search:hover {
  background: var(--yellow-400);
}

.btn-icon-clear {
  background: var(--gray-300);
  color: var(--gray-700);
}

.btn-icon-clear:hover {
  background: var(--gray-400);
}

.dark .btn-icon-clear {
  background: var(--gray-600);
  color: var(--gray-200);
}

.dark .btn-icon-clear:hover {
  background: var(--gray-500);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.form-actions .btn-success {
  order: 2;
}

.form-actions .btn-danger {
  order: 1;
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.card-title {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  color: var(--teal-700);
}

.dark .card-title {
  color: var(--teal-500);
}

/* ---------- Alerts ---------- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.alert-danger {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.dark .alert-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.3);
}

.alert-success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.dark .alert-success {
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
}

.hidden {
  display: none !important;
}

/* ---------- Data table ---------- */
.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.table-search {
  display: flex;
  gap: 0.5rem;
  flex: 1;
  min-width: 260px;
}

.table-search input {
  max-width: 320px;
}

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 1rem;
}

.table-actions-left {
  display: flex;
  gap: 0.5rem;
}

.table-actions {
  display: flex;
  gap: 0.5rem;
}

.table-wrapper {
  overflow: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-card);
  max-height: 60vh;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
  white-space: nowrap;
}

.data-table th {
  background: var(--teal-50);
  color: var(--teal-800);
  font-weight: 600;
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 10;
}

.dark .data-table th {
  background: var(--gray-700);
  color: var(--teal-100);
}

.data-table tbody tr:hover {
  background: var(--gray-50);
}

.dark .data-table tbody tr:hover {
  background: var(--gray-700);
}

.data-table .col-action {
  width: 50px;
  min-width: 50px;
  text-align: center;
}

.action-menu {
  position: relative;
  display: inline-block;
}

.btn-action-menu {
  background: var(--yellow-500);
  color: var(--gray-900);
  border: none;
  border-radius: var(--radius);
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-action-menu:hover {
  background: var(--yellow-400);
}

.action-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 50;
  display: flex;
  flex-direction: row;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  margin-top: 4px;
}

.action-dropdown a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 1rem;
  text-decoration: none;
}

.action-dropdown a.action-add {
  color: var(--green-600);
}

.action-dropdown a:hover {
  background: var(--teal-50);
}

.dark .action-dropdown a:hover {
  background: var(--gray-700);
}

.data-table .col-status {
  width: 90px;
  min-width: 90px;
}

.data-table .col-id {
  width: 70px;
  min-width: 70px;
}

.data-table .col-code {
  width: 130px;
  min-width: 130px;
}

.data-table .col-name {
  width: 180px;
  min-width: 180px;
  max-width: 300px;
}

.data-table .col-desc {
  min-width: 220px;
  max-width: 400px;
}

.data-table .col-date {
  width: 120px;
  min-width: 120px;
}

.cell-truncate {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 400px;
  white-space: normal;
}

.status-badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-active {
  background: #dcfce7;
  color: #166534;
}

.status-inactive {
  background: #fee2e2;
  color: #991b1b;
}

/* ---------- Pagination ---------- */
.pagination-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-top: 1rem;
}

.pagination-controls {
  display: flex;
  gap: 0.25rem;
}

.pagination-controls button {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  border-radius: var(--radius);
  cursor: pointer;
}

.pagination-controls button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.page-info {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.page-size {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.page-size select {
  width: auto;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

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

.modal-header h3 {
  margin: 0;
  color: var(--teal-700);
}

.dark .modal-header h3 {
  color: var(--teal-500);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 1rem;
  overflow-y: auto;
  min-height: 0;
}

.modal-footer {
  padding: 1rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.modal-image {
  overscroll-behavior: contain;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

.modal-image.dragging {
  cursor: grabbing;
}

.modal-image img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
}

/* ---------- FK Picker ---------- */
.picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 1rem;
}

.picker-panel {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 600px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.picker-header h3 {
  margin: 0;
}

.picker-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}

.picker-search {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.picker-table-wrap {
  overflow: auto;
  flex: 1;
  max-height: 50vh;
}

.picker-table {
  width: 100%;
  border-collapse: collapse;
}

.picker-table th,
.picker-table td {
  padding: 0.625rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.picker-table tbody tr {
  cursor: pointer;
}

.picker-table tbody tr:hover {
  background: var(--teal-50);
}

.dark .picker-table tbody tr:hover {
  background: var(--gray-700);
}

.picker-footer {
  padding: 1rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

/* ---------- Receipt Upload ---------- */
.upload-zone {
  border: 3px dashed var(--teal-500);
  border-radius: var(--radius);
  background: var(--teal-50);
  padding: 3rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.dark .upload-zone {
  background: rgba(20, 184, 166, 0.08);
}

.upload-zone.dragover {
  background: var(--yellow-100);
  border-color: var(--yellow-500);
}

.dark .upload-zone.dragover {
  background: rgba(250, 204, 21, 0.12);
}

.upload-zone-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
}

.upload-zone-text {
  font-size: 1.1rem;
  color: var(--text-secondary);
}

.upload-zone-text strong {
  color: var(--teal-600);
}

.upload-list {
  margin-top: 1.5rem;
}

.upload-list h4 {
  margin: 0 0 0.75rem;
  color: var(--teal-700);
}

.dark .upload-list h4 {
  color: var(--teal-500);
}

.upload-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  background: var(--bg-card);
}

.process-progress {
  margin-top: 1.5rem;
}

.progress-bar {
  height: 20px;
  background: var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.dark .progress-bar {
  background: var(--gray-700);
}

.progress-fill {
  height: 100%;
  background: var(--teal-500);
  width: 0;
  transition: width 0.3s ease;
}

.progress-text {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.log-list {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 0.75rem;
  background: var(--bg-body);
  margin-top: 1rem;
}

.log-item {
  font-size: 0.875rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--border-color);
}

.log-item:last-child {
  border-bottom: none;
}

/* ---------- Dashboard ---------- */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.quick-link-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.quick-link-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.quick-link-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: var(--teal-100);
  color: var(--teal-700);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.dark .quick-link-icon {
  background: rgba(20, 184, 166, 0.15);
  color: var(--teal-500);
}

.quick-link-title {
  font-weight: 600;
  color: var(--text-primary);
}

.quick-link-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ---------- Ask AI Chat ---------- */
.chat-card {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 140px);
  min-height: 400px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  background: var(--gray-50);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.dark .chat-messages {
  background: var(--gray-700);
}

.chat-message {
  display: flex;
  margin-bottom: 1rem;
}

.chat-message.user {
  justify-content: flex-end;
}

.chat-message.ai {
  justify-content: flex-start;
}

.chat-bubble {
  max-width: 80%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  line-height: 1.5;
  word-break: break-word;
}

.chat-message.user .chat-bubble {
  background: var(--teal-600);
  color: var(--white);
  border-bottom-right-radius: 0.25rem;
}

.chat-message.ai .chat-bubble {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 0.25rem;
  box-shadow: var(--shadow);
}

.chat-message.ai .chat-bubble strong {
  color: var(--teal-700);
}

.dark .chat-message.ai .chat-bubble strong {
  color: var(--teal-500);
}

.chat-message.ai .chat-bubble ul,
.chat-message.ai .chat-bubble ol {
  margin: 0.5rem 0;
  padding-left: 1.25rem;
}

.chat-message.ai .chat-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

.chat-message.ai .chat-bubble th,
.chat-message.ai .chat-bubble td {
  border: 1px solid var(--border-color);
  padding: 0.375rem 0.5rem;
  text-align: left;
}

.chat-message.ai .chat-bubble th {
  background: var(--teal-50);
  color: var(--teal-700);
}

.dark .chat-message.ai .chat-bubble th {
  background: var(--gray-600);
  color: var(--teal-100);
}

.chat-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.chat-input-row input {
  flex: 1;
}

.chat-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 0.5rem 0;
}

.sql-details {
  margin-top: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
}

.sql-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--gray-100);
  color: var(--teal-700);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

.dark .sql-summary {
  background: var(--gray-700);
  color: var(--teal-500);
}

.sql-summary::before {
  content: '▶';
  font-size: 0.75rem;
  transition: transform 0.15s;
}

.sql-details.open .sql-summary::before {
  transform: rotate(90deg);
}

.sql-content {
  display: none;
  padding: 0.75rem;
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
}

.sql-details.open .sql-content {
  display: block;
}

.sql-content pre {
  margin: 0;
  padding: 0.75rem;
  background: var(--gray-100);
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.dark .sql-content pre {
  background: var(--gray-800);
}

.sql-content .sql-results {
  margin-top: 0.75rem;
  max-height: 200px;
  overflow: auto;
}

.sql-content .data-table th,
.sql-content .data-table td {
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  white-space: nowrap;
}

.sql-content .sql-results table {
  width: auto;
  min-width: 100%;
}

/* ---------- Theme toggle ---------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--white);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
}

.login-footer .theme-toggle {
  background: var(--gray-100);
  border-color: var(--gray-300);
  color: var(--gray-700);
}

.dark .login-footer .theme-toggle {
  background: var(--gray-700);
  border-color: var(--gray-600);
  color: var(--gray-100);
}

/* ---------- Utilities ---------- */
.text-center {
  text-align: center;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--gray-300);
  border-top-color: var(--teal-500);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 260px;
    max-width: 80vw;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .menu-toggle {
    display: block;
  }

  .topbar {
    padding: 0.75rem 1rem;
  }

  .content-area {
    padding: 1rem;
  }

  .table-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .table-search input {
    max-width: none;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions .btn {
    width: 100%;
    order: unset;
  }

  .pagination-bar {
    flex-direction: column;
    align-items: stretch;
  }
}

/* ---------- Inline Detail Section (Master-Detail Forms) ---------- */
.detail-section {
  margin-top: 1.5rem;
  border-top: 2px solid var(--border-color);
  padding-top: 1rem;
}

.detail-table-wrap {
  overflow-x: auto;
}

.detail-header {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 0;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--teal-700);
  border-bottom: 2px solid var(--border-color);
  min-width: 700px;
}

.dark .detail-header {
  color: var(--teal-500);
}

.detail-h-no { width: 40px; min-width: 40px; text-align: center; }
.detail-h-type { width: 110px; min-width: 110px; }
.detail-h-addn { flex: 1; min-width: 140px; }
.detail-h-ded { flex: 1; min-width: 140px; }
.detail-h-amount { width: 100px; min-width: 100px; }
.detail-h-status { width: 90px; min-width: 90px; }
.detail-h-action { width: 40px; min-width: 40px; }

.detail-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-color);
  min-width: 700px;
}

.detail-row:hover {
  background: var(--gray-50);
}

.dark .detail-row:hover {
  background: var(--gray-700);
}

.detail-item-no {
  width: 40px;
  min-width: 40px;
  text-align: center;
  font-weight: 600;
  color: var(--text-muted);
}

.detail-row .detail-type { width: 110px; min-width: 110px; }
.detail-row .detail-addition { flex: 1; min-width: 140px; }
.detail-row .detail-deduction { flex: 1; min-width: 140px; }
.detail-row .detail-amount { width: 100px; min-width: 100px; }
.detail-row .detail-status { width: 90px; min-width: 90px; }

.detail-row .remove-detail {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.detail-row select.form-control,
.detail-row input.form-control {
  height: 36px;
  padding: 0.375rem 0.5rem;
  font-size: 0.85rem;
}

@media (max-width: 480px) {
  .login-card {
    padding: 1.5rem 1rem;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}
