/* ═══════════════════════════════════════════════════════════════
   ThaiChat · UI Primitives v4 (drop-in CSS classes)
   Vanilla CSS classes that wrap iOS patterns — pair with Tailwind.

   Why both?
   ─ Tailwind utilities = flex/grid/spacing/text size
   ─ tc-* primitives    = brand-aware components, iOS chrome,
                          glass effects, gradients

   USAGE
   ─────
   <button class="tc-btn tc-btn-primary text-sm px-4 py-2.5">บันทึก</button>
   <input  class="tc-input" placeholder="ค้นหา…"/>
   <div    class="tc-card p-6">…</div>
   ═══════════════════════════════════════════════════════════════ */

/* ─── BUTTONS ─────────────────────────────────────────────── */
.tc-btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; padding: 10px 16px; border-radius: var(--tc-r-3);
  border: none; font-family: inherit; font-weight: 600; font-size: 14px;
  color: var(--tc-text-1); background: var(--tc-fill-1);
  cursor: pointer; white-space: nowrap; line-height: 1;
  transition: transform .12s ease, box-shadow .15s ease,
              background .15s ease, opacity .15s ease;
}
.tc-btn:hover { background: var(--tc-fill-2); }
.tc-btn:active { transform: translateY(1px); }
.tc-btn:disabled { opacity: .4; cursor: not-allowed; }

.tc-btn-primary {
  background: var(--tc-brand-grad); color: #fff;
  box-shadow: var(--tc-brand-glow-sm);
}
.tc-btn-primary:hover { background: var(--tc-brand-grad); filter: brightness(1.05); box-shadow: var(--tc-brand-glow); transform: translateY(-1px); }

.tc-btn-ghost {
  background: var(--tc-fill-1); color: var(--tc-text-1);
}

.tc-btn-tinted {
  background: var(--tc-brand-tint); color: var(--tc-brand-on-tint);
}
.tc-btn-tinted:hover { background: var(--tc-brand-tint-strong); }

.tc-btn-outlined {
  background: transparent; border: 1px solid var(--tc-line-2);
  color: var(--tc-text-1);
}
.tc-btn-outlined:hover { background: var(--tc-fill-1); }

.tc-btn-danger {
  background: var(--tc-bad); color: #fff;
  box-shadow: 0 2px 8px rgba(255,59,48,.35);
}
.tc-btn-danger:hover { filter: brightness(1.05); }

.tc-btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: var(--tc-r-2); }
.tc-btn-lg { padding: 14px 22px; font-size: 16px; border-radius: var(--tc-r-4); }

/* Icon button (square) */
.tc-icon-btn {
  width: 36px; height: 36px; padding: 0; border-radius: var(--tc-r-2);
  background: var(--tc-fill-1); border: none; color: var(--tc-text-2);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .15s, color .15s;
}
.tc-icon-btn:hover { background: var(--tc-fill-2); color: var(--tc-text-1); }
.tc-icon-btn.tc-icon-btn-sm { width: 28px; height: 28px; border-radius: var(--tc-r-1); }
.tc-icon-btn.tc-icon-btn-lg { width: 44px; height: 44px; border-radius: var(--tc-r-3); }

/* ─── INPUTS ──────────────────────────────────────────────── */
.tc-input, .tc-textarea {
  width: 100%; font-family: inherit; font-size: 14px;
  padding: 11px 14px; background: var(--tc-fill-1);
  border: 1px solid transparent; border-radius: var(--tc-r-3);
  color: var(--tc-text-1); outline: none;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.tc-input:focus, .tc-textarea:focus {
  background: var(--tc-bg-elev); border-color: var(--tc-brand-500);
  box-shadow: 0 0 0 4px var(--tc-brand-tint);
}
.tc-input::placeholder, .tc-textarea::placeholder { color: var(--tc-text-4); }
.tc-textarea { min-height: 80px; resize: vertical; }

.tc-input-group { position: relative; }
.tc-input-group .tc-input { padding-left: 38px; }
.tc-input-group > .tc-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  font-size: 16px; color: var(--tc-text-3); pointer-events: none;
}

/* ─── CARDS ───────────────────────────────────────────────── */
.tc-card {
  background: var(--tc-bg-elev);
  border: .5px solid var(--tc-line-1);
  border-radius: var(--tc-r-6);
  box-shadow: var(--tc-sh-2);
}
.tc-card-glass {
  background: var(--tc-bg-glass);
  -webkit-backdrop-filter: var(--tc-blur);
  backdrop-filter: var(--tc-blur);
  border: .5px solid var(--tc-line-1);
  border-radius: var(--tc-r-6);
}
.tc-card-flat {
  background: var(--tc-bg-elev);
  border: .5px solid var(--tc-line-1);
  border-radius: var(--tc-r-6);
}

/* ─── BADGES & PILLS ──────────────────────────────────────── */
.tc-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: var(--tc-r-full);
  font-size: 11px; font-weight: 600; line-height: 1.5;
  background: var(--tc-fill-2); color: var(--tc-text-2);
  font-variant-numeric: tabular-nums;
}
.tc-badge-brand { background: var(--tc-brand-tint); color: var(--tc-brand-on-tint); }
.tc-badge-ok    { background: rgba(52,199,89,.16);  color: #248A3D; }
.tc-badge-warn  { background: rgba(255,159,10,.18); color: #B25E00; }
.tc-badge-bad   { background: rgba(255,59,48,.16);  color: #C7372F; }
.tc-badge-info  { background: rgba(0,122,255,.14);  color: #0066CC; }
.tc-badge-purple{ background: rgba(175,82,222,.14); color: #864AA8; }

[data-theme="dark"] .tc-badge-ok    { color: #58D27A; }
[data-theme="dark"] .tc-badge-warn  { color: #FFB454; }
[data-theme="dark"] .tc-badge-bad   { color: #FF6B61; }
[data-theme="dark"] .tc-badge-info  { color: #4DA3FF; }
[data-theme="dark"] .tc-badge-purple{ color: #C77AE8; }

/* Channel chips (fixed channel brand colors) */
.tc-chan {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px 3px 6px; border-radius: var(--tc-r-full);
  font-size: 11.5px; font-weight: 600;
  background: var(--tc-fill-1); color: var(--tc-text-2);
}
.tc-chan-dot {
  width: 10px; height: 10px; border-radius: 999px; flex-shrink: 0;
  display: inline-block;
}
.tc-chan[data-chan="line"]  .tc-chan-dot { background: var(--tc-line); }
.tc-chan[data-chan="ig"]    .tc-chan-dot { background: var(--tc-ig); }
.tc-chan[data-chan="fb"]    .tc-chan-dot { background: var(--tc-fb); }
.tc-chan[data-chan="web"]   .tc-chan-dot { background: var(--tc-brand-500); }

/* Count badge — for nav items / notifications */
.tc-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 6px;
  border-radius: var(--tc-r-full);
  background: var(--tc-bad); color: #fff;
  font-size: 10.5px; font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.tc-count-brand { background: var(--tc-brand-500); }
.tc-count-soft  { background: var(--tc-fill-2); color: var(--tc-text-2); }

/* ─── SEGMENTED CONTROL (iOS) ────────────────────────────── */
.tc-segmented {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--tc-fill-2); border-radius: var(--tc-r-3);
}
.tc-segmented > button {
  border: none; background: transparent;
  padding: 6px 14px; border-radius: calc(var(--tc-r-3) - 3px);
  font-family: inherit; font-size: 13px; font-weight: 500;
  color: var(--tc-text-2); cursor: pointer;
  transition: background .18s, color .18s, box-shadow .18s;
}
.tc-segmented > button.on {
  background: var(--tc-bg-elev); color: var(--tc-text-1); font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

/* ─── LIST ROWS (iOS settings style) ─────────────────────── */
.tc-list {
  background: var(--tc-bg-elev);
  border: .5px solid var(--tc-line-1);
  border-radius: var(--tc-r-5);
  overflow: hidden;
}
.tc-list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: .5px solid var(--tc-line-1);
  font-size: 14px; color: var(--tc-text-1);
}
.tc-list-row:last-child { border-bottom: none; }
.tc-list-row:hover { background: var(--tc-fill-1); }
.tc-list-row .tc-list-icon {
  width: 28px; height: 28px; border-radius: var(--tc-r-1);
  background: var(--tc-brand-tint); color: var(--tc-brand-on-tint);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 16px;
}
.tc-list-row .tc-list-title { flex: 1; min-width: 0; }
.tc-list-row .tc-list-detail { color: var(--tc-text-3); font-size: 13px; }
.tc-list-row .tc-icon-chevron-right {
  color: var(--tc-text-4); font-size: 14px;
}
.tc-list-section-label {
  font-size: 11px; font-weight: 500; color: var(--tc-text-3);
  letter-spacing: .08em; text-transform: uppercase;
  padding: 16px 16px 6px;
}

/* ─── TOGGLE / SWITCH (iOS) ──────────────────────────────── */
.tc-switch {
  position: relative; display: inline-block;
  width: 44px; height: 26px; flex-shrink: 0;
}
.tc-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.tc-switch .tc-switch-track {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--tc-fill-3); border-radius: var(--tc-r-full);
  transition: background .25s;
}
.tc-switch .tc-switch-track::before {
  content: ''; position: absolute;
  width: 22px; height: 22px; left: 2px; top: 2px;
  background: #fff; border-radius: 999px;
  box-shadow: 0 2px 4px rgba(0,0,0,.18);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}
.tc-switch input:checked + .tc-switch-track { background: var(--tc-ok); }
.tc-switch input:checked + .tc-switch-track::before { transform: translateX(18px); }
.tc-switch-brand input:checked + .tc-switch-track { background: var(--tc-brand-500); }

/* ─── MODAL / SHEET ──────────────────────────────────────── */
.tc-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.tc-modal {
  background: var(--tc-bg-elev); border-radius: var(--tc-r-7);
  box-shadow: var(--tc-sh-4);
  max-width: 90vw; max-height: 90vh; overflow: hidden;
  border: .5px solid var(--tc-line-1);
}

/* ─── TOAST ──────────────────────────────────────────────── */
.tc-toast {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 10px 16px 10px 12px; background: var(--tc-bg-glass-strong);
  -webkit-backdrop-filter: var(--tc-blur); backdrop-filter: var(--tc-blur);
  border: .5px solid var(--tc-line-1); border-radius: var(--tc-r-full);
  box-shadow: var(--tc-sh-3); font-size: 13px;
}

/* ─── AVATAR ──────────────────────────────────────────────── */
.tc-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; background: var(--tc-fill-2);
  color: var(--tc-text-2); font-weight: 600;
  flex-shrink: 0; position: relative; overflow: hidden;
  font-variant-numeric: tabular-nums;
}
.tc-avatar > .tc-avatar-dot {
  position: absolute; right: 0; bottom: 0;
  width: 28%; height: 28%; min-width: 8px; min-height: 8px;
  background: var(--tc-ok); border: 2px solid var(--tc-bg-elev);
  border-radius: 999px;
}

/* ─── PROGRESS ────────────────────────────────────────────── */
.tc-progress {
  width: 100%; height: 6px; background: var(--tc-fill-2);
  border-radius: var(--tc-r-full); overflow: hidden;
}
.tc-progress > i {
  display: block; height: 100%;
  background: var(--tc-brand-grad);
  border-radius: inherit; transition: width .35s ease;
}

/* ─── SKELETON ────────────────────────────────────────────── */
@keyframes tc-shimmer {
  0% { background-position: -200px 0; }
  100% { background-position: calc(200px + 100%) 0; }
}
.tc-skel {
  background: linear-gradient(90deg, var(--tc-fill-1) 0%,
              var(--tc-fill-2) 50%, var(--tc-fill-1) 100%);
  background-size: 200px 100%;
  background-repeat: no-repeat;
  animation: tc-shimmer 1.4s linear infinite;
  border-radius: var(--tc-r-1);
}

/* ─── DIVIDER / HAIRLINE ─────────────────────────────────── */
.tc-hr {
  border: none; border-top: .5px solid var(--tc-line-1);
  margin: 0;
}

/* ─── KBD ─────────────────────────────────────────────────── */
.tc-kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 22px; padding: 0 6px;
  background: var(--tc-bg-elev); border: .5px solid var(--tc-line-2);
  border-bottom-width: 1.5px; border-radius: 5px;
  font-family: var(--tc-font-mono); font-size: 11px; font-weight: 600;
  color: var(--tc-text-2);
}
