/* Live AI Admin — ส่วนเสริมเล็กน้อยต่อจาก /shared/styles.css (ห้ามซ้ำกับ design system) */

.brand-slot { display: inline-flex; }
.admin-chip { background: var(--card); border: 1px solid var(--card-border); }
.admin-chip .who { min-width: 0; }

.stack-xs { display: grid; gap: 0; line-height: 1.35; }

/* loading */
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 32px 12px; color: var(--muted); }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgb(255 255 255 / 0.15); border-top-color: var(--cyan); animation: spin .8s linear infinite; flex: none; }
.empty-ico { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: rgb(255 255 255 / 0.05); color: var(--cyan); }
.empty-ico svg { width: 22px; height: 22px; }

/* KPI */
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); }
.kpi-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: rgb(255 255 255 / 0.05); color: var(--cyan); flex: none; }
.kpi-ico svg { width: 18px; height: 18px; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.tone-ok { background: linear-gradient(135deg, rgb(34 197 94 / 0.14), rgb(34 197 94 / 0.03)); border-color: rgb(34 197 94 / 0.3); }
.kpi.tone-ok .kpi-ico { color: var(--ok); }
.kpi.tone-warn { background: linear-gradient(135deg, rgb(245 158 11 / 0.16), rgb(245 158 11 / 0.03)); border-color: rgb(245 158 11 / 0.35); }
.kpi.tone-warn .kpi-ico { color: var(--warn); }

/* layout */
.grid-main { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; }
.donut-wrap { display: flex; align-items: center; justify-content: center; gap: 20px; flex-wrap: wrap; flex: 1; }
.donut-wrap .legend { min-width: 140px; flex: 1; }

/* tables */
.table-wrap {
  container-type: inline-size;
}
th.num-col, td.num-col { text-align: right; }
tr.clickable { cursor: pointer; }
.key-cell { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; flex-wrap: wrap; }
.cell-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-user p { line-height: 1.25; }
.detail-cell { max-width: 420px; overflow-wrap: anywhere; }
.bar-cell { display: grid; grid-template-columns: minmax(80px, 1fr) auto; align-items: center; gap: 10px; min-width: 220px; }
.bar-cell .num { min-width: 72px; text-align: right; }
tfoot th, tfoot td { border-top: 1px solid var(--card-border); border-bottom: 0; font-weight: 600; position: static; background: rgb(255 255 255 / 0.03); color: var(--text); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.toolbar .count { margin-left: auto; }

/* Template chip buttons */
.tpl-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tpl-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 11px;
  border-radius: 99px;
  font-size: 12.5px;
  font-weight: 700;
  background: rgba(56, 189, 248, 0.14);
  color: #7dd3fc;
  border: 1px solid rgba(56, 189, 248, 0.35);
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}
.tpl-chip:hover {
  background: rgba(56, 189, 248, 0.24);
}
.tpl-chip:active {
  transform: scale(0.96);
}
.tpl-chip code {
  color: #34d399;
  font-family: ui-monospace, monospace;
  font-weight: 800;
}

/* drawer */
.drawer-body { display: grid; gap: 20px; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; position: sticky; top: -20px; margin: -20px -20px 0; padding: 16px 20px 12px; background: var(--bg-2); border-bottom: 1px solid var(--card-border); z-index: 1; }
.drawer-head h2:focus { outline: none; }
.drawer-section { display: grid; gap: 10px; }
.drawer-section > h3 { font-size: 13px; color: var(--muted); font-weight: 600; }
.profile-head { display: flex; align-items: center; gap: 12px; }
.profile-head .avatar { width: 44px; height: 44px; font-size: 18px; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* new keys */
.keys-list { display: grid; gap: 6px; max-height: 300px; overflow: auto; padding: 10px 12px; border-radius: 12px; background: rgb(0 0 0 / 0.25); border: 1px solid var(--card-border); }
.keys-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.forbidden { max-width: 520px; margin: 10vh auto 0; }
.forbidden .empty-ico { width: 56px; height: 56px; }

/* Responsive Stacked Table Cards (Container Query + Media Query Fallback) */
table.users-resp-table {
  --label-1: "ลูกค้า / ร้านค้า";
  --label-2: "รหัสคีย์ (Key)";
  --label-3: "แพ็กเกจ / สถานะ";
  --label-4: "วันหมดอายุ";
  --label-5: "วันที่สร้าง";
}

@container (width < 760px) {
  table.users-resp-table,
  table.users-resp-table thead,
  table.users-resp-table tbody,
  table.users-resp-table tr,
  table.users-resp-table th,
  table.users-resp-table td {
    display: block;
  }

  table.users-resp-table thead {
    /* MANDATORY: Hide column header from layout and screen readers. */
    display: none;
  }

  table.users-resp-table tbody {
    display: grid;
    gap: 12px;
    padding: 10px;
  }

  table.users-resp-table tbody tr {
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 18px;
    padding: 14px;
    background: rgba(15, 23, 42, 0.65);
    box-shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.45);
    display: grid;
    gap: 10px;
  }

  table.users-resp-table tbody td {
    padding: 4px 0;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    text-align: right;
  }

  table.users-resp-table tbody td:first-child {
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    padding-bottom: 10px;
    margin-bottom: 2px;
    text-align: left;
  }

  table.users-resp-table tbody td:nth-child(2)::before {
    content: var(--label-2) ": " / var(--label-2);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
  }
  table.users-resp-table tbody td:nth-child(3)::before {
    content: var(--label-3) ": " / var(--label-3);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
  }
  table.users-resp-table tbody td:nth-child(4)::before {
    content: var(--label-4) ": " / var(--label-4);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
  }
  table.users-resp-table tbody td:nth-child(5)::before {
    content: var(--label-5) ": " / var(--label-5);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
  }

  table.users-resp-table tbody td.actions {
    border-bottom: 0;
    padding-top: 8px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    white-space: normal;
  }

  table.users-resp-table tbody td.actions .btn-copy-main {
    grid-column: 1 / -1;
    padding: 11px 16px;
    font-size: 14.5px;
    margin-right: 0 !important;
  }

  table.users-resp-table tbody td.actions .btn {
    width: 100%;
    margin-right: 0 !important;
    justify-content: center;
  }
}

@media (max-width: 1100px) {
  .grid-main { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .sidebar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
    padding: 12px 14px !important;
    margin: 8px !important;
    border-radius: 20px !important;
  }
  .sidebar .brand {
    font-size: 18px;
    justify-content: space-between;
  }
  .sidebar #admin-nav {
    overflow-x: auto;
    padding-bottom: 2px;
  }
  .sidebar .nav {
    display: flex !important;
    gap: 6px !important;
    width: max-content;
  }
  .sidebar .nav a {
    padding: 8px 12px !important;
    font-size: 13px !important;
    white-space: nowrap;
  }
  .sidebar .nav a span.label {
    display: inline !important;
  }
  .sidebar-foot {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 0 !important;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    flex-wrap: wrap;
  }
  .sidebar-foot .admin-chip {
    display: none !important;
  }
  .main {
    padding: 12px !important;
    gap: 14px !important;
  }
  .page-head {
    flex-direction: column;
    align-items: stretch !important;
    gap: 12px;
  }
  .page-head h1 {
    font-size: 20px;
    line-height: 1.3;
  }
  .page-actions {
    width: 100%;
    display: grid !important;
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .page-actions .btn {
    width: 100%;
    min-height: 44px;
    font-size: 14.5px;
  }
  .toolbar input[type="search"] {
    max-width: 100% !important;
    width: 100%;
  }
  dialog {
    width: 96vw !important;
    max-height: 92dvh !important;
    padding: 16px !important;
    border-radius: 20px !important;
  }
  dialog.drawer {
    width: 100vw !important;
    height: 94dvh !important;
    max-height: 94dvh !important;
    margin: auto 0 0 0 !important;
    border-radius: 22px 22px 0 0 !important;
  }
  .drawer-body {
    padding: 8px !important;
    max-width: 100% !important;
  }
  .drawer-head {
    margin: -8px -8px 0 !important;
    padding: 12px 12px 10px !important;
    top: -8px !important;
  }
}
