:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-soft: #f1f2f8;
  --surface-strong: #e8e9f2;
  --text: #171927;
  --muted: #70758b;
  --line: #e3e5ed;
  --primary: #6757e8;
  --primary-soft: #eeeafd;
  --primary-deep: #4f40c8;
  --mint: #20aa91;
  --mint-soft: #e8f8f4;
  --warning: #c27a14;
  --warning-soft: #fff4df;
  --danger: #d9485f;
  --danger-soft: #ffedf0;
  --shadow: 0 18px 50px rgba(43, 39, 79, .08);
  --radius: 16px;
  --sidebar: 244px;
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1018;
  --surface: #141824;
  --surface-soft: #1a1f2d;
  --surface-strong: #23293a;
  --text: #f2f3f7;
  --muted: #969db3;
  --line: #292f40;
  --primary: #8b7cf2;
  --primary-soft: #26213f;
  --primary-deep: #a99df8;
  --mint: #46cdb4;
  --mint-soft: #152e2b;
  --warning: #e0a84f;
  --warning-soft: #32291a;
  --danger: #f06f83;
  --danger-soft: #39202a;
  --shadow: 0 20px 60px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.boot { min-height: 100vh; display: grid; place-content: center; gap: 18px; justify-items: center; }
.boot img { width: 54px; height: 54px; }
.boot span { width: 92px; height: 3px; border-radius: 9px; background: var(--surface-strong); overflow: hidden; position: relative; }
.boot span::after { content: ""; position: absolute; inset: 0 60% 0 0; background: var(--primary); animation: load 1s ease-in-out infinite alternate; }
@keyframes load { to { inset: 0 0 0 60%; } }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: var(--surface); border-right: 1px solid var(--line); padding: 24px 16px 18px; display: flex; flex-direction: column; z-index: 30; }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 25px; }
.brand img { width: 38px; height: 38px; }
.brand-copy strong { display: block; font-size: 17px; letter-spacing: -.3px; }
.brand-copy small { color: var(--muted); font-size: 10px; letter-spacing: 2.1px; text-transform: uppercase; }
.nav-label { padding: 13px 12px 8px; font-size: 10px; letter-spacing: 1.6px; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.nav { display: grid; gap: 4px; }
.nav a { min-height: 44px; display: flex; align-items: center; gap: 11px; padding: 0 12px; border-radius: 11px; color: var(--muted); font-size: 14px; font-weight: 600; transition: .18s ease; }
.nav a:hover { color: var(--text); background: var(--surface-soft); }
.nav a.active { color: var(--primary-deep); background: var(--primary-soft); }
.nav svg { width: 19px; height: 19px; stroke-width: 1.8; }
.nav-spacer { flex: 1; }
.side-note { border-top: 1px solid var(--line); padding: 16px 10px 0; }
.side-note p { margin: 0 0 6px; font-size: 12px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 4px var(--mint-soft); }
.side-note small { color: var(--muted); font-size: 11px; line-height: 1.6; }

.topbar { height: 70px; position: fixed; inset: 0 0 auto var(--sidebar); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 34px; z-index: 20; }
.top-title { display: flex; align-items: baseline; gap: 10px; }
.top-title strong { font-size: 17px; letter-spacing: -.2px; }
.top-title span { color: var(--muted); font-size: 12px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 11px; display: grid; place-items: center; background: var(--surface); cursor: pointer; }
.icon-button:hover { border-color: var(--primary); color: var(--primary); }
.icon-button svg { width: 18px; height: 18px; }
.balance-pill { height: 38px; padding: 0 14px; border-radius: 11px; display: flex; align-items: center; gap: 8px; background: var(--mint-soft); color: var(--mint); font-weight: 800; font-size: 13px; }
.balance-pill svg { width: 17px; }
.user-menu { height: 42px; padding: 0 5px 0 6px; display: flex; align-items: center; gap: 9px; border: 0; background: transparent; cursor: pointer; }
.avatar { width: 34px; height: 34px; border-radius: 11px; background: var(--primary); color: white; display: grid; place-items: center; font-weight: 800; font-size: 13px; }
.user-copy { text-align: left; }
.user-copy strong { display: block; max-width: 145px; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.user-copy small { color: var(--muted); font-size: 10px; }

.main { margin-left: var(--sidebar); padding: 104px 34px 50px; min-height: 100vh; }
.page { max-width: 1320px; margin: 0 auto; animation: pageIn .28s ease both; }
@keyframes pageIn { from { opacity: 0; transform: translateY(5px); } }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.eyebrow { margin: 0 0 8px; color: var(--primary); font-size: 10px; font-weight: 800; letter-spacing: 2.2px; text-transform: uppercase; }
.page-heading h1 { margin: 0; font-size: clamp(28px, 3vw, 40px); line-height: 1.15; letter-spacing: -1.6px; font-weight: 760; }
.page-heading .subhead { margin: 9px 0 0; color: var(--muted); font-size: 13px; line-height: 1.7; max-width: 680px; }
.heading-actions { display: flex; gap: 10px; }

.btn { min-height: 40px; border-radius: 10px; border: 1px solid var(--line); padding: 0 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--surface); cursor: pointer; font-size: 13px; font-weight: 700; transition: .18s ease; }
.btn:hover { transform: translateY(-1px); border-color: var(--primary); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 8px 20px color-mix(in srgb, var(--primary) 24%, transparent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.btn svg { width: 17px; height: 17px; }

.studio-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(310px, .6fr); gap: 18px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.compose-panel { overflow: hidden; }
.compose-intro { min-height: 190px; padding: 31px 32px; background: #171728; color: #f8f8fc; position: relative; overflow: hidden; }
html[data-theme="dark"] .compose-intro { background: #1b1b31; }
.compose-intro::after { content: "M"; position: absolute; right: 15px; top: -46px; font-size: 220px; line-height: 1; font-weight: 900; color: rgba(255,255,255,.035); }
.compose-intro .eyebrow { color: #8ce3d2; }
.compose-intro h2 { margin: 0; font-size: clamp(27px, 3.5vw, 45px); letter-spacing: -2px; max-width: 620px; line-height: 1.12; }
.compose-intro p { margin: 14px 0 0; color: #a7a9bb; font-size: 13px; }
.compose-form { padding: 28px 32px 32px; }
.field { display: grid; gap: 8px; margin-bottom: 20px; }
.field > label, .field-label { font-size: 12px; font-weight: 750; }
.field small { color: var(--muted); font-size: 11px; }
input, textarea, select { width: 100%; color: var(--text); background: var(--surface-soft); border: 1px solid transparent; border-radius: 11px; outline: none; transition: .18s ease; }
input, select { height: 44px; padding: 0 13px; }
textarea { min-height: 138px; padding: 14px; resize: vertical; line-height: 1.65; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 3px var(--primary-soft); }
.prompt-wrap { position: relative; }
.char-count { position: absolute; right: 11px; bottom: 9px; font-size: 10px; color: var(--muted); }
.model-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.model-option { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 13px; cursor: pointer; text-align: left; }
.model-option strong { display: block; font-size: 12px; }
.model-option span { display: block; color: var(--muted); font-size: 10px; margin-top: 5px; }
.model-option.selected { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.submit-row { padding-top: 6px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.cost-note { font-size: 11px; color: var(--muted); }
.cost-note strong { color: var(--text); }

.aside-stack { display: grid; gap: 18px; }
.mini-panel { padding: 22px; }
.panel-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.panel-title h3 { margin: 0; font-size: 14px; }
.text-link { border: 0; background: transparent; color: var(--primary); font-size: 11px; font-weight: 700; cursor: pointer; padding: 0; }
.balance-block { padding: 23px; background: var(--primary-soft); border-radius: 13px; }
.balance-block small { color: var(--muted); font-size: 10px; }
.balance-block strong { display: block; margin: 8px 0 15px; font-size: 32px; letter-spacing: -1.6px; }
.balance-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }
.task-mini { display: grid; gap: 14px; }
.task-mini-item { display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; }
.task-thumb { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-soft); color: var(--primary); }
.task-thumb svg { width: 18px; }
.task-mini-item strong { display: block; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 185px; }
.task-mini-item small { color: var(--muted); font-size: 9px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; margin-bottom: 20px; }
.stat { padding: 23px 24px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 12px; }
.stat strong { font-size: 27px; letter-spacing: -1px; }
.stat small { margin-left: 7px; color: var(--mint); font-size: 10px; }

.data-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.data-toolbar { min-height: 62px; padding: 0 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; align-items: center; gap: 22px; height: 62px; }
.tab { height: 100%; padding: 0 2px; display: flex; align-items: center; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-size: 12px; font-weight: 700; cursor: pointer; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 15px 20px; text-align: left; border-bottom: 1px solid var(--line); font-size: 11px; vertical-align: middle; }
th { color: var(--muted); font-size: 9px; letter-spacing: .8px; text-transform: uppercase; font-weight: 800; background: var(--surface-soft); }
tr:last-child td { border-bottom: 0; }
td strong { font-size: 11px; }
.cell-main { max-width: 360px; }
.cell-main strong, .cell-main span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-main span { color: var(--muted); font-size: 9px; margin-top: 4px; }
.badge { display: inline-flex; align-items: center; gap: 6px; min-height: 24px; padding: 0 9px; border-radius: 20px; background: var(--surface-soft); color: var(--muted); font-size: 9px; font-weight: 800; text-transform: uppercase; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.succeeded, .badge.active, .badge.paid { color: var(--mint); background: var(--mint-soft); }
.badge.failed, .badge.suspended, .badge.revoked { color: var(--danger); background: var(--danger-soft); }
.badge.processing, .badge.submitting, .badge.pending { color: var(--warning); background: var(--warning-soft); }
.empty { min-height: 260px; display: grid; place-content: center; justify-items: center; text-align: center; padding: 36px; color: var(--muted); }
.empty svg { width: 34px; height: 34px; color: var(--primary); margin-bottom: 12px; }
.empty strong { color: var(--text); font-size: 13px; }
.empty p { font-size: 11px; max-width: 300px; line-height: 1.7; }

.wallet-hero { background: #171728; color: white; border-radius: var(--radius); padding: 32px 34px; display: flex; align-items: center; justify-content: space-between; min-height: 190px; margin-bottom: 18px; overflow: hidden; position: relative; }
.wallet-hero::after { content: "M"; position: absolute; right: 50px; font-size: 160px; font-weight: 900; color: rgba(255,255,255,.04); }
.wallet-hero small { color: #a7a9bb; font-size: 10px; letter-spacing: .7px; }
.wallet-hero strong { display: block; font-size: clamp(42px, 6vw, 68px); letter-spacing: -3px; margin: 6px 0 10px; }
.wallet-hero p { margin: 0; color: #a7a9bb; font-size: 11px; }
.wallet-actions { position: relative; z-index: 1; display: flex; gap: 10px; }
.wallet-actions .btn { background: white; color: #171728; border: 0; }
.independence-note { display: flex; align-items: flex-start; gap: 12px; padding: 15px 17px; margin-bottom: 18px; border: 1px solid color-mix(in srgb, var(--primary) 35%, var(--line)); border-radius: 12px; background: var(--primary-soft); }
.independence-note svg { flex: 0 0 auto; width: 18px; color: var(--primary); }
.independence-note strong { display: block; font-size: 11px; margin-bottom: 4px; }
.independence-note p { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.6; }
.recharge-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.amount { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 15px; cursor: pointer; text-align: left; }
.amount strong { display: block; font-size: 16px; }
.amount small { color: var(--muted); font-size: 9px; }
.amount.selected { border-color: var(--primary); background: var(--primary-soft); }

.developer-grid, .profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.code-block { margin: 0; padding: 18px; background: #171728; color: #d7daf0; border-radius: 12px; font: 11px/1.8 "SFMono-Regular", Consolas, monospace; overflow: auto; white-space: pre; }
.key-secret { padding: 13px 15px; border: 1px dashed var(--primary); background: var(--primary-soft); border-radius: 11px; font: 11px/1.7 monospace; overflow-wrap: anywhere; }
.setting-row { min-height: 70px; padding: 14px 0; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: 0; }
.setting-row strong { display: block; font-size: 12px; }
.setting-row small { display: block; color: var(--muted); font-size: 10px; margin-top: 4px; }
.identity-mark { width: 38px; height: 38px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 900; }

.admin-grid { display: grid; grid-template-columns: 1.1fr .9fr; gap: 18px; align-items: start; }
.admin-list { display: grid; }
.admin-item { padding: 15px 0; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.admin-item:last-child { border-bottom: 0; }
.admin-item strong { display: block; font-size: 11px; }
.admin-item small { color: var(--muted); font-size: 9px; }

.auth-page { min-height: 100vh; display: grid; grid-template-columns: minmax(380px, .85fr) minmax(500px, 1.15fr); background: var(--surface); }
.auth-brand { padding: 54px; background: #171728; color: white; position: relative; overflow: hidden; display: flex; flex-direction: column; }
.auth-brand::after { content: "M"; position: absolute; right: -40px; bottom: -90px; font-size: 420px; font-weight: 900; color: rgba(255,255,255,.025); line-height: 1; }
.auth-logo { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
.auth-logo img { width: 43px; }
.auth-logo strong { display: block; font-size: 17px; }
.auth-logo small { color: #85899f; font-size: 9px; letter-spacing: 2px; }
.auth-pitch { margin: auto 0; max-width: 500px; position: relative; z-index: 1; }
.auth-pitch .eyebrow { margin: 0 0 12px; color: #72d5c2; }
.auth-pitch h1 { margin: 0; font-size: clamp(42px, 5vw, 72px); line-height: 1.03; letter-spacing: -4px; }
.auth-main { display: grid; place-items: center; padding: 60px 28px; background: var(--bg); }
.auth-card { width: min(420px, 100%); }
.auth-card h2 { margin: 0; font-size: 29px; letter-spacing: -1.2px; }
.auth-card > p { color: var(--muted); font-size: 12px; line-height: 1.7; margin: 10px 0 28px; }
.auth-card .field { margin-bottom: 16px; }
.auth-card .btn { width: 100%; min-height: 46px; }
.divider { display: flex; align-items: center; gap: 13px; margin: 20px 0; color: var(--muted); font-size: 9px; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.milesapi-btn { background: var(--surface); }
.milesapi-btn .small-logo { width: 22px; height: 22px; border-radius: 7px; background: #16a893; color: white; display: grid; place-items: center; font-size: 10px; }
.auth-footer { margin-top: 24px; text-align: center; font-size: 11px; color: var(--muted); }
.auth-footer a { color: var(--primary); font-weight: 700; }
.theme-float { position: fixed; top: 20px; right: 20px; z-index: 10; }

.modal-backdrop { position: fixed; inset: 0; z-index: 80; background: rgba(10, 12, 20, .58); display: grid; place-items: center; padding: 20px; backdrop-filter: blur(5px); }
.modal { width: min(470px, 100%); max-height: 88vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 30px 80px rgba(0,0,0,.28); padding: 25px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.modal-head h3 { margin: 0; font-size: 19px; letter-spacing: -.5px; }
.modal-head p { margin: 6px 0 0; color: var(--muted); font-size: 10px; line-height: 1.6; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; }

.toast-region { position: fixed; top: 84px; right: 22px; z-index: 120; display: grid; gap: 9px; }
.toast { min-width: 280px; max-width: 390px; padding: 13px 15px; border: 1px solid var(--line); border-left: 3px solid var(--primary); border-radius: 11px; background: var(--surface); box-shadow: var(--shadow); font-size: 11px; animation: toastIn .22s ease both; }
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--mint); }
@keyframes toastIn { from { opacity: 0; transform: translateX(8px); } }

@media (max-width: 1040px) {
  :root { --sidebar: 82px; }
  .brand { justify-content: center; padding-inline: 0; }
  .brand-copy, .nav span, .nav-label, .side-note small, .side-note p span { display: none; }
  .nav a { justify-content: center; padding: 0; }
  .side-note { display: grid; place-items: center; }
  .studio-grid, .developer-grid, .profile-grid, .admin-grid { grid-template-columns: 1fr; }
  .auth-page { grid-template-columns: 1fr; }
  .auth-brand { min-height: 330px; padding: 34px; }
  .auth-pitch h1 { font-size: 48px; }
}

@media (max-width: 720px) {
  :root { --sidebar: 0px; }
  .sidebar { inset: auto 0 0 0; width: auto; height: 64px; border-right: 0; border-top: 1px solid var(--line); padding: 7px 10px; flex-direction: row; }
  .brand, .nav-label, .side-note, .nav-spacer, .nav a[href="/profile"], .nav a[href="/admin"] { display: none; }
  .nav { grid-template-columns: repeat(4, 1fr); width: 100%; }
  .nav a { display: grid; place-items: center; align-content: center; gap: 2px; min-height: 48px; }
  .nav a span { display: block; font-size: 8px; }
  .nav svg { width: 18px; height: 18px; }
  .topbar { left: 0; padding: 0 16px; height: 62px; }
  .top-title span, .user-copy, .top-actions .icon-button:first-child { display: none; }
  .main { margin-left: 0; padding: 86px 16px 94px; }
  .page-heading { align-items: flex-start; flex-direction: column; margin-bottom: 22px; }
  .page-heading h1 { font-size: 30px; }
  .compose-intro, .compose-form { padding: 24px 20px; }
  .model-options, .form-row { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat:nth-child(2) { border-right: 0; }
  .stat:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .wallet-hero { padding: 26px 22px; align-items: flex-start; flex-direction: column; gap: 22px; }
  .wallet-hero strong { font-size: 48px; }
  .recharge-grid { grid-template-columns: 1fr 1fr; }
  .auth-brand { min-height: 250px; padding: 25px; }
  .auth-pitch h1 { font-size: 37px; letter-spacing: -2px; }
  .auth-pitch p { margin-top: 13px; }
  .auth-main { padding: 42px 20px; }
}
