/* ชิ้นส่วนที่ใช้ซ้ำหลายหน้า: การ์ด ปุ่ม ฟอร์ม ตาราง ลิ้นชัก กล่องข้อความ */

.card {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.panel-title {
  font-family: var(--font-disp);
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.count-badge {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-mid);
  background: var(--panel-raised);
  padding: 3px 8px;
  border-radius: 100px;
}

.eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  color: var(--text-mid);
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 100px;
  border: 1px solid var(--hairline);
  color: var(--text-mid);
  background: var(--panel);
}

.pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-low);
}

.pill.live {
  color: var(--accent);
  border-color: var(--accent-dim);
}

.pill.live .dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.pill.bad {
  color: var(--danger);
  border-color: var(--danger);
}

.pill.bad .dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 15px;
  border-radius: var(--radius-md);
  border: 1px solid var(--hairline);
  background: var(--panel-raised);
  color: var(--text-hi);
  font-size: 13px;
  font-weight: 600;
  transition: filter 0.15s, border-color 0.15s;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent-dim);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #062012;
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-danger {
  color: var(--danger);
  border-color: var(--danger-soft);
  background: var(--danger-soft);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  color: var(--text-mid);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  color: var(--text-hi);
}

/* ---------- แท็บ ---------- */
.tabbar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.tabbar::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: none;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--hairline);
  background: var(--panel);
  color: var(--text-mid);
  font-size: 12.5px;
  font-weight: 600;
}

.tab:hover {
  color: var(--text-hi);
  border-color: var(--accent-dim);
}

.tab.active {
  background: var(--accent);
  color: #06150e;
  border-color: var(--accent);
}

.tab.small {
  padding: 7px 12px;
  font-size: 12px;
}

.section-gap {
  margin-top: 18px;
}

/* ---------- ฟอร์ม ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-size: 11.5px;
  color: var(--text-mid);
  font-weight: 600;
}

.field input,
.field select,
.field textarea {
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  color: var(--text-hi);
  padding: 10px 12px;
  font-size: 13px;
  outline: none;
  width: 100%;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent-dim);
}

.field .hint {
  font-size: 11px;
  color: var(--text-low);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 620px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

.switch {
  width: 38px;
  height: 22px;
  border-radius: 100px;
  background: var(--hairline);
  position: relative;
  border: none;
  flex: none;
  transition: background 0.15s;
}

.switch.on {
  background: var(--accent);
}

.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.15s;
}

.switch.on::after {
  left: 18px;
}

.switch:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-top: 1px solid var(--hairline-soft);
}

.switch-row:first-of-type {
  border-top: none;
}

.switch-row .label {
  font-size: 13px;
  font-weight: 600;
}

.switch-row .sub {
  font-size: 11.5px;
  color: var(--text-mid);
  margin-top: 2px;
  line-height: 1.5;
}

/* ---------- ตาราง ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  white-space: nowrap;
}

table.data th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-low);
  font-weight: 700;
  padding: 11px 12px;
  background: var(--panel-raised);
  position: sticky;
  top: 0;
}

table.data td {
  padding: 10px 12px;
  border-top: 1px solid var(--hairline-soft);
  color: var(--text-hi);
}

table.data tbody tr:hover td {
  background: rgba(62, 207, 142, 0.04);
}

table.data td.num,
table.data th.num {
  text-align: right;
  font-family: var(--font-mono);
}

table.data tfoot td {
  background: var(--panel-raised);
  font-weight: 700;
  border-top: 1px solid var(--hairline);
}

/* ---------- สถานะว่าง / กำลังโหลด ---------- */
.empty {
  text-align: center;
  color: var(--text-low);
  font-size: 12.5px;
  padding: 26px 10px;
  line-height: 1.7;
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--panel-raised) 25%,
    #183826 37%,
    var(--panel-raised) 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
  }
}

/* ---------- ลิ้นชักด้านขวา ---------- */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 460px;
  max-width: 94vw;
  background: var(--panel);
  border-left: 1px solid var(--hairline);
  z-index: 41;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
  padding: 22px 20px 40px;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 9, 6, 0.6);
  backdrop-filter: blur(2px);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
  gap: 12px;
}

.drawer-title {
  font-family: var(--font-disp);
  font-size: 18px;
  font-weight: 700;
}

.drawer-sub {
  font-size: 12px;
  color: var(--text-mid);
  margin-top: 2px;
}

/* ---------- กล่องโต้ตอบ ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 9, 6, 0.7);
  backdrop-filter: blur(3px);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-drop);
  width: 460px;
  max-width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 22px;
}

.modal h3 {
  font-family: var(--font-disp);
  font-size: 16px;
  margin-bottom: 4px;
}

.modal .modal-sub {
  font-size: 12.5px;
  color: var(--text-mid);
  margin-bottom: 16px;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.modal-actions .btn {
  flex: 1;
}

/* ---------- แถบแจ้งผล ---------- */
.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
}

.toast {
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  border-left-width: 3px;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 12.5px;
  line-height: 1.6;
  box-shadow: var(--shadow-drop);
  animation: toast-in 0.18s ease;
}

.toast.ok {
  border-left-color: var(--accent);
}

.toast.err {
  border-left-color: var(--danger);
}

.toast.info {
  border-left-color: var(--info);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- หน้าเข้าสู่ระบบ ---------- */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: radial-gradient(
      circle at 15% 12%,
      rgba(62, 207, 142, 0.1),
      transparent 45%
    ),
    var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.login-card {
  width: 380px;
  max-width: 100%;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 28px 26px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.login-error {
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  margin-bottom: 14px;
  line-height: 1.6;
}

.login-foot {
  margin-top: 16px;
  font-size: 11.5px;
  color: var(--text-low);
  text-align: center;
  line-height: 1.7;
}

/* ---------- ตัวช่วยทั่วไป ---------- */
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.row.between {
  justify-content: space-between;
}

.grow {
  flex: 1;
  min-width: 0;
}

.muted {
  color: var(--text-mid);
}

.dim {
  color: var(--text-low);
}

.good {
  color: var(--accent);
}

.warn {
  color: var(--warn);
}

.bad {
  color: var(--danger);
}

.nowrap {
  white-space: nowrap;
}

.status-chip {
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 100px;
  display: inline-block;
}

.status-chip.pending {
  color: var(--warn);
  background: var(--warn-soft);
}

.status-chip.done {
  color: var(--accent);
  background: var(--accent-soft);
}

.status-chip.off {
  color: var(--text-low);
  background: var(--panel-raised);
}

.status-chip.bad {
  color: var(--danger);
  background: var(--danger-soft);
}
