:root {
  --navy: #0f2540;
  --navy2: #1a3a5c;
  --navy3: #234d78;
  --orange: #e8500a;
  --orange2: #f06830;
  --bg: #e8ecf4;
  --surface: #ffffff;
  --surface2: #f4f6fb;
  --border: #d1d8e8;
  --text: #0d1b2a;
  --muted: #6b7a90;
  --green: #148f52;
  --red: #dc2626;
  --shadow: 0 2px 14px rgba(15,37,64,.10);
  --shadow2: 0 8px 32px rgba(15,37,64,.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.loader {
  width: 36px; height: 36px;
  border: 4px solid var(--border);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ===== TOPBAR ===== */
.topbar {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy3) 100%);
  color: #fff;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  position: sticky;
  top: 0;
  z-index: 300;
  box-shadow: 0 2px 20px rgba(0,0,0,.35);
}
.tb-brand { display: flex; align-items: center; gap: 10px; }
.tb-logo { font-family: 'Rajdhani', sans-serif; font-size: 1.2rem; font-weight: 700; letter-spacing: .5px; }
.tb-ver { font-size: .68rem; opacity: .65; border-left: 1px solid rgba(255,255,255,.2); padding-left: 10px; letter-spacing: 1px; }
.tb-right { display: flex; align-items: center; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 8px; }
.av {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--orange);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem;
}
.uname { font-size: .85rem; font-weight: 500; }
.logout-btn {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.15);
  color: #fff;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: .78rem;
  cursor: pointer;
  font-family: inherit;
}
.logout-btn:hover { background: rgba(255,255,255,.15); }

/* ===== MAIN / PAGES ===== */
.main { max-width: 1440px; margin: 0 auto; padding: 20px 14px; }
.page { display: none; }
.page.active { display: block; animation: fadeIn .22s ease; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.page-title {
  font-family: 'Rajdhani', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--navy2);
  letter-spacing: 0.01em;
}
.page-subtitle {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 3px;
}

/* ===== BUTTONS ===== */
.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: opacity .15s;
}
.btn:hover { opacity: .88; }
.btn-primary {
  background: linear-gradient(135deg, var(--navy2), var(--navy3));
  color: #fff;
  box-shadow: 0 4px 12px rgba(15,37,64,0.20);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--navy3), var(--navy2));
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(15,37,64,0.28);
}
.btn-ghost { background: var(--surface2); color: var(--navy); border: 1px solid var(--border); }
#itemsTable td:last-child {
  text-align: center;
}
.btn-icon {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: .95rem;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  transition: .15s;
}
.btn-icon:hover { color: var(--red); background: #fee2e2; }

/* ===== SEARCH / FIELDS ===== */
.search-row { margin-bottom: 12px; }
input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: .85rem;
  font-family: inherit;
  outline: none;
}
input:focus, select:focus { border-color: var(--orange); }

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
  appearance: none;
}

.field { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.field label { font-size: .72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

.detail-header-row {
  display: flex;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* ===== TABLE ===== */
.table-wrap {
  background: var(--surface);
  padding: 14px;
  overflow-x: auto;
}
.data-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.data-table th {
  text-align: left;
  padding: 9px 11px;
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: none;
}
.data-table td { padding: 9px 11px; font-size: .78rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:hover { background: var(--surface2); }
.data-table tbody tr { cursor: pointer; }

#itemsTable input, #itemsTable select {
  width: 100%;
  height: 100%;
  padding: 6px 8px;
  font-size: .8rem;
  border: none;
  border-radius: 0;
  background: transparent;
}
#itemsTable input:focus, #itemsTable select:focus {
  background: rgba(15,58,92,0.05);
  outline: none;
}

.hint { font-size: .75rem; color: var(--muted); margin-top: 8px; }

/* ===== TOTAL BAR ===== */
.total-bar {
  margin-top: 14px;
  background: var(--navy);
  color: #fff;
  border-radius: 12px;
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}
#grandTotal {
  font-family: 'Rajdhani', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--orange2);
  margin-left: 8px;
}
.btn-save {
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 18px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-save:hover { opacity: .88; }

/* ===== MODAL ===== */
.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,37,64,.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-title {
  font-family: 'Rajdhani', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-close { background: none; border: none; cursor: pointer; font-size: 1rem; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #fff;
  border-left: 4px solid var(--green);
  border-radius: 10px;
  padding: 12px 18px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
  display: none;
  z-index: 2000;
}
.toast.show { display: block; animation: fadeIn .2s ease; }
.toast.error { border-left-color: var(--red); }

/* ===== SUMMARY CARDS ===== */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}
.summary-card {
  background: var(--surface);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.summary-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.summary-icon.s1 { background: #fff3ef; }
.summary-icon.s2 { background: #e6f1fb; }
.summary-icon.s3 { background: #e1f5ee; }
.summary-label { font-size: .72rem; color: var(--muted); margin: 0; }
.summary-value { font-size: 1.2rem; font-weight: 700; color: var(--navy); margin: 0; }

/* ===== SEARCH ICON ===== */
.search-wrap { position: relative; }
.search-wrap .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: .85rem;
  pointer-events: none;
}
.search-wrap input { padding-left: 32px; }

/* ===== CATEGORY BADGE ===== */
.cat-badge {
  font-size: .68rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  display: inline-block;
}

/* ===== BASIS WITH ICON ===== */
.basis-cell { display: flex; align-items: center; gap: 4px; }
.basis-cell input { flex: 1; min-width: 0; }
.basis-icon { font-size: .75rem; flex-shrink: 0; }

/* ===== ROW ADD ANIMATION ===== */
@keyframes rowIn { from { opacity: 0; background: rgba(232,80,10,0.12); } to { opacity: 1; background: transparent; } }
.row-new { animation: rowIn .5s ease; }

.empty-state {
  background: var(--surface);
  border-radius: 10px;
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
}
.empty-icon { font-size: 28px; }
.empty-title { font-size: .85rem; font-weight: 600; color: var(--navy); margin: 8px 0 2px; }
.empty-sub { font-size: .78rem; margin: 0; }

.eye-toggle {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 6px;
}
.eye-toggle.off { color: var(--muted); }
.eye-toggle:hover { background: var(--surface2); }
.row-excluded { opacity: 0.45; }