/* =============================================================
   AOT Maintenance System — Main Stylesheet
   Font: Sarabun (Thai-friendly) + Clean Industrial UI
   ============================================================= */

/* ---------- CSS Variables ---------- */
:root {
  --sidebar-w: 260px;
  --sidebar-bg: #1e2330;
  --sidebar-hover: rgba(255,255,255,.08);
  --sidebar-active: rgba(99,179,237,.15);
  --sidebar-accent: #63b3ed;
  --brand-primary: #2b6cb0;
  --brand-secondary: #3182ce;
  --bg-app: #f0f4f8;
  --bg-card: #ffffff;
  --text-main: #2d3748;
  --text-muted: #718096;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,.07);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
  --status-wait: #e53e3e;
  --status-wip: #dd6b20;
  --status-parts: #d69e2e;
  --status-done: #38a169;
  --status-cancel: #718096;
  --transition: .2s ease;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: 'Sarabun', sans-serif;
  font-size: 15px;
  color: var(--text-main);
  background: var(--bg-app);
}

a { color: var(--brand-secondary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: transform var(--transition);
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 1.2rem 1.2rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-text {
  font-weight: 700;
  font-size: 1rem;
  color: #e2e8f0;
  white-space: nowrap;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: .9rem 1.2rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.user-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--sidebar-accent);
  color: var(--sidebar-bg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1rem;
  flex-shrink: 0;
}
.user-name  { color: #e2e8f0; font-weight: 600; font-size: .9rem; }
.user-meta  { color: #a0aec0; font-size: .75rem; }

.sidebar-nav { flex: 1; padding: .8rem .6rem; }
.nav-group-label {
  font-size: .7rem;
  font-weight: 700;
  color: #718096;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: .5rem .6rem .3rem;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: .6rem .8rem;
  border-radius: 8px;
  color: #cbd5e0;
  font-size: .9rem;
  transition: background var(--transition), color var(--transition);
  margin-bottom: 2px;
  text-decoration: none;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: var(--sidebar-accent); font-weight: 600; }
.nav-item i { font-size: 1rem; flex-shrink: 0; }

.sidebar-footer { padding: .8rem 1rem 1.2rem; margin-top: auto; }
.btn-logout {
  width: 100%;
  padding: .55rem;
  background: rgba(229,62,62,.15);
  border: 1px solid rgba(229,62,62,.3);
  border-radius: 8px;
  color: #fc8181;
  font-family: 'Sarabun', sans-serif;
  font-size: .9rem;
  cursor: pointer;
  transition: background var(--transition);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-logout:hover { background: rgba(229,62,62,.3); }

/* ---------- Sidebar Toggle (mobile) ---------- */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 1100;
  width: 40px; height: 40px;
  border-radius: 8px;
  border: none;
  background: var(--sidebar-bg);
  color: white;
  font-size: 1.3rem;
  cursor: pointer;
  align-items: center; justify-content: center;
}

/* ---------- Main Content ---------- */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  transition: margin var(--transition);
}
.content-wrapper {
  padding: 1.8rem 2rem;
  max-width: 1400px;
}

/* ---------- Page Header ---------- */
.page-header {
  margin-bottom: 1.5rem;
}
.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
}
.page-header .breadcrumb { margin: 0; font-size: .82rem; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-card);
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  padding: .9rem 1.2rem;
}

/* Metric Cards */
.metric-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
}
.metric-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.metric-card-header {
  padding: .65rem 1rem;
  font-size: .8rem;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: .05em;
  display: flex; justify-content: space-between; align-items: center;
}
.metric-card-body { padding: 1rem 1.2rem .9rem; }
.metric-value { font-size: 2rem; font-weight: 700; color: var(--text-main); line-height: 1; }
.metric-sub   { font-size: .78rem; color: var(--text-muted); margin-top: .25rem; }

/* ---------- Status Badges ---------- */
.badge-status {
  padding: .3em .7em;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-wait   { background: #fff5f5; color: var(--status-wait);   border: 1px solid #fed7d7; }
.badge-wip    { background: #fffaf0; color: var(--status-wip);    border: 1px solid #feebc8; }
.badge-parts  { background: #fffff0; color: var(--status-parts);  border: 1px solid #fefcbf; }
.badge-done   { background: #f0fff4; color: var(--status-done);   border: 1px solid #c6f6d5; }
.badge-cancel { background: #f7fafc; color: var(--status-cancel); border: 1px solid #e2e8f0; }

/* ---------- Tables ---------- */
.table thead th {
  background: #f7fafc;
  font-weight: 700;
  font-size: .82rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.table tbody tr:hover { background: #f7fafc; }
.table td { vertical-align: middle; font-size: .88rem; }

/* ---------- Forms ---------- */
.form-label { font-weight: 600; font-size: .85rem; color: var(--text-main); margin-bottom: .25rem; }
.form-control, .form-select {
  border-color: var(--border);
  border-radius: 8px;
  font-family: 'Sarabun', sans-serif;
  font-size: .9rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand-secondary);
  box-shadow: 0 0 0 3px rgba(49,130,206,.15);
}
.section-title {
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  border-bottom: 2px solid var(--border);
  padding-bottom: .4rem;
  margin-bottom: 1rem;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: 'Sarabun', sans-serif;
  font-weight: 600;
  border-radius: 8px;
  transition: all var(--transition);
}
.btn-primary   { background: var(--brand-primary); border-color: var(--brand-primary); }
.btn-primary:hover { background: var(--brand-secondary); border-color: var(--brand-secondary); transform: translateY(-1px); }

/* ---------- Alert / Toast ---------- */
.alert { border-radius: 10px; font-size: .9rem; }
.toast-container { z-index: 9999; }

/* ---------- Login Page ---------- */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e2330 0%, #2b3a5c 50%, #1a365d 100%);
  padding: 1rem;
}
.login-card {
  background: #fff;
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  padding: 2.5rem 2rem;
}
.login-logo { text-align: center; margin-bottom: 1.2rem; }
.login-logo img { height: 64px; }
.login-title { text-align: center; font-size: 1.3rem; font-weight: 700; color: var(--text-main); }
.login-sub   { text-align: center; font-size: .82rem; color: var(--text-muted); margin-bottom: 1.5rem; }
.tab-auth { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 1.5rem; }
.tab-auth-item {
  flex: 1;
  text-align: center;
  padding: .55rem;
  cursor: pointer;
  font-weight: 600;
  font-size: .88rem;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color var(--transition), border-color var(--transition);
}
.tab-auth-item.active { color: var(--brand-primary); border-color: var(--brand-primary); }

/* ---------- Tabs ---------- */
.nav-tabs .nav-link { font-weight: 600; color: var(--text-muted); border-radius: 8px 8px 0 0; }
.nav-tabs .nav-link.active { color: var(--brand-primary); border-bottom-color: transparent; }

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

/* ---------- Misc Helpers ---------- */
.btn-xs { padding: .15rem .45rem; font-size: .75rem; }
.font-monospace { font-family: 'Courier New', monospace; }

/* ---------- Responsive: Tablet (≤992px) ---------- */
@media (max-width: 992px) {
  .content-wrapper { padding: 1.2rem 1.4rem; }
  .metric-value { font-size: 1.6rem; }
}

/* ---------- Responsive: Mobile (≤768px) ---------- */
@media (max-width: 768px) {

  /* Sidebar: ซ่อน → เปิดด้วยปุ่ม */
  .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); box-shadow: none; }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.35);
  }
  .sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 999;
  }
  .sidebar-overlay.open { display: block; }

  .main-content { margin-left: 0; }
  .content-wrapper { padding: .75rem; }
  .sidebar-toggle { display: flex; }

  /* Page header ลดขนาด */
  .page-header h1 { font-size: 1.2rem; }

  /* Bootstrap grid: col-lg-* ใน mobile = full width */
  .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8 { width: 100% !important; }

  /* Card padding ลด */
  .card-body { padding: .85rem; }
  .card-header { padding: .7rem .9rem; }

  /* ตารางในมือถือ: scroll แนวนอน */
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Form: font ใหญ่ขึ้นนิดหน่อยสำหรับ touch */
  .form-control, .form-select {
    font-size: 1rem;
    min-height: 42px;
  }
  .form-control-sm, .form-select-sm { min-height: 36px; font-size: .9rem; }

  /* ปุ่ม full-width ในมือถือ */
  .btn-mobile-full { width: 100% !important; margin-bottom: .4rem; }

  /* Nav tabs: scroll แนวนอน */
  .nav-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 1px;
  }
  .nav-tabs .nav-link { white-space: nowrap; }

  /* Nav pills เช่นกัน */
  .nav-pills {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  /* Metric cards: 2 columns */
  .row.metric-row > [class*="col-"] { width: 50%; }

  /* Badge status: ไม่ตัดบรรทัด */
  .badge-status { white-space: nowrap; }

  /* Content wrapper padding top เพิ่มเพื่อหลีก hamburger */
  .content-wrapper { padding-top: 3.5rem; }

  /* Row gap ลด */
  .row.g-3 { --bs-gutter-x: .75rem; --bs-gutter-y: .75rem; }

  /* Modal/Alert full width */
  .alert { font-size: .88rem; }

  /* ซ่อน breadcrumb ในมือถือ */
  .page-header .breadcrumb { display: none; }

  /* calendar ใน shift.php */
  .cal-table th, .cal-table td { font-size: 10px !important; padding: 3px !important; min-height: 70px !important; height: 70px !important; }

  /* Topbar สำหรับ mobile: แสดงชื่อหน้า */
  .mobile-topbar {
    display: flex !important;
    align-items: center;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    background: var(--sidebar-bg);
    color: #e2e8f0;
    z-index: 998;
    padding: 0 1rem 0 3.5rem;
    font-weight: 600;
    font-size: 1rem;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
  }
}

/* Mobile topbar: ซ่อนบน desktop */
.mobile-topbar { display: none; }

/* =============================================================
   Choices.js — override ทุก state ให้ชัดเจน
   ============================================================= */

/* Container */
.choices { font-family: 'Sarabun', sans-serif; font-size: .9rem; margin-bottom: 0; }

/* Inner box (แทน input/select) */
.choices .choices__inner {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .3rem .5rem;
  min-height: 38px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 3px;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: 'Sarabun', sans-serif;
}
.choices .choices__inner:focus-within {
  border-color: #3182ce;
  box-shadow: 0 0 0 3px rgba(49,130,206,.15);
}

/* Search input ใน inner */
.choices .choices__input {
  font-family: 'Sarabun', sans-serif;
  font-size: .9rem;
  color: var(--text-main);
  background: transparent;
  border: none !important;
  box-shadow: none !important;
  margin: 0; padding: 2px 0;
  min-width: 80px;
}

/* Dropdown container */
.choices .choices__list--dropdown,
.choices .choices__list[aria-expanded] {
  border: 1px solid #cbd5e0;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
  z-index: 9999;
  font-family: 'Sarabun', sans-serif;
  background: #fff;
}

/* ทุก item ใน dropdown */
.choices .choices__list--dropdown .choices__item,
.choices .choices__list[aria-expanded] .choices__item {
  font-size: .9rem;
  padding: 8px 12px;
  color: #1a202c !important;
  background: #fff !important;
  cursor: pointer;
}

/* Hover */
.choices .choices__list--dropdown .choices__item--selectable.is-highlighted,
.choices .choices__list[aria-expanded] .choices__item--selectable.is-highlighted {
  background: #2b6cb0 !important;
  color: #fff !important;
}

/* Selected (ค่าที่เลือกอยู่) */
.choices .choices__list--dropdown .choices__item.is-selected,
.choices .choices__list[aria-expanded] .choices__item.is-selected {
  background: #ebf4ff !important;
  color: #1a365d !important;
  font-weight: 600;
}

/* Selected + Hover */
.choices .choices__list--dropdown .choices__item.is-selected.is-highlighted,
.choices .choices__list[aria-expanded] .choices__item.is-selected.is-highlighted {
  background: #2b6cb0 !important;
  color: #fff !important;
}

/* Disabled */
.choices .choices__list--dropdown .choices__item--disabled {
  color: #a0aec0 !important;
  background: #f7fafc !important;
  opacity: .7;
  cursor: not-allowed;
}

/* ช่อง search ใน dropdown */
.choices .choices__list--dropdown .choices__input {
  border: none !important;
  border-bottom: 1px solid #e2e8f0 !important;
  border-radius: 0;
  padding: 8px 12px;
  background: #f7fafc !important;
  font-size: .88rem;
  color: #1a202c;
  width: 100%;
}

/* Selected item pill (multiple) */
.choices .choices__list--multiple .choices__item {
  background: #2b6cb0;
  border: none;
  border-radius: 6px;
  font-size: .8rem;
  padding: 2px 8px;
  color: #fff;
}
.choices .choices__list--multiple .choices__item.is-highlighted {
  background: #2c5282;
}

/* Single value ที่แสดงใน inner */
.choices .choices__list--single { padding: 0; }
.choices .choices__list--single .choices__item {
  font-size: .9rem;
  color: #1a202c;
}

/* Placeholder */
.choices .choices__placeholder { opacity: .5; color: #718096; }

/* ปุ่ม X */
.choices .choices__button {
  border-left: 1px solid rgba(255,255,255,.4);
  opacity: .85;
  filter: invert(1);
}

/* sm variant */
.choices.is-sm .choices__inner { min-height: 32px; padding: .15rem .4rem; }
.choices.is-sm .choices__input { font-size: .82rem; }
.choices.is-sm .choices__list--dropdown .choices__item { font-size: .82rem; padding: 5px 10px; }
