:root {
  --primary: #1a3a5c;
  --primary-dark: #0f2540;
  --primary-light: #2e5c8a;
  --accent: #2980b9;
  --accent-light: #3498db;
  --secondary: #5d6d7e;
  --bg: #f0f3f7;
  --bg-card: #ffffff;
  --border: #d5dde6;
  --text: #2c3e50;
  --text-muted: #7f8c8d;
  --success: #27ae60;
  --warning: #f39c12;
  --danger: #e74c3c;
  --info: #2980b9;
  --sidebar-w: 260px;
  --header-h: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Sarabun', 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 15px; -webkit-text-size-adjust: 100%; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f0f3f7; }
::-webkit-scrollbar-thumb { background: #c0ccd8; border-radius: 3px; }

/* ===== LOGIN ===== */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%); padding: 16px; }
.login-box { background: white; border-radius: 12px; padding: 36px 32px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .icon { font-size: 48px; display: block; margin-bottom: 8px; }
.login-logo h1 { font-size: 18px; color: var(--primary); font-weight: 700; }
.login-logo p { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.login-box .form-group { margin-bottom: 16px; }
.login-box label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--secondary); }
.login-box input { width: 100%; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 15px; outline: none; transition: border 0.2s; font-family: inherit; }
.login-box input:focus { border-color: var(--accent); }
.btn-login { width: 100%; padding: 13px; background: var(--primary); color: white; border: none; border-radius: 8px; font-size: 16px; font-weight: 700; cursor: pointer; margin-top: 8px; transition: background 0.2s; font-family: inherit; }
.btn-login:hover { background: var(--primary-light); }
.login-error { background: #fdecea; border: 1px solid #f5c6cb; border-radius: 6px; padding: 10px 14px; color: var(--danger); font-size: 13px; margin-bottom: 14px; display: none; }

/* ===== LAYOUT ===== */
#app { display: flex; height: 100vh; overflow: hidden; position: relative; }

/* Sidebar overlay (mobile) */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200; }
.sidebar-overlay.show { display: block; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  color: white;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform 0.3s ease;
  z-index: 300;
}
.sidebar-header { padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-header .logo { font-size: 15px; font-weight: 700; line-height: 1.3; }
.sidebar-header .sub { font-size: 11px; opacity: 0.7; margin-top: 2px; }
.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-section { padding: 8px 16px 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; opacity: 0.5; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 12px 20px; cursor: pointer; transition: background 0.15s; font-size: 14px; border-left: 3px solid transparent; white-space: nowrap; }
.nav-item:hover { background: rgba(255,255,255,0.08); }
.nav-item.active { background: rgba(255,255,255,0.15); border-left-color: #5dade2; color: white; }
.nav-item .icon { font-size: 20px; width: 24px; text-align: center; flex-shrink: 0; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.1); }
.user-info { display: flex; align-items: center; gap: 10px; }
.user-avatar { width: 36px; height: 36px; background: rgba(255,255,255,0.2); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 700; flex-shrink: 0; }
.user-details .name { font-size: 13px; font-weight: 600; }
.user-details .role { font-size: 11px; opacity: 0.65; }

/* ===== MAIN ===== */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.topbar { height: var(--header-h); background: white; border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 16px; gap: 12px; flex-shrink: 0; }
.topbar-title { flex: 1; font-size: 16px; font-weight: 700; color: var(--primary); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { flex: 1; overflow-y: auto; padding: 20px; }

/* Hamburger button (hidden on desktop) */
.btn-hamburger { display: none; background: none; border: none; cursor: pointer; font-size: 22px; padding: 4px 6px; border-radius: 6px; line-height: 1; flex-shrink: 0; }
.btn-hamburger:hover { background: #f0f3f7; }

/* ===== NOTIFICATIONS ===== */
.notif-btn { position: relative; background: none; border: none; cursor: pointer; font-size: 22px; padding: 6px; flex-shrink: 0; }
.notif-badge { position: absolute; top: 0; right: 0; background: var(--danger); color: white; font-size: 10px; min-width: 18px; height: 18px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.notif-dropdown { position: fixed; right: 8px; top: calc(var(--header-h) + 4px); width: min(340px, calc(100vw - 16px)); background: white; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,0.15); z-index: 1000; display: none; }
.notif-dropdown.show { display: block; }
.notif-header { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.notif-header h3 { font-size: 14px; font-weight: 700; }
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item { padding: 12px 16px; border-bottom: 1px solid #f0f3f7; cursor: pointer; transition: background 0.15s; }
.notif-item:hover { background: #f8f9fa; }
.notif-item.unread { background: #eef4fc; }
.notif-item .ntitle { font-size: 13px; font-weight: 600; color: var(--text); }
.notif-item .nmsg { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.notif-item .ntime { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.notif-empty { text-align: center; padding: 24px; color: var(--text-muted); font-size: 13px; }

/* Logout label (hide text on small screens via class) */
.btn-logout-label { }

/* ===== CARDS ===== */
.card { background: white; border-radius: 10px; border: 1px solid var(--border); }
.card-header { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.card-header h3 { font-size: 15px; font-weight: 700; color: var(--primary); }
.card-body { padding: 16px; }

/* ===== STATS ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: white; border-radius: 10px; padding: 16px; border: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.stat-icon { width: 46px; height: 46px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; }
.stat-icon.blue { background: #dbeafe; }
.stat-icon.green { background: #d1fae5; }
.stat-icon.yellow { background: #fef3c7; }
.stat-icon.red { background: #fee2e2; }
.stat-icon.purple { background: #ede9fe; }
.stat-icon.teal { background: #ccfbf1; }
.stat-info .val { font-size: 24px; font-weight: 800; color: var(--text); line-height: 1; }
.stat-info .lbl { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===== TABLES ===== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 500px; }
th { background: #f0f3f7; padding: 10px 12px; text-align: left; font-size: 12px; font-weight: 700; color: var(--secondary); text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 2px solid var(--border); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid #f0f3f7; font-size: 14px; vertical-align: middle; }
tr:hover td { background: #fafbfc; }
tr:last-child td { border-bottom: none; }

/* ===== BADGES ===== */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-secondary { background: #f0f3f7; color: var(--secondary); }
.badge-purple { background: #ede9fe; color: #5b21b6; }

/* ===== BUTTONS ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 7px; font-size: 14px; font-weight: 600; cursor: pointer; border: none; transition: all 0.15s; font-family: inherit; white-space: nowrap; touch-action: manipulation; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-secondary { background: #f0f3f7; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #219a52; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c0392b; }
.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #d68910; }
.btn-icon { padding: 7px; background: none; border: none; cursor: pointer; font-size: 16px; border-radius: 6px; transition: background 0.15s; }
.btn-icon:hover { background: #f0f3f7; }

/* ===== FORMS ===== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-full { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--secondary); }
.form-control { padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 7px; font-size: 15px; outline: none; transition: border 0.2s; font-family: inherit; background: white; color: var(--text); width: 100%; }
.form-control:focus { border-color: var(--accent); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 8px; flex-wrap: wrap; }

/* ===== MODAL ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 500; display: none; align-items: flex-end; justify-content: center; }
.modal-overlay.show { display: flex; }
.modal { background: white; border-radius: 12px 12px 0 0; width: 100%; max-width: 640px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 -4px 30px rgba(0,0,0,0.2); }
.modal-lg { max-width: 840px; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.modal-header h2 { font-size: 16px; font-weight: 700; color: var(--primary); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; flex-shrink: 0; flex-wrap: wrap; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted); padding: 4px 8px; border-radius: 4px; }
.modal-close:hover { background: #f0f3f7; }

/* ===== SEARCH BAR ===== */
.search-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.search-input { flex: 1; min-width: 160px; padding: 10px 14px 10px 36px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 15px; outline: none; background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237f8c8d' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E") 10px center no-repeat; font-family: inherit; width: 100%; }
.search-input:focus { border-color: var(--accent); }

/* ===== CALENDAR ===== */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.cal-day-header { background: var(--primary); color: white; text-align: center; padding: 8px 4px; font-size: 12px; font-weight: 700; }
.cal-day { background: white; min-height: 80px; padding: 6px; cursor: pointer; transition: background 0.15s; }
.cal-day:hover { background: #f0f7ff; }
.cal-day.other-month { background: #f8f9fa; opacity: 0.6; }
.cal-day.today { background: #eef4fc; }
.cal-day.today .day-num { background: var(--primary); color: white; border-radius: 50%; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; }
.day-num { font-size: 12px; font-weight: 600; margin-bottom: 3px; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; }
.cal-event { background: var(--accent-light); color: white; border-radius: 3px; padding: 2px 4px; font-size: 10px; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.cal-event.meeting { background: var(--success); }
.cal-event.holiday { background: var(--danger); }

/* ===== TASK BOARD ===== */
.task-cols { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.task-col { background: #f0f3f7; border-radius: 10px; padding: 12px; }
.task-col-header { font-size: 13px; font-weight: 700; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.task-card { background: white; border-radius: 8px; padding: 12px; margin-bottom: 8px; border: 1px solid var(--border); cursor: pointer; transition: box-shadow 0.15s; }
.task-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.task-card .tc-title { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.task-card .tc-meta { font-size: 11px; color: var(--text-muted); display: flex; gap: 8px; flex-wrap: wrap; }
.priority-urgent { border-left: 3px solid var(--danger); }
.priority-high { border-left: 3px solid var(--warning); }
.priority-normal { border-left: 3px solid var(--accent); }
.priority-low { border-left: 3px solid var(--text-muted); }

/* ===== PROGRESS ===== */
.progress-bar { background: #e2e8f0; border-radius: 4px; height: 8px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
.progress-fill.green { background: var(--success); }
.progress-fill.blue { background: var(--accent); }
.progress-fill.orange { background: var(--warning); }

/* ===== TOAST ===== */
#toast-container { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; align-items: center; gap: 8px; width: calc(100vw - 32px); max-width: 400px; pointer-events: none; }
.toast { background: white; border-radius: 8px; padding: 12px 16px; width: 100%; box-shadow: 0 4px 20px rgba(0,0,0,0.18); display: flex; align-items: center; gap: 10px; border-left: 4px solid var(--accent); font-size: 14px; animation: slideUp 0.3s ease; pointer-events: auto; }
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.warning { border-color: var(--warning); }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Boss Parcel — blinking red badge */
@keyframes bpBlink { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
.bp-blink { animation: bpBlink 1.2s ease-in-out infinite; }

/* ===== MISC ===== */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.page-header h2 { font-size: 18px; font-weight: 800; color: var(--primary); }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }
.section-title { font-size: 15px; font-weight: 700; color: var(--primary); margin-bottom: 12px; padding-bottom: 8px; border-bottom: 2px solid var(--border); }
.tag { display: inline-flex; align-items: center; padding: 2px 8px; background: #e2e8f0; border-radius: 4px; font-size: 12px; color: var(--secondary); margin: 2px; }
.avatar { width: 32px; height: 32px; background: var(--primary); color: white; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; flex-shrink: 0; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.text-muted { color: var(--text-muted); font-size: 13px; }
.text-right { text-align: right; }
.fw-bold { font-weight: 700; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ========================================
   RESPONSIVE — Tablet (≤900px)
   ======================================== */
@media (max-width: 900px) {
  .task-cols { grid-template-columns: 1fr 1fr; }
  .form-grid-3 { grid-template-columns: 1fr 1fr; }
  .row-3 { grid-template-columns: 1fr 1fr; }
}

/* ========================================
   RESPONSIVE — Mobile (≤640px)
   Sidebar becomes off-canvas drawer
   ======================================== */
@media (max-width: 640px) {
  :root { --header-h: 52px; }

  /* Sidebar: hidden off-screen by default */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    width: 280px;
    z-index: 300;
  }
  .sidebar.open { transform: translateX(0); }

  /* Show hamburger, hide topbar logout label */
  .btn-hamburger { display: flex; align-items: center; justify-content: center; }
  .btn-logout-label { display: none; }

  /* Content padding smaller */
  .content { padding: 12px; }

  /* Modal: full-width bottom sheet */
  .modal { border-radius: 16px 16px 0 0; max-height: 95vh; }

  /* Forms: single column */
  .form-grid { grid-template-columns: 1fr; }
  .form-grid-3 { grid-template-columns: 1fr; }
  .form-full { grid-column: 1; }

  /* Grids: single column */
  .row-2 { grid-template-columns: 1fr; }
  .row-3 { grid-template-columns: 1fr; }
  .task-cols { grid-template-columns: 1fr; }

  /* Stats: 2 per row */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }

  /* Calendar: compact */
  .cal-day { min-height: 52px; padding: 4px; }
  .cal-day-header { padding: 6px 2px; font-size: 11px; }
  .day-num { font-size: 11px; width: 20px; height: 20px; }
  .cal-event { font-size: 9px; padding: 1px 3px; }

  /* Tables: allow horizontal scroll */
  .table-wrap { margin: 0 -12px; padding: 0 12px; }
  table { min-width: 480px; }
  td, th { padding: 8px 10px; font-size: 13px; }

  /* Buttons: larger tap targets */
  .btn { padding: 10px 14px; font-size: 14px; }
  .btn-sm { padding: 7px 12px; font-size: 13px; }

  /* Notification dropdown: full width minus margin */
  .notif-dropdown { right: 8px; left: 8px; width: auto; }

  /* Page header wrap */
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header h2 { font-size: 17px; }

  /* Form actions: full-width buttons on mobile */
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; justify-content: center; }

  /* Section title font */
  .section-title { font-size: 14px; }
}

/* ========================================
   RESPONSIVE — Very small (≤360px)
   ======================================== */
@media (max-width: 360px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { padding: 12px; }
  .stat-info .val { font-size: 20px; }
}
