/*
 * assets/css/admin.css — 後台管理頁（admin.html）：分頁「金鑰管理」（#281）與「xBAS 設定」（#351）。
 * 金鑰管理的 GET 回應帶每把金鑰的明文值，所以頁面不載任何第三方資源（CDN 腳本、字型、樣式表）：
 * 同源的第三方腳本讀得到 DOM，連第三方 CSS 都能用屬性選擇器把值一個字一個字送出去。
 * 版型照原本 Tailwind 版的深色看板；字型改用系統字型。整頁是滿版直欄：標題列、分頁列，
 * 下面的內容區自己捲動，xBAS 設定分頁的 CityLens iframe 撐滿內容區。
 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0b1120;
  --line: rgba(30, 41, 59, 0.9);
  --line-strong: rgba(51, 65, 85, 0.9);
  --text: #e2e8f0;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --cyan: #22d3ee;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  color: var(--slate-200);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei",
    "Noto Sans TC", sans-serif;
  line-height: 1.5;
  background-color: var(--bg);
  background-image: radial-gradient(circle at 50% 0%, #1e293b 0%, #0b1120 70%);
}

h1,
h2,
p {
  margin: 0;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

a {
  color: inherit;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

.icon {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  vertical-align: -0.125em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------------------------------------------------------------- header */

.page-header {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid rgba(22, 78, 99, 0.3);
}

.brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.pulse-dot {
  width: 0.75rem;
  height: 0.75rem;
  flex-shrink: 0;
  border-radius: 999px;
  background: var(--cyan);
  box-shadow: 0 0 15px var(--cyan);
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.5;
  }
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.page-title .grad {
  color: transparent;
  background: linear-gradient(to right, #a5f3fc, #bfdbfe, #60a5fa);
  -webkit-background-clip: text;
  background-clip: text;
}

.page-title .sep {
  margin: 0 0.5rem;
  color: var(--slate-700);
  font-weight: 100;
}

.page-title .tech {
  color: #06b6d4;
  font-size: 1.25rem;
  letter-spacing: 0.12em;
}

.subtitle {
  margin-top: 0.25rem;
  font-size: 11px;
  color: var(--slate-500);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.viewer {
  font-size: 0.75rem;
  color: var(--slate-400);
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  border: 1px solid var(--slate-700);
  border-radius: 0.5rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  color: var(--slate-300);
  transition: border-color 0.2s;
}

.nav-btn:hover {
  border-color: rgba(6, 182, 212, 0.6);
}

.nav-btn .icon {
  color: rgba(34, 211, 238, 0.8);
}

.nav-btn.danger {
  border-color: rgba(159, 18, 57, 0.7);
  background: rgba(76, 5, 25, 0.3);
  color: rgba(254, 205, 211, 0.95);
}

.nav-btn.danger:hover {
  border-color: rgba(244, 63, 94, 0.5);
}

.nav-btn.danger .icon {
  color: rgba(251, 113, 133, 0.9);
}

/* ---------------------------------------------------------------- layout */

.page-main {
  width: 100%;
  max-width: 72rem;
  margin: 0 auto;
}

.admin-tabs {
  display: flex;
  flex: none;
  gap: 0.25rem;
  padding: 0 1rem;
  border-bottom: 1px solid rgba(22, 78, 99, 0.3);
  overflow-x: auto;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  margin-bottom: -1px;
  padding: 0.625rem 0.875rem;
  border-bottom: 2px solid transparent;
  font-size: 0.875rem;
  color: var(--slate-400);
  white-space: nowrap;
  transition: color 0.2s, border-color 0.2s;
}

.tab:hover {
  color: var(--slate-200);
}

.tab.active {
  border-bottom-color: var(--cyan);
  color: var(--slate-100);
}

.tab .icon {
  color: rgba(34, 211, 238, 0.8);
}

/* 內容區自己捲動；金鑰分頁照原本的頁面留白，xBAS 設定分頁讓 iframe 撐滿。 */
.admin-main {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  overflow: auto;
}

.admin-status > * {
  margin: 1.5rem 1rem 0;
}

.admin-pad {
  padding: 1.5rem 1rem;
}

.settings-panel,
.frame-host {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

.frame-host iframe {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg);
}

.stack > * + * {
  margin-top: 2rem;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: rgba(15, 23, 42, 0.7);
  box-shadow: 0 0 5px rgba(34, 211, 238, 0.15);
  padding: 1.25rem;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
  font-size: 1rem;
  font-weight: 700;
  color: #cffafe;
}

.panel-title .icon {
  color: var(--cyan);
}

.panel-title .icon.amber {
  color: rgba(251, 191, 36, 0.9);
}

.panel-title .count {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--slate-500);
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.panel-head .panel-title {
  margin-bottom: 0;
}

.hint {
  margin-bottom: 1rem;
  font-size: 0.75rem;
  color: var(--slate-500);
}

.hint.relaxed {
  color: var(--slate-400);
  line-height: 1.7;
}

.hint strong {
  color: var(--slate-200);
}

.note {
  font-size: 11px;
  color: var(--slate-500);
}

/* ---------------------------------------------------------------- loading / login / error */

.loading {
  padding: 4rem 0;
  text-align: center;
  color: var(--slate-500);
}

.spinner {
  width: 1.875rem;
  height: 1.875rem;
  margin: 0 auto 0.75rem;
  border: 3px solid rgba(8, 145, 178, 0.25);
  border-top-color: #0891b2;
  border-radius: 999px;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-text {
  font-size: 0.75rem;
  letter-spacing: 0.1em;
}

.login-panel {
  text-align: center;
}

.login-panel .big-icon {
  font-size: 2.25rem;
  color: rgba(245, 158, 11, 0.8);
  margin-bottom: 1rem;
}

.login-panel h2 {
  font-size: 1.125rem;
  font-weight: 700;
}

.login-panel .body {
  margin-top: 0.75rem;
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--slate-400);
}

.login-panel .small {
  margin-top: 0.75rem;
  font-size: 0.75rem;
  color: var(--slate-500);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  max-width: 22rem;
  margin: 1.5rem auto 0;
  text-align: left;
}

.login-form .primary-btn {
  justify-content: center;
}

.alert-error {
  border: 1px solid rgba(136, 19, 55, 0.6);
  border-radius: 0.5rem;
  background: rgba(76, 5, 25, 0.3);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: #fecdd3;
}

/* ---------------------------------------------------------------- form */

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.form-grid label {
  display: block;
}

.label-text {
  font-size: 0.75rem;
  color: var(--slate-400);
}

.field {
  width: 100%;
  margin-top: 0.25rem;
  border-radius: 0.5rem;
  border: 1px solid var(--line-strong);
  background: rgba(2, 6, 23, 0.7);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--text);
}

.field::placeholder {
  color: var(--slate-500);
}

.field:focus {
  outline: none;
  border-color: rgba(34, 211, 238, 0.6);
  box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.15);
}

.field:disabled {
  opacity: 0.5;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.primary-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid rgba(14, 116, 144, 0.7);
  border-radius: 0.5rem;
  background: rgba(8, 51, 68, 0.4);
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #cffafe;
  transition: border-color 0.2s;
}

.primary-btn:hover:not(:disabled) {
  border-color: rgba(34, 211, 238, 0.6);
}

.error-text {
  font-size: 0.875rem;
  color: #fda4af;
}

.created {
  margin-top: 1.25rem;
  border: 1px solid rgba(4, 120, 87, 0.6);
  border-radius: 0.5rem;
  background: rgba(2, 44, 34, 0.3);
  padding: 1rem;
}

.created-title {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #a7f3d0;
}

.created-hint {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: rgba(167, 243, 208, 0.7);
}

.created-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.created-row .icon-btn {
  align-self: flex-start;
}

.created-secret {
  flex: 1;
  border: 1px solid rgba(6, 95, 70, 0.6);
  border-radius: 0.25rem;
  background: rgba(2, 6, 23, 0.8);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: #d1fae5;
}

/* ---------------------------------------------------------------- tables */

.table-wrap {
  overflow-x: auto;
  margin: 0 -0.5rem;
}

.keys-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.keys-table thead {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--slate-500);
}

.keys-table th {
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.keys-table td,
.keys-table th {
  padding: 0.6rem 0.75rem;
  vertical-align: top;
}

.keys-table tbody tr {
  border-top: 1px solid var(--line);
}

.keys-table tr.confirm-row {
  background: rgba(76, 5, 25, 0.3);
}

.secret-cell {
  font-family: var(--mono);
  word-break: break-all;
}

.cell-name {
  font-weight: 500;
  color: var(--slate-100);
  white-space: nowrap;
}

.cell-secret {
  max-width: 18rem;
  color: var(--slate-300);
}

.rename-field {
  min-width: 12rem;
  margin-top: 0;
}

.cell-actions {
  display: flex;
  gap: 0.375rem;
  margin-top: 0.25rem;
}

.cell-label {
  color: var(--slate-200);
}

.cell-config-key {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: rgba(165, 243, 252, 0.8);
  word-break: break-all;
}

.cell-where {
  font-size: 0.75rem;
  color: var(--slate-400);
  word-break: break-all;
}

.nowrap {
  white-space: nowrap;
}

.xs {
  font-size: 0.75rem;
}

.right {
  text-align: right;
}

.muted {
  color: var(--slate-400);
}

.soft {
  color: var(--slate-300);
}

.dim {
  color: var(--slate-500);
}

.faint {
  color: var(--slate-600);
}

.mono {
  font-family: var(--mono);
}

.binding-sub {
  font-family: var(--mono);
  color: rgba(165, 243, 252, 0.9);
}

.cell-grants {
  min-width: 12rem;
  font-size: 0.75rem;
}

.grant {
  white-space: nowrap;
  color: var(--slate-300);
}

.grants > * + * {
  margin-top: 0.125rem;
}

.grant-off {
  color: var(--slate-600);
  text-decoration: line-through;
}

.grant-off .binding-sub {
  color: var(--slate-600);
}

.grants-note {
  margin-top: 0.75rem;
}

.form-jwt {
  color: rgba(252, 211, 77, 0.9);
}

.matches {
  margin-top: 0.25rem;
  font-size: 11px;
  color: var(--slate-500);
}

.matches > * + * {
  margin-top: 0.125rem;
}

.confirm {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  font-size: 0.875rem;
}

.confirm-text {
  flex: 1;
  color: #fecdd3;
}

.confirm-text .icon {
  margin-right: 0.25rem;
}

.confirm-buttons {
  display: flex;
  gap: 0.5rem;
}

.delete-error {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: #fda4af;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.375rem;
  padding: 0.15rem 0.5rem;
  font-size: 0.7rem;
  color: #a5f3fc;
  background: rgba(8, 47, 73, 0.25);
  transition: border-color 0.2s, background 0.2s;
}

.icon-btn:hover {
  border-color: rgba(34, 211, 238, 0.6);
  background: rgba(8, 47, 73, 0.5);
}

.icon-btn.danger {
  color: #fecdd3;
  background: rgba(76, 5, 25, 0.3);
  border-color: rgba(159, 18, 57, 0.6);
}

.icon-btn.danger:hover {
  border-color: rgba(244, 63, 94, 0.7);
}

.empty {
  padding: 1.5rem 0;
  text-align: center;
  font-size: 0.875rem;
  color: var(--slate-500);
}

/* md 以下不斷行 */
.br-md {
  display: none;
}

/* ---------------------------------------------------------------- ≥ 640px / ≥ 768px */

@media (min-width: 640px) {
  .created-row {
    flex-direction: row;
    align-items: center;
  }

  .created-row .icon-btn {
    align-self: auto;
  }
}

@media (min-width: 768px) {
  .page-header {
    padding: 1rem 2rem 0.75rem;
  }

  .admin-tabs {
    padding: 0 2rem;
  }

  .admin-pad {
    padding: 2rem;
  }

  .admin-status > * {
    margin: 2rem 2rem 0;
  }

  .page-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  .page-title {
    font-size: 1.875rem;
  }

  .page-title .tech {
    font-size: 1.5rem;
  }

  .subtitle {
    font-size: 0.75rem;
  }

  .panel {
    padding: 1.5rem;
  }

  .login-panel {
    padding: 2rem;
  }

  .form-grid {
    grid-template-columns: 1fr 1fr;
  }

  .form-grid .span-2 {
    grid-column: span 2;
  }

  .confirm {
    flex-direction: row;
    align-items: center;
  }

  .br-md {
    display: inline;
  }
}
