@import url("https://fonts.googleapis.com/css2?family=Sora:wght@500;600;700;800&family=Noto+Sans+SC:wght@400;500;600;700&display=swap");

:root {
  --bg: #eef2f6;
  --bg-deep: #e4ebf2;
  --card: rgba(255, 255, 255, 0.86);
  --card-solid: #ffffff;
  --text: #15202b;
  --muted: #64748b;
  --line: rgba(21, 32, 43, 0.08);
  --primary: #0f766e;
  --primary-deep: #0b5f59;
  --ink: #1e293b;
  --ok: #059669;
  --warn: #d97706;
  --bad: #dc2626;
  --accent: #0f766e;
  --shadow: 0 14px 40px rgba(15, 40, 48, 0.08);
  --radius: 18px;
  --font-display: "Sora", "Noto Sans SC", "PingFang SC", sans-serif;
  --font-body: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(900px 420px at 8% -8%, rgba(15, 118, 110, 0.16), transparent 60%),
    radial-gradient(800px 380px at 92% 0%, rgba(45, 112, 145, 0.12), transparent 55%),
    linear-gradient(180deg, #f5f8fb 0%, var(--bg) 45%, var(--bg-deep) 100%);
}

a { color: var(--accent); }

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}
.wrap.wrap-wide {
  max-width: 1520px;
  padding: 18px 22px 56px;
}
.wrap.narrow {
  max-width: 420px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* —— Left sidebar layout —— */
.admin-layout {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}
.admin-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.92), rgba(240,249,248,0.88));
  border-right: 1px solid var(--line);
  box-shadow: 8px 0 28px rgba(15, 40, 48, 0.04);
  backdrop-filter: blur(12px);
}
.sidebar-brand { padding: 0 6px 18px; }
.brand-eyebrow {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--primary);
  font-weight: 700;
}
.sidebar-brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink);
}
.sidebar-sub {
  margin: 4px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}
.admin-nav-side {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.admin-nav-side a {
  text-decoration: none;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}
.admin-nav-side a:hover {
  color: var(--text);
  background: rgba(15, 118, 110, 0.08);
}
.admin-nav-side a.active {
  color: #fff;
  background: linear-gradient(120deg, var(--primary-deep), var(--primary));
  box-shadow: 0 10px 20px rgba(15, 118, 110, 0.22);
}
.sidebar-foot { padding-top: 14px; }
.admin-main {
  min-width: 0;
  padding: 20px 22px 56px;
  max-width: 1520px;
}
.logout-link {
  display: block;
  text-align: center;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  transition: color .15s, border-color .15s;
}
.logout-link:hover {
  color: var(--bad);
  border-color: #fecaca;
}
@media (max-width: 900px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .admin-nav-side {
    flex-direction: row;
    flex-wrap: wrap;
  }
}

.top { margin-bottom: 16px; }
.top.row, .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.row.gap { justify-content: flex-start; }

h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin: 0 0 8px;
}
h2 {
  font-family: var(--font-display);
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }

/* —— Cards —— */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.card.danger {
  border-color: #fecaca;
  background: #fef2f2;
}
.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.card-title-row h2 { margin: 0; }

.muted { color: var(--muted); font-size: 0.92rem; line-height: 1.55; }
.note {
  font-size: 0.85rem;
  color: var(--muted);
  background: rgba(248, 250, 252, 0.95);
  border: 1px solid var(--line);
  padding: 10px 12px;
  border-radius: 12px;
}

textarea, input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  margin: 8px 0 12px;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: rgba(15, 118, 110, 0.45);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}
label { display: block; font-size: 0.9rem; margin-bottom: 8px; }

/* —— Buttons —— */
.btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: #e8eef2;
  color: var(--ink);
  transition: transform .12s, filter .12s, box-shadow .12s;
}
.btn:hover:not(:disabled) { filter: brightness(0.98); transform: translateY(-1px); }
.btn.primary {
  background: linear-gradient(120deg, var(--primary-deep), var(--primary));
  color: #fff;
  box-shadow: 0 10px 22px rgba(15, 118, 110, 0.22);
}
.btn.danger { background: #fee2e2; color: #991b1b; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.sm { padding: 6px 10px; font-size: 0.82rem; border-radius: 9px; }
.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
}

.err { color: var(--bad); min-height: 1.2em; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  background: #e8eef1;
  color: var(--ink);
}
.badge.ok { background: #d1fae5; color: #065f46; }
.badge.warn { background: #fff0cc; color: #92400e; }
.badge.bad { background: #fee2e2; color: #991b1b; }

/* —— Stats —— */
.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin: 4px 0 12px;
}
@media (max-width: 1100px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 720px) { .stats { grid-template-columns: 1fr 1fr; } }
@media (max-width: 480px) { .stats { grid-template-columns: 1fr; } }
.stat {
  padding: 14px 16px;
  border-radius: 16px;
  background: linear-gradient(160deg, rgba(255,255,255,0.95), rgba(240,249,248,0.9));
  border: 1px solid var(--line);
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 600;
}
.stat strong {
  display: block;
  margin-top: 6px;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink);
}
.stat .stat-sub {
  display: block;
  margin-top: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}
.view-as-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 14px;
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(232, 163, 23, 0.16);
  border: 1px solid rgba(196, 122, 0, 0.28);
  color: #5c3d00;
  font-size: 0.92rem;
}
.sidebar-user {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 8px;
  word-break: break-all;
}

.meta-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 4px;
}
.meta-chip {
  font-size: 0.8rem;
  color: var(--muted);
  background: rgba(15, 118, 110, 0.06);
  border: 1px solid rgba(15, 118, 110, 0.1);
  padding: 5px 10px;
  border-radius: 999px;
}

/* —— Tables —— */
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.9rem; }
th, td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}
th {
  font-size: 0.78rem;
  text-transform: none;
  letter-spacing: 0.02em;
  color: var(--muted);
  font-weight: 700;
  background: rgba(248, 250, 252, 0.85);
}
thead th:first-child { border-radius: 12px 0 0 0; }
thead th:last-child { border-radius: 0 12px 0 0; }
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,0.55);
}
.link-mini { font-size: 0.8rem; word-break: break-all; }

table.table-compact th,
table.table-compact td {
  white-space: nowrap;
  vertical-align: middle;
  padding: 9px 11px;
  font-size: 0.86rem;
}
table.table-compact tbody tr:hover td {
  background: rgba(15, 118, 110, 0.04);
}
table.table-compact .ops {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.cell-clip {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  color: var(--accent);
  cursor: default;
  font-weight: 600;
}
.cell-clip.short { max-width: 140px; }
.cell-clip.cell-copy { cursor: pointer; }
.cell-clip:hover { text-decoration: underline; }
.result a { color: var(--accent); }

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
}
@media (max-width: 700px) { .field-grid { grid-template-columns: 1fr; } }
.field label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 4px;
}
.field input, .field select, .field textarea {
  width: 100%;
  margin: 0;
}
.field.full { grid-column: 1 / -1; }

/* —— Modal —— */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: min(560px, 100%);
  max-height: min(90vh, 760px);
  overflow: auto;
  background: #fff;
  border-radius: 20px;
  border: 1px solid var(--line);
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.24);
  padding: 22px 24px;
  animation: modalIn .18s ease-out;
}
.modal.wide { width: min(680px, 100%); }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: none; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.modal-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
}
.modal-close {
  border: 0;
  background: #f1f5f9;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
}
.modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-top: 16px;
}
.pill-usage {
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--text);
}

/* —— Login —— */
.login-page .card {
  padding: 22px 22px 18px;
}
.login-page h1 {
  text-align: center;
  margin-bottom: 18px;
  background: linear-gradient(120deg, var(--primary-deep), #145a72);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.login-page .btn.primary { width: 100%; margin-top: 4px; }

.pipeline { list-style: none; padding: 0; margin: 12px 0 0; }
.pipeline li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
}

pre.note {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.5;
}
