:root {
  --navy: #055367;
  --teal: #1F7A95;
  --gold: #C2822B;
  --gold-light: #FBF0E1;
  --gold-text: #A87534;
  --cream: #F4F4E8;
  --bg-page: #FAFAF5;
  --green: #3B8F6B;
  --green-light: #EAF5EF;
  --danger: #C0392B;
  --danger-light: #FDEDEB;
  --border: #E6E6DC;
  --border-soft: #EFEFE6;
  --text-main: #1C2B2E;
  --text-mute: #6B7B7D;
  --text-faint: #9AA5A4;
  --radius-sm: 6px;
  --radius-md: 9px;
  --radius-lg: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: 'Sarabun', 'Inter', sans-serif;
  background: var(--bg-page);
  color: var(--text-main);
  font-size: 14px;
}

button, input, select { font-family: inherit; }

/* ===================== App shell ===================== */
.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

/* ===================== Sidebar ===================== */
.sidebar {
  background: #fff;
  border-right: 0.5px solid var(--border);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 24px;
}
.sidebar .brand img {
  height: 32px;
  width: auto;
}
.sidebar .brand .brand-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--navy);
  line-height: 1.2;
}
.sidebar .brand .brand-sub {
  font-size: 10.5px;
  color: var(--text-faint);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-mute);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: var(--cream); }
.nav-item.active {
  background: var(--cream);
  color: var(--navy);
}
.nav-item .icon { font-size: 17px; line-height: 1; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 0.5px solid var(--border);
  font-size: 11px;
  color: var(--text-faint);
}

/* ===================== Main content ===================== */
.main-content {
  padding: 28px 36px;
  max-width: 1080px;
}

.view { display: none; }
.view.active { display: block; animation: fadeIn .15s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.page-header h1 {
  font-size: 19px;
  font-weight: 600;
  margin: 0;
  color: var(--text-main);
}

/* ===================== Buttons ===================== */
button { cursor: pointer; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  transition: opacity .15s;
}
.btn:active { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--navy); color: #fff; }
.btn-gold { background: var(--gold); color: #fff; }
.btn-ghost {
  background: var(--cream);
  color: var(--navy);
}
.btn-ghost-gold {
  background: var(--gold-light);
  color: var(--gold-text);
}
.btn-outline {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text-mute);
}
.btn-danger-text {
  background: none;
  color: var(--danger);
  padding: 6px 10px;
}
.btn-sm { padding: 6px 12px; font-size: 12.5px; }

/* ===================== Toolbar ===================== */
.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  align-items: center;
}
.search-input {
  flex: 1;
  max-width: 320px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 13.5px;
  background: #fff;
}
.search-input:focus { outline: 2px solid var(--teal); outline-offset: -1px; }

.chip-group { display: flex; gap: 6px; }
.chip {
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-mute);
}
.chip.active { background: var(--navy); border-color: var(--navy); color: #fff; }

/* ===================== Equipment rows ===================== */
.eq-table {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.eq-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 16px;
  background: #fff;
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border-soft);
  cursor: pointer;
  transition: border-color .15s;
}
.eq-row:hover { border-color: var(--border); }

.eq-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.available { background: var(--green); }
.status-dot.borrowed { background: var(--gold); }

.eq-code {
  font-size: 11px;
  font-weight: 600;
  color: var(--gold-text);
  min-width: 64px;
  flex-shrink: 0;
}
.eq-name { font-size: 13.5px; font-weight: 500; color: var(--text-main); }
.eq-type { font-size: 12px; color: var(--text-faint); margin-left: 6px; }
.eq-borrower {
  font-size: 12px;
  color: var(--text-mute);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}

.eq-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ===================== Empty state ===================== */
.empty-state {
  text-align: center;
  padding: 70px 20px;
  color: var(--text-mute);
}
.empty-state .icon { font-size: 40px; margin-bottom: 12px; opacity: 0.5; }
.empty-state .title { font-weight: 600; color: var(--text-main); margin-bottom: 4px; font-size: 15px; }
.empty-state .desc { font-size: 13px; }

/* ===================== Modal ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 32, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal-box {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 460px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
}
.modal-box.wide { max-width: 600px; }
.modal-box h3 {
  margin: 0 0 18px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
}
.modal-box h3 .modal-sub {
  display: block;
  font-size: 12.5px;
  font-weight: 400;
  color: var(--text-mute);
  margin-top: 3px;
}

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-mute);
  margin-bottom: 6px;
}
.field .hint {
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 5px;
}

input[type="text"], select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  background: #fff;
  color: var(--text-main);
}
input[type="text"]:focus, select:focus {
  outline: 2px solid var(--teal);
  outline-offset: -1px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.modal-actions .btn { flex: 1; justify-content: center; }

/* ===================== Photo capture ===================== */
.photo-box {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-page);
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.photo-box img {
  max-width: 100%;
  max-height: 200px;
  border-radius: var(--radius-sm);
  display: block;
}
.photo-box .placeholder { color: var(--text-faint); font-size: 13px; }
.photo-box .placeholder .icon { font-size: 22px; display: block; margin-bottom: 6px; }

/* ===================== Detail panel (history per item) ===================== */
.detail-info-box {
  background: var(--cream);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--navy);
}

.hist-entry {
  border: 0.5px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.hist-entry-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}
.hist-entry-top .who { font-size: 13.5px; font-weight: 500; }
.hist-entry-top .meta { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 10px;
  white-space: nowrap;
}
.badge.returned { background: var(--green-light); color: var(--green); }
.badge.borrowed { background: var(--gold-light); color: var(--gold-text); }

.photo-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.photo-pair .ph {
  position: relative;
  aspect-ratio: 4/3;
  background: var(--cream);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.photo-pair .ph img { width: 100%; height: 100%; object-fit: cover; }
.photo-pair .ph .tag {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  padding: 2px 8px;
  border-radius: 8px;
}
.photo-pair .ph .tag.before { background: var(--navy); }
.photo-pair .ph .tag.after { background: var(--teal); }
.photo-pair .ph.empty-ph { color: var(--text-faint); font-size: 11px; cursor: default; }

.document-photo-box {
  position: relative;
  margin-top: 8px;
  height: 110px;
  background: var(--cream);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.document-photo-box img { width: 100%; height: 100%; object-fit: contain; }
.document-photo-box .tag {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--gold-text);
}

/* ===================== Toast ===================== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--navy);
  color: #fff;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  z-index: 200;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }

.loader {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton-row {
  height: 46px;
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, var(--border-soft) 25%, var(--cream) 37%, var(--border-soft) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  margin-bottom: 7px;
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ===================== Photo grid (multi-photo equipment) ===================== */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 4px;
}
.photo-grid .photo-slot {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-page);
  border: 1.5px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.photo-grid .photo-slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-grid .photo-slot .icon { font-size: 20px; color: var(--text-faint); }
.photo-grid .photo-slot .remove-photo-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(20,30,32,0.65);
  color: #fff;
  border: none;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  padding: 0;
}

.required-mark {
  color: var(--danger);
  font-weight: 600;
  font-size: 11px;
  text-transform: none;
}

/* ===================== Employee / Department rows ===================== */
.simple-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 16px;
  background: #fff;
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border-soft);
  margin-bottom: 7px;
}
.simple-row .simple-row-name { font-size: 13.5px; font-weight: 500; color: var(--text-main); }
.simple-row .simple-row-sub { font-size: 12px; color: var(--text-faint); margin-left: 8px; }

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 14px;
  }
  .sidebar .brand { padding: 0 12px 0 0; border-right: 0.5px solid var(--border); margin-right: 8px; }
  .sidebar-footer { display: none; }
  .main-content { padding: 20px 16px; }
}
