:root {
  color-scheme: light;
  --nav: #0d1838;
  --nav-2: #142653;
  --ink: #15203a;
  --muted: #64718b;
  --line: #dce2ee;
  --line-dark: #c8d1e2;
  --surface: #ffffff;
  --canvas: #f3f6fb;
  --blue: #3f66ed;
  --purple: #6b4df4;
  --teal: #049f9a;
  --green: #17885c;
  --red: #c63d4f;
  --amber: #a56809;
  --shadow: 0 12px 30px rgba(20, 35, 70, .08);
  font-family: Inter, "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--canvas); color: var(--ink); }
body { min-width: 320px; font-size: 14px; }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-screen { min-height: 100vh; display: grid; grid-template-columns: minmax(300px, .8fr) minmax(420px, 1.2fr); background: #eef2f9; }
.login-brand { position: relative; display: flex; align-items: center; justify-content: center; gap: 20px; overflow: hidden; color: white; background: linear-gradient(145deg, #09132e 5%, #172c63 58%, #44289c 115%); }
.login-brand::before { content: ""; position: absolute; width: 330px; height: 330px; border: 1px solid rgba(91, 218, 219, .24); transform: rotate(34deg); box-shadow: inset 0 0 70px rgba(72, 109, 255, .14); }
.login-brand img { position: relative; width: 82px; height: 82px; border-radius: 8px; box-shadow: 0 24px 55px rgba(0, 0, 0, .3); }
.login-brand div { position: relative; display: grid; }
.login-brand strong { font-size: 30px; }
.login-brand span { margin-top: 5px; color: #b9c8ef; font-size: 16px; }
.login-panel { align-self: center; width: min(420px, calc(100% - 48px)); margin: 0 auto; padding: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.login-panel h1 { margin: 8px 0 6px; font-size: 29px; }
.login-panel p { margin: 0 0 28px; color: var(--muted); }
.login-panel label { display: grid; gap: 8px; margin-top: 18px; font-weight: 700; }
.login-panel input { height: 46px; padding: 0 13px; border: 1px solid var(--line-dark); border-radius: 6px; outline: none; }
.login-panel input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(63, 102, 237, .12); }
.form-message { min-height: 20px; margin: 14px 0 0 !important; color: var(--red) !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 246px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; z-index: 10; height: 100vh; display: flex; flex-direction: column; padding: 22px 16px; color: white; background: var(--nav); }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 22px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand img { width: 43px; height: 43px; border-radius: 7px; }
.brand div { display: grid; gap: 2px; }
.brand strong { font-size: 18px; }
.brand span { color: #9fafcf; font-size: 13px; }
.nav-list { display: grid; gap: 7px; padding-top: 23px; }
.nav-item { width: 100%; min-height: 46px; display: grid; grid-template-columns: 30px 1fr; align-items: center; text-align: left; color: #aebbd6; border: 1px solid transparent; border-radius: 6px; background: transparent; }
.nav-item span { color: #7284ad; font-size: 12px; }
.nav-item:hover { color: white; background: rgba(255,255,255,.05); }
.nav-item.active { color: white; border-color: rgba(106, 83, 244, .55); background: var(--nav-2); box-shadow: inset 3px 0 0 #7656ff; }
.nav-item.active span { color: #91a4ff; }
.sidebar-foot { margin-top: auto; display: grid; grid-template-columns: 10px 1fr; gap: 10px; align-items: center; padding: 18px 8px 2px; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-foot div { min-width: 0; display: grid; }
.sidebar-foot strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot small { margin-top: 3px; color: #8fa0c1; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #28d7a0; box-shadow: 0 0 0 4px rgba(40, 215, 160, .12); }

.workspace { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 8; height: 74px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 30px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.94); backdrop-filter: blur(12px); }
.topbar > div:first-of-type { display: grid; gap: 3px; }
.top-label { color: var(--muted); font-size: 12px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.balance-pill { padding: 8px 12px; color: #3155c5; border: 1px solid #cfd9fb; border-radius: 999px; background: #eef2ff; font-weight: 800; }
.mobile-menu { display: none !important; }
main { padding: 28px 30px 56px; }
.view { display: none; }
.view.active { display: block; }
.page-heading { min-height: 65px; display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 18px; }
.page-heading h1 { margin: 5px 0 0; font-size: 27px; line-height: 1.15; }
.eyebrow { color: var(--blue); font-size: 12px; font-weight: 900; }
.date-text { color: var(--muted); }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric { min-height: 126px; padding: 20px; border: 1px solid var(--line); border-top: 3px solid var(--blue); border-radius: 6px; background: var(--surface); box-shadow: 0 6px 20px rgba(20, 35, 70, .04); }
.metric:nth-child(2) { border-top-color: var(--teal); }
.metric:nth-child(3) { border-top-color: var(--green); }
.metric:nth-child(4) { border-top-color: var(--purple); }
.metric span, .metric small { display: block; color: var(--muted); }
.metric strong { display: block; margin: 10px 0 6px; font-size: 28px; }

.panel { overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); box-shadow: 0 7px 24px rgba(20, 35, 70, .04); }
.panel-heading { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-heading h2 { margin: 0 0 4px; font-size: 17px; }
.panel-heading p { margin: 0; color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 14px; text-align: left; border-bottom: 1px solid #e8ecf3; white-space: nowrap; }
th { color: #60708d; background: #f8f9fc; font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfe; }
.cell-main { display: block; color: var(--ink); font-weight: 750; }
.cell-sub { display: block; max-width: 230px; margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; }
.task-id { color: #3159d7; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.empty-row { padding: 34px 18px; color: var(--muted); text-align: center; }
.points-in { color: var(--green); font-weight: 800; }
.points-out { color: var(--red); font-weight: 800; }

.status { display: inline-flex; align-items: center; min-height: 25px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.status-success, .status-enabled { color: var(--green); background: #e9f8f1; }
.status-running, .status-reserved { color: #3159d7; background: #eaf0ff; }
.status-queued { color: #7b4d00; background: #fff4d7; }
.status-failed, .status-disabled { color: var(--red); background: #fff0f2; }
.status-owner { color: #6445d8; background: #f0edff; }
.status-employee { color: #176e79; background: #e9f7f8; }

.callout { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; padding: 13px 16px; border-left: 3px solid var(--teal); background: #eaf8f8; }
.callout strong { flex: 0 0 auto; }
.callout span { color: #4e657a; }
.key-grid, .model-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.key-card, .model-card { min-width: 0; padding: 18px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); box-shadow: 0 7px 24px rgba(20, 35, 70, .04); }
.key-top, .model-top { display: flex; justify-content: space-between; gap: 12px; }
.key-card h2, .model-card h2 { margin: 5px 0 3px; font-size: 17px; }
.key-card p, .model-card p { min-height: 40px; color: var(--muted); line-height: 1.55; }
.key-prefix { font-family: ui-monospace, Consolas, monospace; color: #3159d7; }
.quota-list { display: grid; gap: 11px; margin-top: 16px; padding-top: 15px; border-top: 1px solid var(--line); }
.quota-row { display: grid; grid-template-columns: 58px 1fr auto; align-items: center; gap: 10px; }
.quota-row > span, .quota-row > small { color: var(--muted); }
.bar { height: 7px; overflow: hidden; border-radius: 999px; background: #e8edf6; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), var(--teal)); }
.card-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.model-type { color: var(--blue); font-size: 11px; font-weight: 900; }
.model-price { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-top: 18px; padding-top: 15px; border-top: 1px solid var(--line); }
.model-price-copy { min-width: 0; }
.model-price-copy > span { display: block; margin-bottom: 3px; }
.model-price-copy > div { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px; }
.model-price strong { font-size: 21px; line-height: 1.1; }
.model-price small { color: var(--muted); white-space: nowrap; }
.model-price span { color: var(--muted); }
.pricing-details { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.pricing-details summary { color: #3159d7; cursor: pointer; font-weight: 800; }
.pricing-details > div { display: grid; gap: 7px; margin-top: 11px; }
.pricing-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; color: var(--muted); font-size: 12px; }
.pricing-row strong { color: var(--ink); text-align: right; font-size: 12px; }
.admin-model-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 15px; }
.admin-model-form label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
.admin-model-form .wide { grid-column: 1 / -1; }
.actual-billing-note { display: grid; gap: 4px; padding: 11px 12px; border: 1px solid #b8e7df; border-radius: 6px; background: #eefbf8; color: #11695d; font-size: 12px; }
.actual-billing-note strong { font-size: 13px; }
.tier-editor { display: grid; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: #f8faff; }
.tier-editor-head, .tier-editor-row { display: grid; grid-template-columns: minmax(150px, 1.4fr) 1fr 1fr; gap: 8px; align-items: center; }
.tier-editor-head { color: var(--muted); font-size: 11px; font-weight: 800; }
.tier-editor-row > span { min-width: 0; font-size: 12px; font-weight: 750; }
.tier-editor-row small { display: block; margin-top: 2px; color: var(--muted); font-weight: 400; }

.settings-band { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 22px; border-top: 1px solid var(--line); background: white; }
.settings-band:first-of-type { border-top: 0; }
.settings-band h2 { margin: 0 0 5px; font-size: 17px; }
.settings-band p { margin: 0; color: var(--muted); }
.release-form { width: min(620px, 65%); display: grid; grid-template-columns: 110px 1fr; gap: 8px; }
.release-form input { min-width: 0; height: 38px; padding: 0 10px; border: 1px solid var(--line-dark); border-radius: 6px; }
.release-form input[name="notes"] { grid-column: 1 / -1; }
.release-form label { display: flex; align-items: center; gap: 7px; }
.tag { padding: 6px 9px; color: var(--green); border: 1px solid #a8dbc5; border-radius: 999px; background: #effaf5; font-weight: 800; }

.primary-button, .secondary-button, .danger-button, .text-button, .icon-button { min-height: 38px; padding: 0 14px; border-radius: 6px; font-weight: 800; }
.primary-button { color: white; border: 0; background: linear-gradient(135deg, var(--blue), var(--purple)); box-shadow: 0 6px 16px rgba(73, 81, 226, .18); }
.primary-button:hover { filter: brightness(1.05); }
.secondary-button { color: #263656; border: 1px solid var(--line-dark); background: white; }
.danger-button { color: var(--red); border: 1px solid #f1b9c2; background: white; }
.text-button { min-height: 30px; padding: 0 7px; color: #3159d7; border: 0; background: transparent; }
.icon-button { width: 40px; padding: 0; color: var(--ink); border: 1px solid var(--line); background: white; }
.full { width: 100%; margin-top: 24px; }
button:disabled { cursor: not-allowed; opacity: .52; }

dialog { width: min(650px, calc(100% - 30px)); max-height: calc(100vh - 40px); overflow: auto; padding: 0; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); box-shadow: 0 30px 80px rgba(8, 18, 45, .28); }
dialog.wide-dialog { width: min(1180px, calc(100% - 30px)); }
.table-number-input { width: 110px; min-height: 34px; margin-bottom: 4px; }
dialog::backdrop { background: rgba(8, 17, 39, .58); backdrop-filter: blur(2px); }
dialog form, dialog > div { padding: 22px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.dialog-heading h2 { margin: 5px 0 0; font-size: 22px; }
.dialog-close { width: 36px; height: 36px; padding: 0; color: var(--muted); border: 1px solid var(--line); border-radius: 50%; background: white; font-size: 22px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid.single { grid-template-columns: 1fr; }
.form-grid label { display: grid; gap: 7px; font-weight: 750; }
.form-grid label small { color: var(--muted); font-weight: 400; }
#view-script-library .panel{padding:20px;margin-top:20px}#view-script-library textarea{font:inherit;padding:10px;border:1px solid var(--line-dark);border-radius:6px;min-height:80px;resize:vertical}#view-script-library select[multiple]{min-height:90px;width:100%;padding:8px}#view-script-library label:has(input[type=checkbox]){display:flex;align-items:center;gap:8px;margin:12px 0}#view-script-library input[type=checkbox]{width:18px;height:18px;margin:0;flex:0 0 auto}#libraryList .settings-band{padding:20px 0;align-items:flex-start}#libraryList form{display:grid;grid-template-columns:minmax(180px,1fr) minmax(180px,1fr);gap:10px;min-width:400px}#libraryList form>label:first-child{grid-row:span 3}#libraryList form button{grid-column:2}#libraryList .settings-band>div{max-width:48%}@media(max-width:850px){#libraryList form{min-width:0;width:100%}#libraryList .settings-band>div{max-width:100%}}
.form-grid .wide { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .admin-model-form input, .admin-model-form select { min-width: 0; height: 42px; padding: 0 11px; border: 1px solid var(--line-dark); border-radius: 6px; outline: none; background: white; }
.form-grid input:focus, .form-grid select:focus, .admin-model-form input:focus, .admin-model-form select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(63, 102, 237, .11); }
.record-toolbar { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; }
.record-toolbar input, .record-toolbar select { min-width: 180px; height: 40px; padding: 0 11px; border: 1px solid var(--line-dark); border-radius: 6px; background: white; }
.record-toolbar input { flex: 1; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 12px; color: var(--muted); }
.switch-line { grid-template-columns: auto 1fr !important; align-items: center; justify-content: start; }
.switch-line input { width: 18px; height: 18px; }
.field-label { display: block; margin-bottom: 8px; font-weight: 750; }
.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check-grid label { min-height: 42px; display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font-weight: 600; }
.check-grid input { width: 17px; height: 17px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.dialog-context { color: var(--muted); }
.secret-box { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 12px; border: 1px solid #cbd5ef; border-radius: 6px; background: #f4f7ff; }
.secret-box code { overflow-wrap: anywhere; color: #1f47bd; font-size: 13px; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 100; max-width: 420px; padding: 13px 16px; color: white; border-radius: 6px; background: #15203a; box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); pointer-events: none; transition: .18s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .key-grid, .model-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .login-screen { grid-template-columns: 1fr; }
  .login-brand { min-height: 180px; }
  .login-brand::before { width: 210px; height: 210px; }
  .login-brand img { width: 64px; height: 64px; }
  .app-shell { display: block; }
  .sidebar { position: fixed; left: -260px; width: 246px; transition: left .2s ease; box-shadow: 20px 0 45px rgba(8, 17, 39, .25); }
  .sidebar.open { left: 0; }
  .mobile-menu { display: inline-grid !important; place-items: center; }
  .topbar { height: auto; min-height: 70px; padding: 12px 16px; }
  .topbar > div:first-of-type { flex: 1; }
  .top-actions .balance-pill { display: none; }
  main { padding: 22px 16px 44px; }
  .metric-grid, .key-grid, .model-grid { grid-template-columns: 1fr; }
  .form-grid, .check-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .page-heading { min-height: 58px; }
  .settings-band, .callout { align-items: flex-start; flex-direction: column; }
  .release-form { width: 100%; grid-template-columns: 1fr; }
  .release-form input[name="notes"] { grid-column: auto; }
  .record-toolbar { align-items: stretch; flex-direction: column; }
  .record-toolbar input, .record-toolbar select, .record-toolbar button { width: 100%; }
  .model-price { align-items: flex-start; flex-direction: column; gap: 12px; }
  .tier-editor-head, .tier-editor-row { grid-template-columns: 1fr 90px 90px; }
}
