/* Design tokens */
:root {
  --nav:     #1A2742;
  --ground:  #F7F5F0;
  --accent:  #B87333;
  --text-1:  #1A1A1A;
  --text-2:  #4A4A4A;
  --text-3:  #8A8A8A;
  --border:  #D8D4CC;
  --danger:  #C0392B;
  --success: #2E7D32;
  --r-sm:    4px;
  --r-md:    8px;
  --nav-h:   56px;
  --sidebar-w: 240px;
}

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

html { font-size: 15px; }

body {
  font-family: "Leelawadee UI", "Tahoma", sans-serif;
  background: var(--ground);
  color: var(--text-1);
  min-height: 100vh;
}

/* Numbers / codes */
.mono, code, .costing-code, .item-code, input[type="number"] {
  font-family: "Consolas", monospace;
}

/* Nav bar */
.nav {
  background: var(--nav);
  color: #fff;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.02em;
  color: #fff;
  text-decoration: none;
  margin-right: 4px;
}

.nav-tabs {
  display: flex;
  gap: 2px;
  margin-right: auto;
}

.nav-tab {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.65);
  padding: 6px 14px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  text-decoration: none;
  display: flex;
  align-items: center;
  transition: background 0.15s, color 0.15s;
}

.nav-tab:hover { background: rgba(255,255,255,0.1); color: #fff; }
.nav-tab.active { background: rgba(255,255,255,0.15); color: #fff; font-weight: 600; }

.nav-user {
  color: rgba(255,255,255,0.8);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-link {
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 4px 8px;
  border-radius: var(--r-sm);
  transition: background 0.15s;
}

.nav-link:hover { background: rgba(255,255,255,0.1); color: #fff; }

/* Page layout */
.page { padding: 24px 20px; max-width: 1400px; margin: 0 auto; }
.page-header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.page-title { font-size: 1.15rem; font-weight: 700; color: var(--text-1); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  text-decoration: none;
}

.btn:hover { opacity: 0.88; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary   { background: var(--accent); color: #fff; }
.btn-secondary { background: transparent; border-color: var(--border); color: var(--text-2); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-ghost     { background: transparent; color: var(--accent); border-color: transparent; }
.btn-sm        { padding: 4px 10px; font-size: 0.8rem; }

/* Filters bar */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}

/* Search input */
.search-input {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 0.875rem;
  background: #fff;
  width: 220px;
}

.search-input:focus { outline: none; border-color: var(--accent); }

select.filter-select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 0.875rem;
  background: #fff;
  color: var(--text-2);
  cursor: pointer;
}

select.filter-select:focus { outline: none; border-color: var(--accent); }

/* Tables */
.table-wrap { overflow-x: auto; border-radius: var(--r-md); border: 1px solid var(--border); background: #fff; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  background: #fff;
  border-bottom: 2px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
  position: sticky;
  top: 0;
  cursor: pointer;
  user-select: none;
}

thead th:hover { color: var(--text-1); }
thead th.sorted-asc::after  { content: ' ↑'; color: var(--accent); }
thead th.sorted-desc::after { content: ' ↓'; color: var(--accent); }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  cursor: pointer;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f5f1ea; }
tbody tr.expanded { background: #f5f1ea; }

tbody td {
  padding: 10px 12px;
  vertical-align: top;
}

/* Expanded row */
.expand-row td {
  padding: 0 !important;
  border-bottom: 2px solid var(--accent) !important;
}

.expand-content {
  padding: 16px 20px;
  background: #faf8f4;
  border-top: 1px solid var(--border);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-draft    { background: #FFF3CD; color: #856404; }
.badge-complete { background: #D1FAE5; color: #065F46; }
.badge-accent   { background: #FDF1E8; color: var(--accent); }

/* Progress chips */
.progress-chips { display: flex; gap: 3px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
}
.chip-done    { background: #D1FAE5; color: #065F46; }
.chip-pending { background: var(--border); color: var(--text-3); }

/* Material name chips */
.mat-chip {
  display: inline-block;
  padding: 1px 7px;
  background: #f0ece4;
  border-radius: 20px;
  font-size: 0.75rem;
  color: var(--text-2);
  margin: 1px 2px;
}

/* Days badge */
.days-badge { color: var(--danger); font-weight: 600; font-size: 0.8rem; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 0.875rem;
  background: #fff;
  color: var(--text-1);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(184,115,51,0.15);
}
.form-textarea { resize: vertical; min-height: 70px; }

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

/* Money amounts */
.amount { font-family: "Consolas", monospace; text-align: right; }
.amount-lg { font-size: 1.1rem; font-weight: 700; color: var(--accent); }

/* Section header */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin-bottom: 8px;
  cursor: pointer;
  user-select: none;
}

.section-header:hover { background: #faf8f4; }
.section-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  margin-right: 8px;
  flex-shrink: 0;
}
.section-title { font-weight: 600; color: var(--text-1); }
.section-subtitle { font-size: 0.8rem; color: var(--text-3); margin-left: auto; margin-right: 10px; }

/* Warning */
.warning-text {
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 3px;
  display: block;
}

/* Card */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px;
}

/* Divider */
.divider { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

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

.toast {
  padding: 10px 16px;
  border-radius: var(--r-md);
  font-size: 0.875rem;
  font-weight: 500;
  color: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,0.18);
  animation: slideIn 0.2s ease;
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--nav); }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

.modal {
  background: #fff;
  border-radius: var(--r-md);
  padding: 24px;
  min-width: 340px;
  max-width: 520px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

.modal-title { font-weight: 700; font-size: 1rem; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* Checkbox */
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* Utility */
.text-muted { color: var(--text-3); }
.text-danger { color: var(--danger); }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-4 { gap: 4px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.hidden { display: none !important; }

/* Responsive */
@media (max-width: 768px) {
  .nav-tabs { display: none; }
  .page { padding: 16px 12px; }
}
