/* ============================================================
   ระบบตรวจครุภัณฑ์ วิทยาลัยการดนตรี — Stylesheet
   ============================================================ */

:root {
  --bg: #FAF8F4;
  --header: #16264D;
  --header-hover: #0F1B38;
  --accent: #D9A441;
  --teal: #2C5694; /* หมายเหตุ: ใช้สีน้ำเงิน (ไม่ใช่เขียวอมฟ้าตามชื่อตัวแปรเดิม) สำหรับลิงก์/ปุ่มรอง/ขอบ input ตอน focus */
  --ok: #2F6F4E;
  --warn: #B8862B;
  --danger: #A33D3D;
  --stone-800: #292524;
  --stone-700: #44403c;
  --stone-500: #78716c;
  --stone-400: #a8a29e;
  --stone-200: #e7e5e4;
  --stone-100: #f5f5f4;
  --stone-50: #fafaf9;
  --white: #ffffff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Sarabun', 'Inter', 'Noto Sans Thai', sans-serif;
  background: var(--bg);
  color: var(--stone-800);
}

a { color: inherit; text-decoration: none; }

.container {
  max-width: 1152px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ---------- Header ---------- */
header.app-header {
  background: var(--header);
  color: #fff;
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.header-brand .logo {
  background: rgba(255,255,255,0.1);
  border-radius: 0.5rem;
  padding: 0.5rem;
  display: flex;
}
.header-brand h1 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.2;
}
.header-brand p {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.6);
  margin: 0;
  line-height: 1.2;
}
.header-user {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  font-size: 0.8rem;
  color: rgba(255,255,255,0.75);
}
.header-user .role-badge {
  font-size: 0.65rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: rgba(217,164,65,0.2);
  color: var(--accent);
  border: 1px solid rgba(217,164,65,0.4);
}
.header-user a.logout {
  color: rgba(255,255,255,0.6);
  font-size: 0.8rem;
}
.header-user a.logout:hover { color: #fff; }

nav.tabs {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
}
nav.tabs a {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 0.9rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: rgba(255,255,255,0.55);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
nav.tabs a.active {
  color: #fff;
  border-bottom-color: var(--accent);
}
nav.tabs a:hover { color: rgba(255,255,255,0.85); }

main { padding: 1.5rem 0; }

/* ---------- Stats ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
@media (min-width: 640px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}
.stat-card {
  background: #fff;
  border: 1px solid var(--stone-200);
  border-radius: 0.75rem;
  padding: 1rem;
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}
.stat-card .icon-box {
  border-radius: 0.5rem;
  padding: 0.5rem;
  display: flex;
}
.stat-card .value {
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1;
}
.stat-card .label {
  font-size: 0.75rem;
  color: var(--stone-500);
  margin-top: 0.25rem;
}

/* ---------- Cards / panels ---------- */
.panel {
  background: #fff;
  border: 1px solid var(--stone-200);
  border-radius: 0.75rem;
  padding: 1rem;
}
.panel h3 {
  font-size: 0.875rem;
  font-weight: 600;
  margin: 0 0 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.grid-2 {
  display: grid;
  gap: 1rem;
}
@media (min-width: 640px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
}

.alert-box {
  border-radius: 0.75rem;
  padding: 1rem;
  margin-bottom: 1.5rem;
}
.alert-box.danger {
  background: rgba(163,61,61,0.05);
  border: 1px solid rgba(163,61,61,0.2);
}
.alert-box .alert-title {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--danger);
  font-weight: 500;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}
.alert-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
  padding: 0.2rem 0;
  color: var(--stone-700);
}

/* ---------- Pills ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.search-box {
  position: relative;
  flex: 1;
  min-width: 200px;
}
.search-box input {
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2.25rem;
}
.search-box svg {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--stone-400);
}
.filter-chips {
  display: flex;
  gap: 0.4rem;
}
.filter-chips a {
  padding: 0.4rem 0.8rem;
  border-radius: 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  background: #fff;
  border: 1px solid var(--stone-200);
  color: var(--stone-500);
}
.filter-chips a.active {
  background: var(--header);
  color: #fff;
  border-color: var(--header);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--header);
  color: #fff;
  padding: 0.55rem 1.1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--header-hover); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-block { width: 100%; justify-content: center; }
.btn-link {
  background: none;
  color: var(--teal);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0;
  text-decoration: none;
}
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--danger); }
.btn-secondary {
  background: #fff;
  border: 1px solid var(--stone-200);
  color: var(--stone-700);
}

/* ---------- Tables ---------- */
.table-wrap {
  background: #fff;
  border: 1px solid var(--stone-200);
  border-radius: 0.75rem;
  overflow: hidden;
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
thead tr {
  background: var(--stone-50);
  color: var(--stone-500);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
th, td {
  padding: 0.75rem 1rem;
  text-align: left;
}
th.right, td.right { text-align: right; }
tbody tr {
  border-top: 1px solid var(--stone-100);
}
tbody tr:hover { background: var(--stone-50); }
.sub { font-size: 0.75rem; color: var(--stone-400); margin-top: 0.15rem; }
.empty-row { text-align: center; padding: 2rem; color: var(--stone-400); }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 0.85rem; }
.field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--stone-500);
  margin-bottom: 0.3rem;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--stone-200);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--stone-800);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(47,93,98,0.2);
}
.hint { font-size: 0.75rem; color: var(--danger); margin: -0.4rem 0 0.75rem; }

/* ---------- Login page ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  background: #fff;
  border-radius: 1rem;
  box-shadow: 0 10px 40px rgba(31,59,58,0.1);
  padding: 2.25rem 2rem;
  width: 100%;
  max-width: 380px;
}
.login-card .logo-circle {
  width: 52px;
  height: 52px;
  background: var(--header);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  margin: 0 auto 1rem;
}
.login-card h1 {
  font-size: 1.05rem;
  text-align: center;
  margin: 0 0 0.2rem;
}
.login-card p.sub-text {
  text-align: center;
  font-size: 0.8rem;
  color: var(--stone-500);
  margin: 0 0 1.5rem;
}
.login-error {
  background: rgba(163,61,61,0.08);
  border: 1px solid rgba(163,61,61,0.25);
  color: var(--danger);
  font-size: 0.8rem;
  padding: 0.6rem 0.85rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
}

/* ---------- Progress bars ---------- */
.progress-track {
  height: 6px;
  background: var(--stone-100);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.35rem;
}
.progress-fill { height: 100%; border-radius: 999px; }

/* ---------- Modal (CSS-only via :target) ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}
.modal-overlay:target { display: flex; }
.modal-box {
  background: #fff;
  border-radius: 1rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-box.wide { max-width: 640px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--stone-100);
  position: sticky;
  top: 0;
  background: #fff;
}
.modal-head h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.modal-head a.close {
  color: var(--stone-400);
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.25rem;
}
.modal-body { padding: 1.25rem; }

.auth-denied {
  text-align: center;
  padding: 4rem 1rem;
}
.auth-denied h2 { color: var(--danger); }

.flash-message {
  background: rgba(47,111,78,0.08);
  border: 1px solid rgba(47,111,78,0.25);
  color: var(--ok);
  font-size: 0.85rem;
  padding: 0.65rem 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
}
.flash-message.error {
  background: rgba(163,61,61,0.08);
  border-color: rgba(163,61,61,0.25);
  color: var(--danger);
}

.text-muted { color: var(--stone-400); font-size: 0.875rem; }
.mt-6 { margin-top: 1.5rem; }
.consumable-grid {
  display: grid;
  gap: 0.75rem;
}
@media (min-width: 640px) { .consumable-grid { grid-template-columns: 1fr 1fr; } }
.consumable-card {
  background: #fff;
  border: 1px solid var(--stone-200);
  border-radius: 0.75rem;
  padding: 0.9rem;
}
.consumable-card .row {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
}

/* ---------- Barcode scan ---------- */
.scan-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #fff;
  border: 1px solid var(--stone-200);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: 1rem;
}
.scan-box svg { color: var(--teal); flex-shrink: 0; }
.scan-box input {
  border: none;
  padding: 0.15rem 0;
  font-size: 0.875rem;
}
.scan-box input:focus { outline: none; box-shadow: none; }
.scan-status {
  font-size: 0.75rem;
  color: var(--stone-500);
  min-width: 140px;
  text-align: right;
}
.scan-status-error { color: var(--danger) !important; }
.scan-input-error { border-color: var(--danger) !important; }
tr.row-highlight { background: rgba(217,164,65,0.18) !important; transition: background 0.3s; }
