/* ============================================================
   ระบบขออนุญาตใช้รถยนต์ส่วนกลาง - องค์การบริหารส่วนตำบลบ้านเจียง
   Theme: ฟ้าน้ำเงินองค์กร ผสมทองอ่อน-ขาว (ทางการแต่เข้าถึงง่าย)
   Colors: Sky Corporate Blue (#0b6cd4), Aqua (#4aa8ff), Soft Gold (#c7a23a), White
   ============================================================ */

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

:root {
  --primary: #0b6cd4;          /* ฟ้าน้ำเงินองค์กรภาครัฐ */
  --primary-hover: #0855ab;
  --primary-light: #e8f2fd;
  --sky-blue: #4aa8ff;         /* ฟ้าสดใส */
  --accent-gold: #c7a23a;      /* ทองอ่อนองค์กร */
  --accent-gold-hover: #a8882c;
  --accent-light: #fdf6e2;
  --bg-gradient: linear-gradient(135deg, #f4f8fd 0%, #e9f2fc 100%);
  --card-bg: #ffffff;
  --text-main: #17233d;
  --text-muted: #5b6b83;
  --border-color: #dae6f3;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  
  --sidebar-w: 270px;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  
  --shadow-sm: 0 1px 3px rgba(11,108,212,0.06);
  --shadow-md: 0 4px 14px rgba(11,108,212,0.10);
  --shadow-lg: 0 12px 30px rgba(11,108,212,0.16);
}

html, body { height: 100%; }

body {
  font-family: 'Sarabun', 'Leelawadee UI', 'Tahoma', 'Segoe UI', sans-serif;
  background: var(--bg-gradient);
  color: var(--text-main);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

img { max-width: 100%; height: auto; display: block; }

/* ============ Typography & Base Elements ============ */
h1, h2, h3, h4 { color: var(--primary); font-weight: 700; }
a { color: var(--sky-blue); text-decoration: none; }

/* ============ Buttons (Touch-Friendly) ============ */
.btn {
  padding: 11px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px; /* Touch target standard */
  user-select: none;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--sky-blue));
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(11, 61, 145, 0.25);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-hover), var(--primary));
  box-shadow: 0 6px 16px rgba(11, 61, 145, 0.35);
}

.btn-gold {
  background: linear-gradient(135deg, var(--accent-gold), #d4b338);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(201, 162, 39, 0.25);
}
.btn-gold:hover {
  background: linear-gradient(135deg, var(--accent-gold-hover), var(--accent-gold));
}

.btn-secondary {
  background: #ffffff;
  color: var(--text-main);
  border: 1.5px solid var(--border-color);
}
.btn-secondary:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.btn-danger {
  background: var(--danger-light);
  color: var(--danger);
  border: 1.5px solid #fca5a5;
}
.btn-danger:hover { background: #fee2e2; }

.btn-success {
  background: var(--success-light);
  color: #047857;
  border: 1.5px solid #a7f3d0;
}
.btn-success:hover { background: #d1fae5; }

.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 34px; border-radius: var(--radius-sm); }

/* ============ Auth (Login / Register Card) ============ */
.auth-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(circle at 15% 15%, rgba(199,162,58,0.20), transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(74,168,255,0.20), transparent 40%),
    linear-gradient(145deg, #0a5fbd 0%, #0b6cd4 50%, #4aa8ff 100%);
}

.auth-card {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 36px 32px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.2);
  animation: fadeIn 0.4s ease-out;
}

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

.brand { text-align: center; margin-bottom: 24px; }
.brand-logo {
  width: 90px;
  height: 90px;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 3px solid var(--accent-gold);
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 6px 18px rgba(0,0,0,0.15);
  padding: 4px;
}
.brand-logo img { display: none; width: 100%; height: 100%; object-fit: contain; }
.brand-logo img.has-img { display: block; }
.brand-text {
  display: none;
  font-size: 24px;
  font-weight: 800;
  color: var(--primary);
  text-align: center;
  line-height: 1.2;
  padding: 4px;
}
.brand-text.has-text { display: block; }

.brand-name {
  font-size: 20px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.35;
  letter-spacing: -0.2px;
}
.brand-title {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 6px;
  font-weight: 500;
}

.auth-tabs {
  display: flex;
  background: #f1f5f9;
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 22px;
}
.auth-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  font-family: inherit;
  transition: all 0.2s;
}
.auth-tab.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(11,108,212,0.18);
}

.auth-pane { display: none; }
.auth-pane.active { display: block; }

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin: 14px 0 6px;
  color: var(--text-main);
}
.auth-pane input, .auth-pane select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border-color);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  background: #ffffff;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.auth-pane input:focus, .auth-pane select:focus {
  outline: none;
  border-color: var(--sky-blue);
  box-shadow: 0 0 0 3.5px rgba(74,168,255,0.18);
}

/* ============ Alerts ============ */
.alert { padding: 12px 16px; border-radius: 10px; font-size: 14px; margin-top: 14px; line-height: 1.5; }
.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid #fca5a5; }
.alert-success { background: var(--success-light); color: #047857; border: 1px solid #6ee7b7; }
.alert-info { background: var(--primary-light); color: var(--primary); border: 1px solid #bfdbfe; }
  .alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fcd34d; white-space: pre-line; }

/* ============ Layout: Sidebar & Main Area ============ */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #0855ab 0%, #0b6cd4 60%, #0958b0 100%);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 50;
  box-shadow: 4px 0 20px rgba(0,0,0,0.18);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-brand {
  padding: 24px 18px 20px;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.1);
}
.sidebar-logo {
  width: 70px;
  height: 70px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2.5px solid var(--accent-gold);
  padding: 3px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.sidebar-logo img { display: none; width: 100%; height: 100%; object-fit: contain; }
.sidebar-logo img.has-img { display: block; }
.sidebar-logo .brand-text { font-size: 15px; color: #0b6cd4; line-height: 1.25; }
.sidebar-org { font-size: 14px; font-weight: 700; line-height: 1.35; color: #ffffff; letter-spacing: 0.2px; }

.sidebar-user {
  padding: 16px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
}
.sidebar-user-name { font-size: 15px; font-weight: 700; color: #ffffff; }
.sidebar-user-role { font-size: 12px; color: var(--accent-gold); font-weight: 600; margin-top: 3px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 10px;
  color: rgba(255,255,255,0.85);
  font-size: 15px;
  margin-bottom: 4px;
  transition: all 0.2s;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  font-family: inherit;
  text-align: left;
  font-weight: 500;
}
.nav-item:hover { background: rgba(255,255,255,0.12); color: #ffffff; }
.nav-item.active {
  background: linear-gradient(135deg, var(--accent-gold), #d4b338);
  color: #0b6cd4;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,0.12); }
.btn-logout {
  width: 100%;
  padding: 11px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.06);
  color: #ffffff;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: background 0.2s;
}
.btn-logout:hover { background: rgba(239,68,68,0.3); border-color: rgba(239,68,68,0.5); }

/* ============ Main Content Area ============ */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 28px;
  min-width: 0; /* Prevents flex items overflow */
}
.page { max-width: 1060px; margin: 0 auto; }
.page h2 { font-size: 24px; margin-bottom: 6px; color: var(--primary); letter-spacing: -0.3px; }
.page h3 { font-size: 17px; margin: 26px 0 14px; color: var(--text-main); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.page-sub { color: var(--text-muted); font-size: 14px; font-weight: 500; }

.topbar-mobile { display: none; }

/* ============ Dashboard Stat Cards ============ */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-top: 16px; }
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  text-align: center;
  border-top: 5px solid var(--accent-gold);
  transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-card .num { font-size: 34px; font-weight: 800; color: var(--primary); line-height: 1.1; }
.stat-card .lbl { font-size: 14px; color: var(--text-muted); margin-top: 6px; font-weight: 500; }

/* ============ Panels & Data Tables ============ */
.panel {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  margin-bottom: 22px;
}
.panel-title { font-size: 17px; font-weight: 700; color: var(--primary); margin-bottom: 14px; border-bottom: 2px solid var(--primary-light); padding-bottom: 8px; }

.table-wrap {
  overflow-x: auto;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  -webkit-overflow-scrolling: touch;
}

.data-table { width: 100%; border-collapse: collapse; min-width: 680px; }
.data-table thead th {
  background: #f8fafc;
  text-align: left;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 700;
  padding: 13px 14px;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}
.data-table tbody td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border-color);
  font-size: 14.5px;
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f1f5f9; }
.empty-msg { text-align: center; color: var(--text-muted); padding: 36px; font-size: 15px; }

.tag { display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.tag.available { background: var(--success-light); color: #047857; }
.tag.maintenance { background: var(--warning-light); color: #b45309; }
.tag.retired { background: var(--danger-light); color: var(--danger); }
.tag.admin { background: var(--primary); color: #ffffff; }
.tag.executive { background: var(--accent-gold); color: #0b6cd4; }
.tag.user { background: #f1f5f9; color: #475569; }
.tag.pending { background: var(--warning-light); color: #b45309; }
.tag.approved { background: var(--success-light); color: #047857; }
.tag.rejected { background: var(--danger-light); color: var(--danger); }

.user-actions { display: flex; gap: 6px; flex-wrap: wrap; min-width: 240px; }

/* ============ Forms & Input Grids ============ */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.field label { display: block; font-size: 13.5px; font-weight: 700; margin-bottom: 6px; color: var(--text-main); }
.field label .opt-mark { font-size: 11px; font-weight: 600; color: var(--text-muted); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 15px;
  font-family: inherit;
  background: #ffffff;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--sky-blue);
  box-shadow: 0 0 0 3.5px rgba(74,168,255,0.18);
}
.field input[readonly] { background: #f8fafc; color: var(--text-muted); font-weight: 700; }

.forgot-link { display: inline-block; margin-top: 12px; color: var(--sky-blue); font-size: 13.5px; font-weight: 600; text-decoration: none; }
  .forgot-link:hover { text-decoration: underline; }
.logo-upload-preview {
  width: 130px; height: 130px; border: 2px dashed var(--border-color); border-radius: var(--radius-md);
  background: #f8fafc; display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0;
}
.logo-upload-preview img { width: 100%; height: 100%; object-fit: contain; display: none; }
.logo-upload-preview img.has-img { display: block; }
.logo-upload-controls { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.logo-upload-hint { font-size: 13px; color: var(--text-muted); line-height: 1.5; max-width: 340px; }
.field-full { grid-column: 1 / -1; }
.form-actions { margin-top: 24px; display: flex; gap: 12px; flex-wrap: wrap; }

.user-banner {
  background: linear-gradient(135deg, #eef4ff 0%, #f5f8ff 100%);
  border: 1.5px solid #c7d2fe;
  border-left: 6px solid var(--primary);
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 20px;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-banner strong { color: var(--primary); }

.edit-banner {
  background: #fffbeb;
  border: 1.5px solid #fcd34d;
  border-left: 6px solid #d97706;
  border-radius: 12px;
  padding: 12px 18px;
  margin-bottom: 20px;
  font-size: 14.5px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Filter bar */
.filter-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.filter-input { padding: 10px 12px; border: 1.5px solid var(--border-color); border-radius: var(--radius-md); font-size: 14.5px; font-family: inherit; }

/* Inline forms (Admin) */
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.inline-form input, .inline-form select {
  padding: 11px 12px;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 14.5px;
  font-family: inherit;
  flex: 1 1 160px;
  background: #ffffff;
}

/* ============ Approval List Items ============ */
.approve-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  margin-bottom: 12px;
  background: #ffffff;
  box-shadow: var(--shadow-sm);
}
.approve-info .name { font-size: 16px; font-weight: 700; color: var(--primary); }
.approve-info .meta { font-size: 13.5px; color: var(--text-muted); margin-top: 3px; }
.approve-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ============ Toast Notifications ============ */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  background: #0f172a;
  color: #ffffff;
  padding: 14px 26px;
  border-radius: 12px;
  font-size: 14.5px;
  font-weight: 600;
  z-index: 250;
  opacity: 0;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 10px 35px rgba(0,0,0,0.3);
  max-width: 90vw;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.success { background: #059669; }
.toast.error { background: var(--danger); }

/* ============ Fully Responsive Breakpoints (Mobile-First) ============ */
@media (max-width: 960px) {
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
  }
  .sidebar.open { transform: translateX(0); }
  
  .main {
    margin-left: 0;
    padding: 16px;
    padding-top: 10px;
  }
  
  /* Mobile Topbar */
  .topbar-mobile {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    background: linear-gradient(135deg, #0a5fbd, #0b6cd4);
    color: #ffffff;
    position: sticky;
    top: 0;
    z-index: 40;
    margin: -16px -16px 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  }
  
  .topbar-mobile-brand {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .topbar-logo-wrap {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #ffffff;
    padding: 2px;
    border: 1.5px solid var(--accent-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }
  .topbar-logo-wrap img { display: none; width: 100%; height: 100%; object-fit: contain; }
  .topbar-logo-wrap img.has-img { display: block; }
  .topbar-logo-wrap .brand-text { font-size: 11px; color: #0b6cd4; padding: 1px; line-height: 1.15; }
  
  .topbar-mobile-text { text-align: left; }
  .topbar-mobile-org { font-size: 13px; font-weight: 800; color: var(--accent-gold); line-height: 1.2; }
  .topbar-mobile-title { font-size: 12px; opacity: 0.9; }

  .icon-btn {
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.2);
    color: #ffffff;
    font-size: 22px;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }
  .icon-btn:active { background: rgba(255,255,255,0.25); }

  /* Backdrop Overlay for Mobile Sidebar */
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(3px);
    z-index: 45;
    display: none;
    animation: fadeIn 0.2s ease-out;
  }
  .sidebar-backdrop.show { display: block; }

  .stat-cards { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .field-full { grid-column: auto; }
  .approve-item { flex-direction: column; align-items: stretch; }
  .approve-actions { width: 100%; justify-content: flex-start; }
  .approve-actions .btn { flex: 1; }
}

@media (max-width: 520px) {
  .auth-card { padding: 26px 20px; border-radius: 16px; }
  .brand-logo { width: 78px; height: 78px; }
  .brand-name { font-size: 18px; }
  
  .stat-cards { grid-template-columns: 1fr; }
  .page h2 { font-size: 20px; }
  .panel { padding: 18px 14px; border-radius: 14px; }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; }
  
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .filter-input { width: 100%; }
  .filter-bar .btn { width: 100%; }
}

