@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;500;600;700&display=swap');

:root {
  /* macOS-inspired light design system */
  --color-forest-900: #183153;
  --color-forest-700: #315C86;
  --color-forest-500: #2D7FD3;
  --color-ocean-700: #1669C9;
  --color-ocean-500: #2B86E5;
  --color-teal-500: #19A9A6;
  --color-teal-100: #E4F7F5;
  --color-ochre-500: #C58C3A;
  --color-ochre-600: #996821;
  --color-bg: #F2F5F8;
  --color-surface: rgba(255, 255, 255, 0.86);
  --color-border: rgba(72, 91, 112, 0.16);
  --color-text: #1C2A39;
  --color-text-muted: #6B7C8E;
  --color-danger: #B84D55;
  --color-danger-bg: #FDEDEF;
  --color-success: #187E6B;

  --radius-sm: 8px;
  --radius-md: 11px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --shadow-card: 0 1px 2px rgba(28, 44, 61, 0.04), 0 16px 42px rgba(48, 73, 101, 0.10);
  --shadow-float: 0 24px 70px rgba(27, 44, 64, 0.22);
  --control-height: 40px;
  --font-body: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Thonburi", "Noto Sans Thai", "Sarabun", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html {
  color-scheme: light;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(circle at 12% 10%, rgba(116, 192, 255, 0.20), transparent 28%),
    radial-gradient(circle at 88% 8%, rgba(167, 218, 235, 0.18), transparent 24%),
    linear-gradient(145deg, #EAF2FA 0%, #F5F8FC 50%, #EAF1F8 100%);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
}

h1, h2, h3 { font-weight: 600; margin: 0 0 8px; color: var(--color-forest-900); }

a { color: var(--color-forest-500); }

/* ---------- หน้าจอศูนย์กลาง (login/register/pending) ---------- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(24px) saturate(145%);
  padding: 36px 32px;
}

.auth-mark {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  overflow: hidden;
  box-shadow: 0 6px 16px rgba(15, 16, 68, 0.15);
}

.auth-mark img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.auth-mark svg { width: 24px; height: 24px; }

.auth-card h1 {
  font-size: 20px;
  margin-bottom: 4px;
}

.auth-subtitle {
  color: var(--color-text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--color-forest-900);
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 15px;
  background: #FAFCFE;
  color: var(--color-text);
}

.field input:focus {
  outline: none;
  border-color: var(--color-forest-500);
  box-shadow: 0 0 0 3px rgba(35, 134, 182, 0.14);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 11px 16px;
  border-radius: var(--radius-md);
  border: none;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary { background:linear-gradient(180deg,#3695ED,#1671D7); color:#fff; border:1px solid rgba(13,91,170,.32); box-shadow:0 5px 14px rgba(22,105,201,.18), inset 0 1px rgba(255,255,255,.22); }
.btn-primary:hover { background:linear-gradient(180deg,#2C8BE4,#1065C4); transform:translateY(-1px); box-shadow:0 7px 18px rgba(22,105,201,.24); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-ghost {
  background: rgba(255,255,255,.72);
  color: var(--color-forest-700);
  border: 1px solid var(--color-border);
}
.btn-ghost:hover { background:#fff; border-color:rgba(69,126,181,.35); box-shadow:0 5px 14px rgba(44,84,126,.08); }

.auth-footer {
  margin-top: 20px;
  font-size: 14px;
  text-align: center;
  color: var(--color-text-muted);
}

.error-box {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  font-size: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  display: none;
}

.error-box.visible { display: block; }

/* ---------- แอปหลัก (dashboard) ---------- */
.app-shell { min-height: 100vh; }

.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: rgba(255,255,255,.72);
  border-bottom: 1px solid var(--color-border);
  backdrop-filter: blur(22px) saturate(150%);
}

.app-topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: var(--color-forest-900);
}

.app-topbar .brand-mark {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--color-border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-topbar .brand-mark img { width: 100%; height: 100%; object-fit: contain; padding: 2px; }

.app-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--color-text-muted);
}

.role-chip {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(22, 166, 178, 0.12);
  color: var(--color-forest-700);
}

.app-main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 24px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.module-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 8px 24px rgba(62, 97, 134, .05);
  backdrop-filter: blur(16px);
}

.module-card h3 { font-size: 16px; margin-bottom: 6px; }
.module-card p { font-size: 14px; color: var(--color-text-muted); margin: 0; }
.module-card .soon {
  display: inline-block;
  margin-top: 10px;
  font-size: 12px;
  color: var(--color-ochre-600);
  font-weight: 600;
}

/* ---------- ตารางแอดมิน ---------- */
.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow:0 12px 34px rgba(57,91,128,.07);
  backdrop-filter:blur(18px) saturate(135%);
}

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--color-border); }
th { color:var(--color-forest-900); background:rgba(237,243,249,.82); font-weight:600; font-size:13px; letter-spacing:.01em; }
tbody tr { transition:background .15s ease; }
tbody tr:hover { background:rgba(227,241,252,.58); }
tr:last-child td { border-bottom: none; }

select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  font-family: var(--font-body);
  background: rgba(255,255,255,.68);
  color:var(--color-text);
}

input, textarea {
  border:1px solid var(--color-border);
  border-radius:10px;
  background:rgba(255,255,255,.68);
  color:var(--color-text);
  font:inherit;
  padding:9px 11px;
  transition:border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

input:focus, textarea:focus, select:focus {
  outline:none;
  border-color:#7EB6D3;
  background:#fff;
  box-shadow:0 0 0 3px rgba(35,134,182,.12);
}

/* ---------- ปุ่มเลือกไฟล์กลางของระบบ ---------- */
input[type="file"] {
  width: 100%;
  min-height: 48px;
  padding: 5px;
  border: 1px solid rgba(112, 150, 184, .30);
  border-radius: 12px;
  background: rgba(248, 252, 255, .90);
  color: var(--color-text-muted);
  font-size: 13px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.9), 0 4px 14px rgba(56, 96, 136, .05);
}

input[type="file"][hidden] { display: none; }

input[type="file"]::file-selector-button,
input[type="file"]::-webkit-file-upload-button {
  min-height: 36px;
  margin: 0 11px 0 0;
  padding: 7px 14px;
  border: 1px solid rgba(69, 132, 184, .24);
  border-radius: 9px;
  background: linear-gradient(180deg, #f8fcff 0%, #e6f2fb 100%);
  color: #1d5d8b;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 7px rgba(41, 104, 153, .10), inset 0 1px 0 #fff;
  transition: background .16s ease, border-color .16s ease, color .16s ease, transform .16s ease, box-shadow .16s ease;
}

input[type="file"]:hover::file-selector-button,
input[type="file"]:hover::-webkit-file-upload-button {
  border-color: rgba(43, 134, 229, .44);
  background: linear-gradient(180deg, #edf8ff 0%, #d7ecfa 100%);
  color: #15527f;
  box-shadow: 0 4px 12px rgba(41, 104, 153, .15), inset 0 1px 0 #fff;
}

input[type="file"]:active::file-selector-button,
input[type="file"]:active::-webkit-file-upload-button {
  transform: translateY(1px);
  box-shadow: 0 1px 4px rgba(41, 104, 153, .12), inset 0 1px 0 #fff;
}

input[type="file"]:focus-visible {
  outline: none;
  border-color: #68a9d3;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(35,134,182,.13), 0 4px 14px rgba(56,96,136,.06);
}

button, a { -webkit-tap-highlight-color:transparent; }
.btn { transition:background .16s ease, border-color .16s ease, transform .16s ease, box-shadow .16s ease; }

html.embedded, html.embedded body { background:transparent; }
html.embedded .app-topbar { display:none; }
html.embedded .app-main { max-width:none; padding:20px; }

.status-active { color: var(--color-success); font-weight: 600; }
.status-disabled { color: var(--color-danger); font-weight: 600; }
.status-pending { color: var(--color-ochre-600); font-weight: 600; }

.empty-state {
  text-align: center;
  color: var(--color-text-muted);
  padding: 60px 24px;
}

/* =========================================================
   macOS-inspired unified interface — shared by every module
   ========================================================= */

::selection { color:#fff; background:rgba(0,122,255,.78); }

* {
  scrollbar-width:thin;
  scrollbar-color:rgba(91,111,132,.34) transparent;
}
*::-webkit-scrollbar { width:10px; height:10px; }
*::-webkit-scrollbar-track { background:transparent; }
*::-webkit-scrollbar-thumb {
  min-height:34px;
  border:3px solid transparent;
  border-radius:999px;
  background:rgba(91,111,132,.34);
  background-clip:padding-box;
}
*::-webkit-scrollbar-thumb:hover { background-color:rgba(68,90,113,.52); }

h1,h2,h3,h4,h5,h6 {
  letter-spacing:-.018em;
  line-height:1.28;
}
h1 { font-size:clamp(24px,3vw,32px); }
h2 { font-size:clamp(20px,2.3vw,25px); }
h3 { font-size:17px; }
p { text-wrap:pretty; }
a { text-underline-offset:3px; }

button,input,textarea,select { font-family:var(--font-body); }
button { user-select:none; }

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
textarea,
select {
  min-height:var(--control-height);
  border:1px solid rgba(71,94,118,.18);
  border-radius:10px;
  background:rgba(255,255,255,.78);
  box-shadow:inset 0 1px 1px rgba(22,43,64,.035),0 1px 0 rgba(255,255,255,.74);
  transition:border-color .16s ease,box-shadow .16s ease,background .16s ease;
}
textarea { min-height:88px; resize:vertical; }
input::placeholder,textarea::placeholder { color:#94A2B0; opacity:1; }
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):hover,
textarea:hover,
select:hover { border-color:rgba(63,103,142,.30); }
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):focus,
textarea:focus,
select:focus {
  border-color:#67ADEC;
  background:#fff;
  box-shadow:0 0 0 3px rgba(0,122,255,.13),inset 0 1px 1px rgba(22,43,64,.025);
}
input[type="checkbox"],input[type="radio"] {
  accent-color:#0A84FF;
  width:16px;
  height:16px;
}
input[type="search"]::-webkit-search-cancel-button { cursor:pointer; }

.btn {
  min-height:38px;
  padding:8px 15px;
  border-radius:10px;
  letter-spacing:-.006em;
  box-shadow:0 1px 1px rgba(25,46,68,.04);
}
.btn:active:not(:disabled) { transform:translateY(1px) scale(.995); }
.btn:disabled { filter:saturate(.55); }
.btn-primary {
  background:linear-gradient(180deg,#3195F4 0%,#0879E5 100%);
  border-color:rgba(0,94,191,.42);
  box-shadow:0 5px 14px rgba(0,105,217,.20),inset 0 1px rgba(255,255,255,.30);
}
.btn-primary:hover {
  background:linear-gradient(180deg,#268BE9 0%,#006ED5 100%);
  box-shadow:0 7px 18px rgba(0,105,217,.26),inset 0 1px rgba(255,255,255,.28);
}
.btn-ghost {
  color:#34526F;
  background:linear-gradient(180deg,rgba(255,255,255,.90),rgba(242,247,251,.84));
  border-color:rgba(78,102,127,.18);
  box-shadow:0 1px 2px rgba(32,56,79,.05),inset 0 1px rgba(255,255,255,.78);
}
.btn-ghost:hover {
  color:#165F9F;
  background:#fff;
  border-color:rgba(0,122,255,.28);
}
button:focus-visible,a:focus-visible,.btn:focus-visible {
  outline:3px solid rgba(0,122,255,.22);
  outline-offset:2px;
}

.panel,.module-card,.auth-card {
  border-color:rgba(73,94,117,.14);
  background:rgba(255,255,255,.84);
  box-shadow:var(--shadow-card);
  backdrop-filter:blur(22px) saturate(135%);
}
.panel { border-radius:var(--radius-lg); }
.module-card {
  transition:transform .18s ease,border-color .18s ease,box-shadow .18s ease;
}
.module-card:hover {
  transform:translateY(-2px);
  border-color:rgba(0,122,255,.20);
  box-shadow:0 18px 42px rgba(42,70,99,.13);
}

.app-topbar {
  min-height:58px;
  position:sticky;
  top:0;
  z-index:40;
  padding:11px 22px;
  background:rgba(247,250,253,.78);
  border-bottom-color:rgba(72,91,112,.13);
  box-shadow:0 1px 0 rgba(255,255,255,.70);
  backdrop-filter:blur(28px) saturate(155%);
}
.app-topbar .brand { letter-spacing:-.01em; }
.app-topbar .brand-mark {
  width:34px;
  height:34px;
  border-radius:10px;
  box-shadow:0 3px 10px rgba(38,63,88,.10);
}
.app-user a,.page-back {
  display:inline-flex;
  align-items:center;
  gap:5px;
  color:#3E668D;
  text-decoration:none;
  font-weight:600;
}
.app-user a:hover,.page-back:hover { color:#0878DA; }
.app-main { max-width:1240px; padding:28px 26px 48px; }

table {
  border-collapse:separate;
  border-spacing:0;
  font-size:13px;
}
th,td { padding:11px 14px; }
th {
  color:#415A72;
  background:rgba(239,244,249,.92);
  border-bottom-color:rgba(75,95,115,.13);
  font-size:11px;
  font-weight:700;
  letter-spacing:.025em;
  text-transform:none;
}
td { border-bottom-color:rgba(75,95,115,.11); }
tbody tr { transition:background-color .14s ease; }
tbody tr:hover { background:rgba(226,240,252,.52); }

.role-chip,.badge,.status,.status-pill,.pill {
  letter-spacing:.005em;
  box-shadow:inset 0 0 0 1px rgba(45,75,102,.04);
}
.error-box {
  border:1px solid rgba(184,77,85,.16);
  box-shadow:0 6px 18px rgba(151,55,64,.06);
}
.empty-state,.empty {
  color:#7A8998;
}

.modal-backdrop {
  background:rgba(21,35,50,.28) !important;
  backdrop-filter:blur(10px) saturate(115%);
}
.modal,.modal-panel {
  border:1px solid rgba(255,255,255,.78);
  background:rgba(250,252,254,.96) !important;
  border-radius:20px !important;
  box-shadow:var(--shadow-float) !important;
  animation:mac-modal-in .18s cubic-bezier(.2,.75,.25,1);
}
dialog {
  border:1px solid rgba(255,255,255,.78);
  background:rgba(250,252,254,.97);
  box-shadow:var(--shadow-float);
}
dialog::backdrop {
  background:rgba(21,35,50,.28);
  backdrop-filter:blur(10px);
}
@keyframes mac-modal-in {
  from { opacity:0; transform:translateY(8px) scale(.985); }
  to { opacity:1; transform:translateY(0) scale(1); }
}

input[type="file"] {
  min-height:46px;
  border-style:dashed;
  border-color:rgba(68,115,157,.30);
  background:rgba(245,250,254,.88);
}
input[type="file"]::file-selector-button,
input[type="file"]::-webkit-file-upload-button {
  background:linear-gradient(180deg,#fff,#EAF3FA);
  border-color:rgba(60,113,157,.22);
}

html.embedded,html.embedded body {
  background:transparent !important;
}
html.embedded .app-main {
  max-width:none;
  padding:18px 20px 30px;
}
html.embedded .page-back { display:none; }

@media (max-width:720px) {
  .app-main { padding:20px 14px 36px; }
  .app-topbar { padding:10px 14px; }
  .panel { border-radius:14px; }
  th,td { padding:10px 12px; }
  .modal,.modal-panel { border-radius:17px !important; }
}

@media (prefers-reduced-motion:reduce) {
  *,*::before,*::after {
    scroll-behavior:auto !important;
    animation-duration:.01ms !important;
    animation-iteration-count:1 !important;
    transition-duration:.01ms !important;
  }
}
