/* =========================================================
   Project Registry — Main CSS
   ========================================================= */

/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@300;400;500;600;700&family=Inter:wght@300;400;500;600;700&display=swap');

/* ── CSS Custom Properties ──────────────────────────────── */
:root {
  /* ── Brand: เขียว (จากโลโก้) ── */
  --brand-50:  #eaf5ef;
  --brand-100: #cfe9db;
  --brand-200: #a7d6bd;
  --brand-400: #3fa073;
  --brand-500: #1b7a4f;   /* primary green */
  --brand-600: #146340;
  --brand-700: #0e4c31;

  /* ── Accent: น้ำตาล/taupe (จากตัวอักษรในโลโก้) ── */
  --brown-50:  #f3efe9;
  --brown-100: #e7ded1;
  --brown-400: #9a8674;
  --brown-500: #6f5b47;
  --brown-600: #5a4a39;

  --primary: #1b7a4f;
  --primary-dark: #146340;
  --primary-hover: #146340;
  --success: #16a34a;
  --warning: #cf8a2c;     /* amber อมน้ำตาล */
  --danger: #dc2626;
  --info: #0e7490;

  /* ── Sidebar: เขียวเข้มอมน้ำตาล ── */
  --sidebar-width: 240px;
  --sidebar-bg: #17241d;
  --sidebar-bg-2: #101b15;
  --sidebar-text: #9db3a5;
  --sidebar-hover: rgba(255,255,255,.06);
  --sidebar-active: #1b7a4f;
  --sidebar-active-bg: rgba(27,122,79,.18);
  --sidebar-active-text: #9fe3c0;
  --sidebar-section: #6d8375;
  --sidebar-border: rgba(255,255,255,.08);
  --topbar-height: 56px;
  --topbar-bg: #ffffff;
  --page-bg: #f3f5f2;

  /* ── Surfaces / text ── */
  --surface: #ffffff;
  --surface-2: #f6f7f4;
  --surface-3: #eef1ec;
  --border: #e4e8e2;
  --border-strong: #d3d9cf;
  --text: #23302a;
  --text-muted: #64726a;
  --text-soft: #94a397;
  --heading: #16231d;

  --font-sans: 'Inter', 'Noto Sans Thai', system-ui, sans-serif;
  --border-radius: 0.5rem;
  --radius-sm: 0.45rem;
  --radius-lg: 1rem;
  --shadow-xs: 0 1px 2px rgba(20,40,30,.06);
  --shadow-sm: 0 1px 3px rgba(20,40,30,.09);
  --shadow: 0 4px 14px rgba(20,40,30,.10);
  --shadow-lg: 0 12px 32px rgba(20,40,30,.16);
  --ring: 0 0 0 3px rgba(27,122,79,.20);
}

/* ── Dark theme (โทนเขียวเข้ม) ── */
:root[data-theme="dark"] {
  color-scheme: dark;
  --page-bg:      #0e1712;
  --surface:      #16241d;
  --surface-2:    #1b2c23;
  --surface-3:    #223529;
  --border:       #2a3d31;
  --border-strong:#354a3c;
  --text:         #e2ece6;
  --text-muted:   #9fb3a6;
  --text-soft:    #6d8375;
  --heading:      #f0f6f2;
  --brand-50:     rgba(27,122,79,.16);
  --brand-100:    rgba(27,122,79,.26);
  --shadow-xs: 0 1px 2px rgba(0,0,0,.4);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.5);
  --shadow:    0 6px 20px rgba(0,0,0,.5);
  --shadow-lg: 0 14px 36px rgba(0,0,0,.6);
}
:root[data-theme="dark"] body { background: var(--page-bg); color: var(--text); }

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

body {
  font-family: var(--font-sans);
  background: var(--page-bg);
  color: #1e293b;
  margin: 0;
  min-height: 100vh;
  font-size: 0.875rem;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  overflow-y: auto;
  overflow-x: hidden;
  transition: width .25s ease;
  z-index: 1030;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #1e293b;
  flex-shrink: 0;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  text-decoration: none;
  color: #f8fafc;
}

.brand-icon { font-size: 1.4rem; color: var(--primary); }
img.brand-icon { width: 30px; height: 30px; object-fit: contain; border-radius: 6px; }
.brand-text  { font-weight: 700; font-size: .95rem; letter-spacing: .3px; white-space: nowrap; }

/* Sidebar Nav */
.sidebar-nav {
  padding: .75rem 0;
  flex: 1;
}

.nav-section {
  padding: .5rem 1.25rem .25rem;
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #475569;
  margin-top: .5rem;
}

.sidebar-nav .nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem 1.25rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: .82rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all .15s ease;
  white-space: nowrap;
}

.sidebar-nav .nav-item i { font-size: 1rem; flex-shrink: 0; width: 18px; text-align: center; }

.sidebar-nav .nav-item:hover {
  background: var(--sidebar-hover);
  color: #f1f5f9;
}

.sidebar-nav .nav-item.active {
  background: rgba(27,122,79,.15);
  color: #9fe3c0;
  border-left-color: var(--primary);
}

/* ── Main Wrapper ────────────────────────────────────────── */
.main-wrapper {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left .25s ease;
}

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-height);
  background: var(--topbar-bg);
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 0 1.25rem;
  z-index: 1020;
  box-shadow: var(--shadow-sm);
}

.btn-toggle-sidebar {
  background: none; border: none; cursor: pointer;
  font-size: 1.25rem; color: #64748b; padding: .25rem;
  line-height: 1;
}
.btn-toggle-sidebar:hover { color: var(--primary); }

.topbar-search { flex: 1; max-width: 360px; }
.topbar-search .input-group-text { background: #f8fafc; border-color: #e2e8f0; }
.topbar-search .form-control { background: #f8fafc; border-color: #e2e8f0; font-size: .82rem; }
.topbar-search .form-control:focus { box-shadow: 0 0 0 3px rgba(27,122,79,.15); border-color: var(--primary); background: #fff; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .75rem; }

.btn-user {
  display: flex; align-items: center; gap: .5rem;
  background: none; border: 1px solid #e2e8f0;
  border-radius: var(--border-radius);
  padding: .35rem .75rem;
  cursor: pointer;
  transition: all .15s;
  text-align: left;
}
.btn-user:hover { background: #f8fafc; border-color: #cbd5e1; }

.user-avatar {
  width: 30px; height: 30px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: .8rem;
  flex-shrink: 0;
}

.user-name  { font-size: .82rem; font-weight: 600; line-height: 1.2; color: #1e293b; }
.user-role  { font-size: .7rem; color: #64748b; }

/* ── Page Content ────────────────────────────────────────── */
.page-content { flex: 1; padding: 1.5rem; }
.page-footer  { padding: .75rem 1.5rem; border-top: 1px solid #e2e8f0; background: #fff; }

/* ── Page Header ─────────────────────────────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.25rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-title  { font-size: 1.25rem; font-weight: 700; color: #0f172a; margin: 0; }
.page-subtitle { font-size: .82rem; color: #64748b; margin: .15rem 0 0; }
.page-actions { flex-shrink: 0; }

/* ── Cards ───────────────────────────────────────────────── */
.card { border: 1px solid #e2e8f0; border-radius: var(--border-radius); }
.card-header {
  background: #f8fafc; padding: .75rem 1rem;
  border-bottom: 1px solid #e2e8f0; font-weight: 600;
}
.card-title { font-size: .9rem; font-weight: 600; color: #1e293b; }

/* ── Stat Cards ──────────────────────────────────────────── */
.stat-card {
  border-radius: var(--border-radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  position: relative;
  overflow: hidden;
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.stat-card--primary { background: linear-gradient(135deg, #1f8a5a, #146340); color: #fff; }
.stat-card--info    { background: linear-gradient(135deg, #2f9e79, #0e6a4a); color: #fff; }
.stat-card--success { background: linear-gradient(135deg, #22c55e, #16a34a); color: #fff; }
.stat-card--warning { background: linear-gradient(135deg, #9a8674, #6f5b47); color: #fff; }  /* น้ำตาล/taupe */

.stat-icon  { font-size: 1.5rem; opacity: .85; }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .8rem; opacity: .85; font-weight: 500; }

/* ── Activity Icon ───────────────────────────────────────── */
.activity-icon {
  width: 28px; height: 28px; flex-shrink: 0;
  background: #f1f5f9; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--primary); font-size: .8rem;
}

/* ── Auth Pages ──────────────────────────────────────────── */
.auth-body {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
}
.auth-wrapper { width: 100%; padding: 1rem; }

.auth-card {
  background: #fff;
  border-radius: 1rem;
  padding: 2.5rem;
  max-width: 420px;
  margin: 0 auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.auth-logo { text-align: center; margin-bottom: 2rem; }
.auth-logo i { font-size: 2.5rem; color: var(--primary); display: block; margin-bottom: .5rem; }
/* uploaded logo image sizing (never render at natural size) */
.auth-logo img { width: 76px; height: 76px; object-fit: contain; display: block; margin: 0 auto .6rem; border-radius: 12px; }
.auth-title  { font-size: 1.4rem; font-weight: 800; color: #0f172a; margin: 0 0 .25rem; }
.auth-subtitle { font-size: .85rem; color: #64748b; margin: 0; }

.btn-login { padding: .65rem; font-weight: 600; border-radius: var(--border-radius); }

/* ── Tables ──────────────────────────────────────────────── */
.table th { font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .3px; color: #475569; }
.table td { vertical-align: middle; }
.table-hover tbody tr:hover { background-color: #f8fafc; }

/* ── Badges ──────────────────────────────────────────────── */
.badge { font-weight: 500; font-size: .72rem; }

/* ── Nav Tabs (สไตล์ pill ทันสมัย) ───────────────────────── */
.nav-tabs {
  border-bottom: none;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: .75rem;
  padding: .35rem;
  gap: .15rem;
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}

.nav-tabs .nav-link {
  font-size: .82rem;
  font-weight: 500;
  color: #64748b;
  border: none !important;
  border-radius: .5rem;
  padding: .45rem .85rem;
  background: transparent;
  transition: color .15s, background .15s;
  white-space: nowrap;
}

.nav-tabs .nav-link:hover,
.nav-tabs .nav-link:focus {
  color: var(--primary);
  background: #eaf5ef;
  outline: none;
  box-shadow: none;
}

.nav-tabs .nav-link.active {
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  box-shadow: 0 2px 6px rgba(27,122,79,.35);
}

.nav-tabs .nav-link i { margin-right: .3rem; }

/* ── Required Label ──────────────────────────────────────── */
.form-label.required::after {
  content: ' *'; color: var(--danger); font-weight: 700;
}

/* ── Toast Notifications ─────────────────────────────────── */
.toast-stack {
  position: fixed;
  top: calc(var(--topbar-height) + 12px);
  right: 16px;
  z-index: 1080;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.auth-body .toast-stack { top: 16px; }

.app-toast {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .85rem 1rem .95rem;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: .75rem;
  box-shadow: 0 10px 30px rgba(15,23,42,.12), 0 2px 6px rgba(15,23,42,.06);
  overflow: hidden;
  pointer-events: auto;
  animation: toast-in .35s cubic-bezier(.21,1.02,.73,1) both;
}

.app-toast.is-hiding {
  animation: toast-out .3s ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(24px) scale(.97); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); max-height: 200px; }
  to   { opacity: 0; transform: translateX(24px); max-height: 0; margin-top: -0.6rem; padding-top: 0; padding-bottom: 0; }
}

.app-toast__icon {
  width: 34px; height: 34px; flex-shrink: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
}

.app-toast__body  { flex: 1; min-width: 0; }
.app-toast__title { font-weight: 700; font-size: .82rem; color: #0f172a; line-height: 1.3; }
.app-toast__msg   { font-size: .8rem; color: #475569; margin-top: .1rem; word-wrap: break-word; }

.app-toast__close {
  background: none; border: none; cursor: pointer;
  color: #94a3b8; font-size: .75rem;
  padding: .2rem .3rem; margin: -.2rem -.3rem 0 0;
  border-radius: .35rem;
  transition: color .15s, background .15s;
  flex-shrink: 0;
}
.app-toast__close:hover { color: #334155; background: #f1f5f9; }

.app-toast__progress {
  position: absolute;
  left: 0; bottom: 0;
  height: 3px;
  width: 100%;
  transform-origin: left;
  animation: toast-progress linear forwards;
}

@keyframes toast-progress {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

.app-toast:hover .app-toast__progress { animation-play-state: paused; }

.app-toast--success .app-toast__icon     { background: #dcfce7; color: #16a34a; }
.app-toast--success .app-toast__progress { background: var(--success); }
.app-toast--error   .app-toast__icon     { background: #fee2e2; color: #dc2626; }
.app-toast--error   .app-toast__progress { background: var(--danger); }
.app-toast--warning .app-toast__icon     { background: #fef3c7; color: #d97706; }
.app-toast--warning .app-toast__progress { background: var(--warning); }
.app-toast--info    .app-toast__icon     { background: #cffafe; color: #0891b2; }
.app-toast--info    .app-toast__progress { background: var(--info); }

/* ── Inline Alerts (form validation ฯลฯ) ─────────────────── */
.alert {
  border: none;
  border-left: 4px solid;
  border-radius: .6rem;
  font-size: .82rem;
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  box-shadow: 0 1px 3px rgba(15,23,42,.06);
}
.alert::before {
  font-family: 'bootstrap-icons';
  font-size: 1rem;
  line-height: 1.3;
}
.alert-danger  { background: #fef2f2; border-left-color: var(--danger);  color: #991b1b; }
.alert-danger::before  { content: '\f622'; color: var(--danger); }   /* x-circle-fill */
.alert-success { background: #f0fdf4; border-left-color: var(--success); color: #166534; }
.alert-success::before { content: '\f26a'; color: var(--success); }  /* check-circle-fill */
.alert-warning { background: #fffbeb; border-left-color: var(--warning); color: #92400e; }
.alert-warning::before { content: '\f33a'; color: var(--warning); }  /* exclamation-triangle-fill */
.alert-info    { background: #ecfeff; border-left-color: var(--info);    color: #155e75; }
.alert-info::before    { content: '\f431'; color: var(--info); }     /* info-circle-fill */

/* ── UI Polish (ทั้งระบบ) ────────────────────────────────── */

/* Buttons */
.btn {
  border-radius: .5rem;
  font-weight: 500;
  transition: all .15s ease;
}
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 1px 3px rgba(27,122,79,.3);
}
.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(27,122,79,.35);
}
.btn:active { transform: translateY(0); }
.btn-outline-primary:hover, .btn-outline-danger:hover, .btn-outline-secondary:hover {
  transform: translateY(-1px);
}

/* Cards */
.card {
  border-radius: .75rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s ease;
}
.card.shadow-sm:hover { box-shadow: 0 4px 14px rgba(15,23,42,.09) !important; }
.card-header {
  border-radius: .75rem .75rem 0 0 !important;
  font-size: .85rem;
}

/* Forms */
/* native date picker calendar icon — keep visible in dark mode */
:root[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1) opacity(.75); }
.form-control, .form-select {
  border-radius: .5rem;
  border-color: #e2e8f0;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(27,122,79,.15);
}
.form-label { font-weight: 500; font-size: .8rem; color: #334155; margin-bottom: .3rem; }
.form-text  { font-size: .72rem; }

/* Native date picker */
input[type="date"].form-control { cursor: pointer; }
input[type="date"].form-control::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: .55;
  transition: opacity .15s;
}
input[type="date"].form-control:hover::-webkit-calendar-picker-indicator { opacity: 1; }

/* Modals */
.modal-content {
  border: none;
  border-radius: .9rem;
  box-shadow: 0 25px 60px rgba(15,23,42,.25);
}
.modal-header {
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  border-radius: .9rem .9rem 0 0;
  padding: .9rem 1.25rem;
}
.modal-title { font-size: .95rem; font-weight: 700; color: #0f172a; }
.modal-footer { border-top: 1px solid #f1f5f9; }

/* Dropdowns */
.dropdown-menu {
  border: 1px solid #e2e8f0;
  border-radius: .6rem;
  box-shadow: 0 10px 30px rgba(15,23,42,.12);
  font-size: .82rem;
  padding: .4rem;
}
.dropdown-item { border-radius: .4rem; padding: .45rem .75rem; }
.dropdown-item:hover { background: #f1f5f9; }

/* Tables */
.table thead th {
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}
.table > :not(caption) > * > * { padding: .65rem .75rem; }

/* Badges */
.badge { border-radius: 2rem; padding: .35em .7em; letter-spacing: .2px; }

/* Empty states (ยังไม่มีข้อมูล) */
.text-center.text-muted.py-4 {
  padding: 2.5rem 1rem !important;
  color: #94a3b8 !important;
  font-size: .85rem;
}
.text-center.text-muted.py-4 > i.fs-3 {
  width: 56px; height: 56px;
  line-height: 56px;
  margin: 0 auto .6rem !important;
  background: #f1f5f9;
  border-radius: 50%;
  color: #94a3b8;
  opacity: 1 !important;
  font-size: 1.4rem !important;
}

/* Pagination */
.pagination { gap: .25rem; }
.pagination .page-link {
  border-radius: .45rem;
  border-color: #e2e8f0;
  color: #475569;
  font-size: .8rem;
  transition: all .15s;
}
.pagination .page-link:hover { background: #eaf5ef; color: var(--primary); border-color: #a7d6bd; }
.pagination .page-item.active .page-link {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 2px 6px rgba(27,122,79,.35);
}

/* Breadcrumb-ish links */
a { transition: color .15s; }

/* ── Help Page (คู่มือการใช้งาน) ─────────────────────────── */
.help-step-icon {
  width: 52px; height: 52px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.35rem;
}

.accordion-button {
  font-size: .85rem;
  font-weight: 600;
  color: #334155;
  padding: .85rem 1.1rem;
}
.accordion-button:not(.collapsed) {
  background: #eaf5ef;
  color: var(--primary);
  box-shadow: none;
}
.accordion-button:focus { box-shadow: none; border-color: #e2e8f0; }
.accordion-body { color: #475569; }

.help-field-table th { background: #f8fafc; font-size: .72rem; text-transform: uppercase; letter-spacing: .3px; color: #64748b; }
.help-field-table td { padding: .55rem .9rem; }
.help-field-table td:first-child { font-weight: 600; color: #334155; }
.help-field-table code { font-size: .72rem; }

/* ── Access Management ───────────────────────────────────── */
.table-row-muted td { opacity: .6; }
.table-row-muted:hover td { opacity: 1; }

/* ── Responsive Sidebar ──────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
}
