@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: dark;
  --ink: #edf4ff;
  --muted: #91a5c3;
  --faint: #627695;
  --canvas: #07111f;
  --canvas-deep: #050c17;
  --panel: rgba(16, 29, 49, .82);
  --panel-strong: #122039;
  --line: rgba(142, 173, 215, .17);
  --line-bright: rgba(112, 209, 255, .36);
  --cyan: #5fe2ff;
  --blue: #7797ff;
  --violet: #ad8bff;
  --green: #5ee7ac;
  --yellow: #ffd477;
  --red: #ff8497;
  --shadow: 0 22px 60px rgba(0, 4, 17, .38);
  font-family: Manrope, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas-deep); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(900px 560px at 8% -10%, rgba(50, 140, 205, .23), transparent 70%),
    radial-gradient(800px 600px at 102% 90%, rgba(112, 88, 214, .20), transparent 72%),
    var(--canvas);
  font-size: 14px;
  line-height: 1.5;
}

body::before {
  position: fixed;
  z-index: -1;
  inset: 0;
  background-image: linear-gradient(rgba(180, 220, 255, .025) 1px, transparent 1px), linear-gradient(90deg, rgba(180, 220, 255, .025) 1px, transparent 1px);
  background-size: 48px 48px;
  content: "";
  mask-image: linear-gradient(to bottom, black, transparent 82%);
}

.hidden, .admin-only { display: none !important; }
.is-admin .admin-only { display: block !important; }
.is-admin button.admin-only { display: block !important; }

button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 36px 20px;
}

.auth-card {
  position: relative;
  width: min(450px, 100%);
  overflow: hidden;
  padding: 43px;
  border: 1px solid rgba(147, 189, 232, .22);
  border-radius: 25px;
  background: linear-gradient(145deg, rgba(25, 45, 75, .92), rgba(12, 25, 44, .92));
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, .06);
  backdrop-filter: blur(22px);
}

.auth-card::after {
  position: absolute;
  top: -120px;
  right: -110px;
  width: 245px;
  height: 245px;
  border-radius: 50%;
  background: rgba(77, 211, 255, .13);
  content: "";
  filter: blur(3px);
}

.brand-mark {
  position: relative;
  z-index: 1;
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 17px;
  background: linear-gradient(135deg, #65e7ff 0%, #7797ff 52%, #b38cff 100%);
  box-shadow: 0 9px 26px rgba(73, 166, 255, .34);
  color: #07101d;
  font-size: 35px;
  font-weight: 800;
  line-height: 1;
}

.brand-mark.mini { width: 37px; height: 37px; border-radius: 12px; font-size: 26px; flex: 0 0 auto; }

.eyebrow {
  margin: 21px 0 7px;
  color: var(--cyan);
  font-family: "DM Mono", monospace;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .15em;
}

.auth-card h1 { position: relative; z-index: 1; margin: 0; font-size: clamp(25px, 5vw, 31px); letter-spacing: -.04em; }
.tagline { position: relative; z-index: 1; margin: 10px 0 29px; color: #bcd0ed; font-size: 15px; }

.tabs { display: flex; gap: 3px; margin-bottom: 22px; border-bottom: 1px solid var(--line); }
.tab {
  position: relative;
  padding: 10px 15px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.tab::after { position: absolute; right: 13px; bottom: -1px; left: 13px; height: 2px; border-radius: 3px; background: transparent; content: ""; }
.tab:hover { color: #d9eaff; }
.tab.active { color: var(--cyan); }
.tab.active::after { background: var(--cyan); box-shadow: 0 0 12px var(--cyan); }

.stack { display: grid; gap: 16px; }
label { display: grid; gap: 7px; color: #c9d9ef; font-size: 12px; font-weight: 600; }

input, select, textarea {
  width: 100%;
  border: 1px solid rgba(139, 172, 216, .23);
  border-radius: 10px;
  outline: none;
  padding: 11px 12px;
  background: rgba(5, 15, 28, .55);
  color: var(--ink);
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, .18);
  transition: border-color .18s, background .18s, box-shadow .18s;
}
input::placeholder, textarea::placeholder { color: #627795; }
input:focus, select:focus, textarea:focus { border-color: var(--cyan); background: rgba(7, 20, 37, .9); box-shadow: 0 0 0 3px rgba(95, 226, 255, .12); }
select option { background: #122039; color: var(--ink); }
textarea { min-height: 88px; resize: vertical; }

.primary, .secondary, .danger {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  padding: 9px 13px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .16s, filter .16s, border-color .16s, background .16s;
}
.primary { border: 1px solid rgba(255, 255, 255, .18); background: linear-gradient(135deg, #69e4ff, #7797ff); box-shadow: 0 7px 18px rgba(80, 168, 255, .18); color: #071120; }
.secondary { border: 1px solid rgba(132, 177, 225, .24); background: rgba(58, 91, 132, .34); color: #d8e8ff; }
.danger { border: 1px solid rgba(255, 130, 151, .28); background: rgba(255, 96, 118, .11); color: #ffa5b3; }
.primary:hover, .secondary:hover, .danger:hover { filter: brightness(1.12); transform: translateY(-1px); }
.primary:active, .secondary:active, .danger:active { transform: translateY(0); }
button:disabled { cursor: not-allowed; opacity: .52; transform: none !important; }

.muted { color: var(--muted); }
.positive { color: var(--green); }
.small { font-size: 12px; line-height: 1.65; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  width: 259px;
  height: 100vh;
  flex: 0 0 259px;
  flex-direction: column;
  padding: 23px 14px 16px;
  border-right: 1px solid var(--line);
  background: rgba(8, 19, 34, .82);
  backdrop-filter: blur(22px);
}

.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 9px 26px; }
.sidebar-brand strong { display: block; font-size: 14px; letter-spacing: -.02em; }
.sidebar-brand small { display: block; margin-top: 2px; color: var(--faint); font-size: 10px; white-space: nowrap; }
.sidebar nav { display: grid; gap: 3px; overflow-y: auto; padding-right: 2px; }
.nav-item {
  position: relative;
  min-height: 39px;
  border: 0;
  border-radius: 9px;
  padding: 9px 12px;
  background: transparent;
  color: #9bb0cc;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background .16s, color .16s;
}
.nav-item:hover { background: rgba(69, 108, 158, .17); color: #ebf5ff; }
.nav-item.active { background: linear-gradient(90deg, rgba(76, 196, 246, .19), rgba(76, 136, 246, .07)); color: #ecf9ff; }
.nav-item.active::before { position: absolute; top: 10px; bottom: 10px; left: 0; width: 3px; border-radius: 0 4px 4px 0; background: var(--cyan); box-shadow: 0 0 12px var(--cyan); content: ""; }
.nav-divider { display: block; padding: 20px 12px 6px !important; color: #607492; font-family: "DM Mono", monospace; font-size: 9px; font-weight: 500; letter-spacing: .13em; text-transform: uppercase; }
.sidebar-footer { display: flex; align-items: center; justify-content: space-between; gap: 9px; margin-top: auto; padding: 16px 8px 2px; border-top: 1px solid var(--line); }
.sidebar-footer strong, .sidebar-footer small { display: block; }
.sidebar-footer strong { font-size: 12px; }
.sidebar-footer small { margin-top: 2px; color: var(--faint); font-size: 10px; }
.text-button { border: 0; padding: 6px; background: none; color: var(--cyan); font-size: 12px; cursor: pointer; }
.text-button:hover { color: white; }

.main { width: calc(100% - 259px); min-width: 0; }
.topbar {
  position: sticky;
  z-index: 4;
  top: 0;
  display: flex;
  min-height: 94px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 19px 42px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 17, 31, .69);
  backdrop-filter: blur(22px);
}
.topbar .eyebrow { margin: 0 0 2px; }
.topbar h2 { margin: 0; font-size: 24px; letter-spacing: -.045em; }
.balance-chip { display: flex; align-items: baseline; gap: 7px; border: 1px solid rgba(108, 227, 177, .22); border-radius: 10px; padding: 8px 12px; background: rgba(55, 194, 137, .075); color: #a2c5b6; font-size: 12px; }
.balance-chip strong { color: var(--green); font-family: "DM Mono", monospace; font-size: 14px; }
.page-content { width: 100%; max-width: 1510px; padding: 31px 42px 60px; }
.loading { padding: 45px 0; color: var(--muted); }

.grid { display: grid; gap: 16px; }
.grid.cards { grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 21px 0; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 16px; }
.card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 19px;
  background: linear-gradient(145deg, rgba(21, 39, 65, .75), rgba(12, 25, 44, .79));
  box-shadow: 0 9px 28px rgba(0, 5, 18, .13), inset 0 1px rgba(255, 255, 255, .025);
}
.grid.cards .card::after { position: absolute; top: -29px; right: -19px; width: 92px; height: 92px; border-radius: 50%; background: rgba(95, 226, 255, .07); content: ""; }
.stat-card p { position: relative; z-index: 1; margin: 0; color: var(--muted); font-size: 12px; font-weight: 600; }
.stat-card strong { position: relative; z-index: 1; display: block; margin-top: 9px; color: #edf5ff; font-family: "DM Mono", monospace; font-size: 26px; letter-spacing: -.06em; }
.stat-card strong.positive { color: var(--green); }
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; margin: 1px 0 16px; }
.section-head h3, .card > h3 { margin: 0; font-size: 16px; letter-spacing: -.025em; }
.section-head p { max-width: 780px; margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.card > h3 + p { margin: 7px 0 15px; color: var(--muted); line-height: 1.65; }

.table-wrap { overflow: auto; border: 1px solid rgba(138, 172, 217, .16); border-radius: 11px; background: rgba(6, 16, 29, .23); }
table { width: 100%; min-width: 620px; border-collapse: collapse; }
th, td { border-bottom: 1px solid rgba(138, 172, 217, .12); padding: 12px 13px; text-align: left; vertical-align: top; }
th { position: sticky; top: 0; z-index: 1; background: #111f36; color: #91a9c8; font-family: "DM Mono", monospace; font-size: 10px; font-weight: 500; letter-spacing: .025em; white-space: nowrap; }
td { color: #d8e5f5; font-size: 12px; }
td strong { color: #f2f7ff; font-size: 13px; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: rgba(86, 143, 214, .065); }
tbody tr:last-child td { border-bottom: 0; }

.actions { display: flex; flex-wrap: wrap; gap: 6px; min-width: 104px; }
.actions .primary, .actions .secondary, .actions .danger { min-height: 31px; padding: 6px 9px; font-size: 11px; }
.pill { display: inline-flex; align-items: center; border: 1px solid rgba(142, 177, 222, .18); border-radius: 99px; padding: 3px 7px; background: rgba(96, 132, 177, .16); color: #bcd5f2; font-size: 10px; font-weight: 700; white-space: nowrap; }
.pill.approved, .pill.active { border-color: rgba(94, 231, 172, .26); background: rgba(94, 231, 172, .1); color: #7cf0bc; }
.pill.pending { border-color: rgba(255, 212, 119, .28); background: rgba(255, 212, 119, .1); color: #ffe09a; }
.pill.rejected, .pill.disabled, .pill.revoked { border-color: rgba(255, 132, 151, .28); background: rgba(255, 132, 151, .1); color: #ffadba; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: center; gap: 9px; margin-top: 16px; }
.notice { margin-bottom: 17px; border: 1px solid rgba(95, 226, 255, .24); border-radius: 11px; padding: 12px 14px; background: linear-gradient(90deg, rgba(54, 184, 227, .11), rgba(72, 112, 230, .07)); color: #c4ecff; font-size: 13px; line-height: 1.65; }
.warning { border-color: rgba(255, 212, 119, .26); background: rgba(255, 212, 119, .075); color: #ffe1a2; }
.empty { border: 1px dashed rgba(142, 177, 222, .24); border-radius: 11px; padding: 31px 18px; color: var(--muted); text-align: center; }
.key-reveal { overflow-wrap: anywhere; margin-top: 10px; border: 1px solid rgba(94, 231, 172, .18); border-radius: 8px; padding: 10px; background: rgba(4, 13, 24, .72); color: var(--green); font-family: "DM Mono", monospace; font-size: 12px; line-height: 1.6; }
.code { color: #9bdbff; font-family: "DM Mono", Consolas, monospace; font-size: 11px; }
.split { display: flex; align-items: center; gap: 9px; }
.split > * { flex: 1; }

#toast { position: fixed; z-index: 10; right: 22px; bottom: 22px; max-width: min(440px, calc(100% - 44px)); border: 1px solid rgba(112, 209, 255, .34); border-radius: 11px; padding: 12px 14px; background: #143151; box-shadow: var(--shadow); color: #e5f7ff; opacity: 0; pointer-events: none; transform: translateY(10px); transition: opacity .2s, transform .2s; }
#toast.show { opacity: 1; transform: translateY(0); }
#toast.error { border-color: rgba(255, 132, 151, .38); background: #4a2633; color: #ffd6dc; }

ol.muted { margin: 12px 0 0; padding-left: 19px; }
ol.muted li { margin: 8px 0; }

@media (max-width: 1080px) {
  .sidebar { width: 222px; flex-basis: 222px; }
  .main { width: calc(100% - 222px); }
  .topbar, .page-content { padding-right: 25px; padding-left: 25px; }
  .grid.cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: relative; width: 100%; height: auto; min-height: 0; padding: 14px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-brand { padding: 0 7px 12px; }
  .sidebar nav { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; overflow: visible; }
  .nav-item { min-height: 34px; padding: 7px 5px; font-size: 11px; text-align: center; }
  .nav-item.active::before { top: auto; right: 10px; bottom: 1px; left: 10px; width: auto; height: 2px; }
  .nav-divider, .sidebar-footer { display: none !important; }
  .is-admin .sidebar nav .admin-only { display: block !important; }
  .main { width: 100%; }
  .topbar { position: relative; min-height: 78px; padding: 17px; }
  .topbar h2 { font-size: 20px; }
  .page-content { padding: 18px 13px 42px; }
  .grid.cards, .grid.two, .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .card { padding: 15px; border-radius: 13px; }
  .section-head { flex-direction: column; }
  .section-head .secondary { width: 100%; }
  .auth-card { padding: 31px 24px; }
  .balance-chip { padding: 7px 9px; }
}

@media (max-width: 410px) {
  .sidebar nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .topbar { align-items: flex-end; }
  .balance-chip { font-size: 10px; }
  .balance-chip strong { font-size: 12px; }
}

.playground-grid { display: grid; grid-template-columns: minmax(230px, .65fr) minmax(0, 1.65fr); gap: 16px; }
.playground-side { align-self: start; min-height: 330px; }
.playground-price { display: grid; gap: 3px; margin-top: 16px; border: 1px solid rgba(100, 224, 255, .18); border-radius: 11px; padding: 13px; background: linear-gradient(135deg, rgba(76, 210, 255, .11), rgba(119, 151, 255, .07)); }
.playground-price span, .playground-price small { color: var(--muted); font-size: 11px; }
.playground-price strong { color: var(--cyan); font-family: "DM Mono", monospace; font-size: 19px; }
.chat-card { display: flex; min-height: 530px; flex-direction: column; padding: 0; }
.chat-title { display: flex; align-items: flex-start; justify-content: space-between; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.chat-title .eyebrow { margin: 0 0 3px; }
.chat-title h3 { margin: 0; font-size: 16px; }
.chat-history { display: flex; min-height: 320px; flex: 1; flex-direction: column; gap: 15px; overflow-y: auto; padding: 20px; background: radial-gradient(360px 190px at 95% 0, rgba(91, 102, 228, .10), transparent 72%); }
.chat-message { display: grid; max-width: 88%; gap: 5px; }
.chat-message > span { color: var(--faint); font-family: "DM Mono", monospace; font-size: 10px; }
.chat-message > div { border: 1px solid rgba(135, 173, 221, .16); border-radius: 4px 13px 13px; padding: 10px 12px; background: rgba(20, 37, 61, .7); white-space: pre-wrap; word-break: break-word; }
.chat-message.user { align-self: flex-end; }
.chat-message.user > span { text-align: right; }
.chat-message.user > div { border-color: rgba(95, 226, 255, .22); border-radius: 13px 4px 13px 13px; background: linear-gradient(135deg, rgba(64, 175, 216, .2), rgba(72, 103, 196, .22)); }
.chat-welcome { display: grid; align-content: center; justify-items: center; min-height: 280px; color: var(--muted); text-align: center; }
.chat-welcome .brand-mark { margin-bottom: 14px; opacity: .85; }
.chat-welcome strong { color: #dcecff; }
.chat-welcome p { max-width: 280px; margin: 7px 0; font-size: 12px; line-height: 1.7; }
.chat-form { border-top: 1px solid var(--line); padding: 14px; background: rgba(9, 20, 36, .72); }
.chat-form textarea { min-height: 79px; }
.chat-form > div { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 9px; }
.modal-backdrop { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(1, 7, 16, .68); backdrop-filter: blur(8px); }
.modal-card { width: min(740px, 100%); max-height: min(820px, calc(100vh - 40px)); overflow-y: auto; border: 1px solid rgba(121, 199, 250, .3); border-radius: 17px; padding: 21px; background: #102039; box-shadow: 0 28px 90px rgba(0, 0, 0, .5); }
.modal-card .eyebrow { margin-top: 0; }

@media (max-width: 880px) {
  .playground-grid { grid-template-columns: 1fr; }
  .playground-side { min-height: 0; }
  .chat-card { min-height: 480px; }
}
