/*
 * Core components — สกัดจาก _reference/orgcare360_design_system_preview_v4_motion_progress_standalone.html
 * (ครอบคลุม comment marker: Sections, Buttons, Form, Navigation demos, Badges/display, Feedback,
 * Modal/drawer/toast) ต้องโหลดหลัง tokens.css และ base.css
 * @media override ของแต่ละ selector รวมไว้ข้างกันในไฟล์นี้เลย ไม่แยกไฟล์ responsive ต่างหาก
 */

/* ===== Layout primitives: Card / Section / Grid ===== */
.ds-section {
  position: relative;
  margin-bottom: 20px;
  padding: clamp(20px, 2.8vw, 32px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xs);
}
/* หมายเหตุ: ต้นฉบับมี overflow:hidden ตรงนี้เพื่อครอบวงกลมตกแต่งของ .hero-section (ไม่ได้สกัดมาใน
   ไลบรารีนี้) — เอาออกเพราะทำให้ popup/dropdown ที่เปิดใกล้ขอบล่างการ์ด (date picker, combobox,
   color picker) โดนตัดขอบ ::before accent bar ด้านบนไม่กระทบเพราะอยู่ในขอบเขตการ์ดอยู่แล้ว */
.ds-section::before {
  content: "";
  position: absolute;
  top: 0;
  left: 30px;
  width: 54px;
  height: 3px;
  border-radius: 0 0 999px 999px;
  background: var(--primary);
}
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}
.section-head h2 { margin: 5px 0 0; font-size: clamp(22px, 2.2vw, 28px); line-height: 1.25; letter-spacing: -.025em; }
.section-head p { margin: 6px 0 0; color: var(--muted); }
.eyebrow { display: block; color: var(--primary); font-size: 10px; line-height: 1.3; font-weight: 900; letter-spacing: .15em; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.top-gap { margin-top: 18px; }
.showcase {
  min-width: 0;
  padding: var(--space);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.showcase h3 { margin: 0 0 15px; font-size: 17px; line-height: 1.35; }

.component-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.component-row.end { justify-content: flex-end; }

code {
  padding: 3px 7px;
  border-radius: 6px;
  color: color-mix(in srgb, var(--text) 88%, var(--primary));
  background: var(--surface-muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: .9em;
}

/* ===== Buttons ===== */
.btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 750;
  line-height: 1.2;
  box-shadow: var(--shadow-xs);
  transition: transform .14s ease, box-shadow .14s ease, background .14s ease, border-color .14s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active:not(:disabled) { transform: translateY(0); box-shadow: var(--shadow-xs); }
.btn.primary { color: #fff; background: var(--primary); border-color: var(--primary); }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.secondary { color: var(--text); background: var(--surface); border-color: var(--border-strong); }
.btn.secondary:hover:not(:disabled) { background: var(--surface-muted); }
.btn.ghost { color: var(--text-soft); background: transparent; border-color: transparent; box-shadow: none; }
.btn.ghost:hover:not(:disabled) { background: var(--surface-muted); box-shadow: none; }
.btn.success { color: #fff; background: var(--success); border-color: var(--success); }
.btn.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn.danger.ghost { color: var(--danger); background: transparent; border-color: transparent; box-shadow: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; transform: none; }
.btn.small { min-height: 34px; padding: 6px 11px; border-radius: 8px; font-size: 13px; }
.btn.full { width: 100%; }
.btn:focus-visible, .icon-btn:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible, canvas:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 28%, transparent);
  outline-offset: 2px;
}
.spinner { width: 15px; height: 15px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  min-width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-soft);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  transition: background .16s ease, border-color .16s ease, transform .16s ease;
}
.icon-btn:hover { background: var(--surface-muted); border-color: var(--border-strong); transform: translateY(-1px); }
.icon-btn.danger { color: var(--danger); }

/* ===== Form ===== */
.field { margin-bottom: 16px; }
.field label, .field > label { display: block; margin-bottom: 7px; color: var(--text-soft); font-weight: 750; }
.field label b { color: var(--danger); }
.field input, .field select, .field textarea, .modal select, .modal textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  outline: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: inset 0 1px 2px rgba(16,24,40,.025);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.field textarea, .modal textarea { min-height: auto; resize: vertical; }
.field input:hover, .field select:hover, .field textarea:hover { border-color: color-mix(in srgb, var(--border-strong) 65%, var(--text)); }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--focus); box-shadow: 0 0 0 4px color-mix(in srgb, var(--focus) 13%, transparent); }
.field small { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.field.error input { border-color: var(--danger); background: color-mix(in srgb, var(--danger-soft) 35%, var(--surface)); }
.field.error small { color: var(--danger); }
.align-right { text-align: right; }
.select-wrap { position: relative; display: flex; }
.select-wrap select { padding-right: 42px; }
.clear-select { position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; font-size: 18px; }
.clear-select:hover { color: var(--text); background: var(--surface-muted); }
.choice { display: flex; align-items: flex-start; gap: 10px; margin: 10px 0; color: var(--text-soft); }
.choice input { margin-top: 4px; accent-color: var(--primary); }
fieldset { margin: 0 0 15px; padding: 0; border: 0; }
legend { margin-bottom: 4px; color: var(--text-soft); font-weight: 750; }
.switch { display: flex; align-items: center; gap: 10px; margin: 14px 0; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { width: 44px; height: 25px; position: relative; display: inline-block; border-radius: 999px; background: var(--border-strong); box-shadow: inset 0 0 0 1px rgba(16,24,40,.08); }
.switch span::after { content:""; position:absolute; top:3px; left:3px; width:19px; height:19px; border-radius:50%; background:#fff; box-shadow:0 1px 4px rgba(16,24,40,.22); transition:transform .18s ease; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(19px); }
.switch.compact { margin: 0; padding: 0; border: 0; background: transparent; }
.otp { display: flex; gap: 8px; flex-wrap: wrap; }
.otp input { width: 44px !important; padding-inline: 4px !important; text-align: center; font-size: 17px; font-weight: 850; }
.upload-box {
  position: relative;
  padding: 26px 20px;
  text-align: center;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  transition: border-color .15s ease, background .15s ease;
}
.upload-box:hover { border-color: var(--primary); background: var(--primary-soft); }
.upload-box svg { color: var(--primary); margin-bottom: 5px; }
.upload-box strong, .upload-box small { display: block; }
.upload-box small { color: var(--muted); }
.upload-box input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ===== Navigation ===== */
.tabs { display: flex; gap: 4px; padding-bottom: 2px; overflow: auto; border-bottom: 1px solid var(--border); }
.tabs button { min-height: 39px; padding: 7px 12px; border: 0; border-radius: 8px 8px 0 0; color: var(--muted); background: transparent; font-weight: 700; white-space: nowrap; }
.tabs button:hover { color: var(--text); background: var(--surface-muted); }
.tabs button.active { color: var(--primary); box-shadow: inset 0 -2px 0 var(--primary); }
.tab-panel { display: none; padding: 16px 2px 2px; }
.tab-panel.active { display: block; }
.mini-breadcrumb { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.mini-breadcrumb span:last-child { color: var(--text); font-weight: 700; }
.mobile-nav-demo { display: flex; justify-content: space-around; margin-top: 15px; padding: 7px; background: var(--surface); border: 1px solid var(--border); border-radius: 13px; box-shadow: var(--shadow-sm); }
.mobile-nav-demo button { min-height: 48px; padding: 5px 12px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; }
.mobile-nav-demo button.active { color: var(--primary); background: var(--primary-soft); font-weight: 750; }
.pagination { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.pagination button { min-width: 36px; height: 36px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.pagination button.active { color: #fff; background: var(--primary); border-color: var(--primary); }

/* ===== Badge / Timeline / Table / native progress ===== */
.badge {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
}
.badge.neutral { color: var(--text-soft); background: var(--surface-muted); border-color: var(--border); }
.badge.info { color: var(--info); background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 20%, transparent); }
.badge.success { color: var(--success); background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 20%, transparent); }
.badge.warning { color: var(--warning); background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 22%, transparent); }
.badge.danger { color: var(--danger); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 20%, transparent); }
.badge.count { min-width: 23px; padding-inline: 6px; color: #fff; background: var(--primary); }

.progress-line, progress { width: 100%; height: 7px; border: 0; border-radius: 999px; overflow: hidden; background: var(--surface-muted); }
progress::-webkit-progress-bar { background: var(--surface-muted); }
progress::-webkit-progress-value { background: var(--primary); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--primary); border-radius: 999px; }

.timeline { position: relative; padding-left: 28px; }
.timeline::before { content:""; position:absolute; left:9px; top:8px; bottom:8px; width:2px; background:var(--border); }
.timeline li { position: relative; padding: 0 0 18px; list-style: none; }
.timeline li::before { content:""; position:absolute; left:-24px; top:5px; width:12px; height:12px; border:3px solid var(--surface); border-radius:50%; background:var(--border-strong); box-shadow:0 0 0 1px var(--border); }
.timeline li.done::before, .timeline li.current::before { background:var(--primary); }
.timeline li:last-child { padding-bottom: 0; }
.timeline strong, .timeline small { display:block; }
.timeline small { color:var(--muted); }
.timeline i { position: absolute; left: -22px; top: 4px; width: 15px; height: 15px; display: grid; place-items: center; color: #fff; }

.table-showcase { overflow: hidden; padding: 0; background: var(--surface); }
.table-toolbar { display:flex; justify-content:space-between; align-items:center; gap:10px; padding:14px 16px; border-bottom:1px solid var(--border); }
.table-scroll { overflow:auto; }
table { width:100%; border-collapse:collapse; }
th, td { padding:12px 14px; border-bottom:1px solid var(--border); text-align:left; white-space:nowrap; }
th { color:var(--muted); background:var(--surface-subtle); font-size:11px; letter-spacing:.04em; text-transform:uppercase; }
tbody tr:hover { background:color-mix(in srgb,var(--primary-soft) 48%,var(--surface)); }
tbody tr:last-child td { border-bottom:0; }
.user-inline { display:flex; align-items:center; gap:9px; }
.user-inline i, .assignee i { width:34px; height:34px; display:grid; place-items:center; border-radius:50%; color:var(--primary); background:var(--primary-soft); font-style:normal; font-weight:850; }
.user-inline strong, .user-inline small { display:block; }
.user-inline small { color:var(--muted); }

/* ===== Feedback: alert / empty / skeleton ===== */
.alerts { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; }
.alert { display:flex; align-items:flex-start; gap:10px; padding:13px 14px; border:1px solid var(--border); border-radius:var(--radius-md); background:var(--surface); }
.alert svg { flex:0 0 auto; margin-top:1px; }
.alert strong { display:block; }
.alert p { margin:3px 0 0; color:color-mix(in srgb,currentColor 76%,var(--muted)); }
.alert.info { color:var(--info); background:var(--info-soft); border-color:color-mix(in srgb,var(--info) 18%,var(--border)); }
.alert.success { color:var(--success); background:var(--success-soft); border-color:color-mix(in srgb,var(--success) 18%,var(--border)); }
.alert.warning { color:var(--warning); background:var(--warning-soft); border-color:color-mix(in srgb,var(--warning) 18%,var(--border)); }
.alert.danger { color:var(--danger); background:var(--danger-soft); border-color:color-mix(in srgb,var(--danger) 18%,var(--border)); }
.empty-state, .danger-state { min-height:210px; display:grid; place-items:center; text-align:center; padding:28px; border:1px dashed var(--border-strong); border-radius:var(--radius-lg); background:var(--surface-subtle); }
.empty-state svg, .danger-state svg { color:var(--muted); }
.empty-state h3, .danger-state h3 { margin:10px 0 3px; }
.empty-state p, .danger-state p { max-width:420px; margin:0 0 13px; color:var(--muted); }
.skeleton-card { display:grid; gap:10px; }
.skeleton-card i { display:block; height:14px; border-radius:7px; background:var(--surface-muted); animation:pulse 1.35s ease-in-out infinite alternate; }
.skeleton-card i:nth-child(1){height:92px}.skeleton-card i:nth-child(2){width:68%}.skeleton-card i:nth-child(3){width:88%}.skeleton-card i:nth-child(4){width:55%}
@keyframes pulse { to { opacity:.46; } }

/* ===== Modal / Drawer / Toast ===== */
.modal-backdrop, .drawer-backdrop { position:fixed; inset:0; z-index:120; display:none; padding:18px; background:rgba(5,12,22,.62); backdrop-filter:blur(4px); }
.modal-backdrop.open, .drawer-backdrop.open { display:grid; place-items:center; }
.modal { width:min(570px,100%); max-height:92vh; overflow:auto; background:var(--surface); border:1px solid var(--border); border-radius:18px; box-shadow:var(--shadow-lg); }
.modal-head, .modal-foot { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:17px 19px; }
.modal-head { border-bottom:1px solid var(--border); }
.modal-head h2 { margin:3px 0; }
.modal-body { padding:19px; }
.modal-foot { justify-content:flex-end; border-top:1px solid var(--border); }
.drawer-backdrop { padding:0; place-items:stretch end; }
.drawer { width:min(430px,100%); height:100%; display:flex; flex-direction:column; background:var(--surface); box-shadow:var(--shadow-lg); }
.drawer-body { flex:1; padding:19px; overflow:auto; }
.drawer-foot { display:flex; justify-content:space-between; gap:10px; padding:16px; border-top:1px solid var(--border); }
.toast-stack { position:fixed; right:20px; bottom:20px; z-index:140; display:flex; flex-direction:column; gap:9px; }
.toast { width:min(370px,calc(100vw - 40px)); display:flex; align-items:flex-start; gap:11px; padding:13px 14px; background:var(--surface); border:1px solid var(--border); border-left:4px solid var(--success); border-radius:12px; box-shadow:var(--shadow-md); animation:toastin .2s ease; }
.toast > span { width:24px; height:24px; display:grid; place-items:center; color:#fff; background:var(--success); border-radius:50%; }
.toast strong, .toast small { display:block; }
.toast small { color:var(--muted); }
@keyframes toastin { from { transform:translateY(8px); opacity:0; } }

/* ===== Responsive (รวม @media ของแต่ละ selector ข้างต้นไว้ที่นี่ ไม่แยกไฟล์) ===== */
@media (max-width: 820px) {
  .ds-section { padding:20px 16px; border-radius:16px; }
  .ds-section::before { left:16px; }
  .grid-2, .grid-3 { grid-template-columns:1fr; }
  .alerts { grid-template-columns:1fr; }
  .section-head { align-items:flex-start; }
}

@media (max-width: 500px) {
  .section-head { flex-direction:column; }
  .component-row.end .btn { width:100%; }
}

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

@media print {
  .toast-stack { display:none !important; }
  .ds-section { break-inside:avoid; box-shadow:none; }
}
