:root {
  --ink: #1e2722;
  --ink-soft: #445248;
  --muted: #738075;
  --line: #d8e0d8;
  --line-strong: #c5d0c5;
  --surface: #ffffff;
  --canvas: #f4f7f2;
  --side: #1d2c24;
  --side-soft: #2a3b31;
  --green: #137a50;
  --green-dark: #0b5c3a;
  --green-pale: #e2f0df;
  --yellow: #916a08;
  --yellow-pale: #fbf0ce;
  --red: #b63c36;
  --red-pale: #f8e1df;
  --shadow: 0 20px 45px rgba(33, 53, 38, .10);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; color: var(--ink); background: var(--canvas); font: 14px/1.55 "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: wait; }
.hidden { display: none !important; }
.skip-link { position: fixed; top: -100px; left: 12px; z-index: 30; padding: 8px 12px; color: #fff; background: var(--green-dark); border-radius: 4px; }
.skip-link:focus { top: 12px; }

/* Authentication state deliberately has no product sidebar. */
.shell { min-height: 100dvh; display: grid; grid-template-columns: 236px minmax(0, 1fr); }
.shell.login-state { display: block; min-height: 100dvh; }
.login-state .side { display: none; }
.side { display: flex; flex-direction: column; min-height: 100dvh; padding: 20px 14px 16px; color: #eef4ed; background: var(--side); }
.brand { display: flex; align-items: center; gap: 10px; padding: 5px 8px 28px; }
.brand-mark { display: grid; width: 33px; height: 33px; place-items: center; color: #173020; background: #d8efb8; border-radius: 5px; font-size: 17px; font-weight: 800; }
.brand strong { display: block; font-size: 16px; line-height: 1.2; }
.brand span { display: block; margin-top: 3px; color: #aabaae; font-size: 10px; letter-spacing: .08em; }
.nav { display: grid; gap: 3px; }
.nav-label { margin: 14px 9px 4px; color: #9cac9f; font-size: 11px; font-weight: 700; letter-spacing: .06em; }
.nav button { width: 100%; border: 0; border-radius: 5px; padding: 9px 11px; color: #c9d5cc; background: transparent; text-align: left; }
.nav button:hover { color: #eef5ed; background: rgba(255, 255, 255, .07); }
.nav button.active { color: #183221; background: #d8efb8; font-weight: 800; }
.side-bottom { margin-top: auto; padding: 14px 8px 2px; border-top: 1px solid rgba(255, 255, 255, .11); }
.identity { display: block; overflow: hidden; color: #c5d0c7; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.text-button { margin-top: 5px; padding: 0; border: 0; color: #d8efb8; background: transparent; font-size: 12px; }

.workspace { min-width: 0; }
.topbar { min-height: 92px; border-bottom: 1px solid var(--line); background: var(--surface); }
.topbar-inner { width: min(100% - 64px, 1360px); min-height: 92px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar-title h1 { margin: 1px 0 0; font-size: 22px; line-height: 1.2; font-weight: 700; }
.eyebrow { margin: 0; color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: .08em; }
.topbar-actions { display: flex; align-items: center; gap: 18px; }
.service-state { color: var(--muted); font-size: 12px; }
.service-state::before { display: inline-block; width: 7px; height: 7px; margin: 0 6px 1px 0; border-radius: 50%; background: #a6ada7; content: ""; }
.service-state.ok { color: var(--green-dark); }
.service-state.ok::before { background: var(--green); }
.service-state.bad { color: var(--red); }
.service-state.bad::before { background: var(--red); }
.topbar-link { padding: 0; border: 0; color: var(--green-dark); background: transparent; font-size: 13px; font-weight: 700; }
.topbar-link:hover { text-decoration: underline; text-underline-offset: 4px; }

/* Authentication */
.login-layout { width: min(100% - 40px, 460px); min-height: calc(100dvh - 92px); margin: 0 auto; display: grid; align-content: center; gap: 14px; padding: 52px 0 72px; }
.auth-frame { padding: 30px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); box-shadow: var(--shadow); }
.auth-heading { margin-bottom: 24px; }
.auth-heading h2 { margin: 6px 0 7px; font-size: 26px; line-height: 1.25; letter-spacing: 0; }
.auth-heading > p:last-child { max-width: 340px; margin: 0; color: var(--muted); font-size: 13px; }
.auth-tabs { display: flex; gap: 20px; margin: 0 0 22px; border-bottom: 1px solid var(--line); }
.auth-tab { position: relative; margin-bottom: -1px; padding: 0 0 10px; border: 0; color: var(--muted); background: transparent; font-size: 13px; }
.auth-tab.active { color: var(--green-dark); font-weight: 800; }
.auth-tab.active::after { position: absolute; right: 0; bottom: 0; left: 0; height: 2px; background: var(--green); content: ""; }
.form-stack { display: grid; gap: 15px; }
label { display: grid; gap: 6px; color: var(--ink-soft); font-size: 12px; font-weight: 700; }
input { width: 100%; min-height: 41px; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 4px; outline: none; color: var(--ink); background: #fff; }
input::placeholder { color: #a0aaa1; }
input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(19, 122, 80, .11); }
.primary, .secondary, .danger { min-height: 38px; padding: 8px 13px; border: 0; border-radius: 4px; font-size: 13px; font-weight: 800; }
.primary { color: #fff; background: var(--green); }
.primary:hover { background: var(--green-dark); }
.secondary { color: var(--green-dark); background: var(--green-pale); }
.secondary:hover { background: #d4e8d1; }
.danger { color: #fff; background: var(--red); }
.form-error { min-height: 19px; margin: 14px 0 0; color: var(--red); font-size: 12px; }
.auth-note { display: flex; gap: 11px; padding: 13px 15px; border: 1px solid #e4dfc9; border-radius: 5px; color: #605c4c; background: #fcfaf2; font-size: 12px; }
.auth-note span { flex: 0 0 auto; color: var(--yellow); font-weight: 800; }
.auth-note p { margin: 0; }
code { color: var(--green-dark); font-family: Consolas, monospace; font-weight: 700; }

/* Application state */
.app-view { width: min(100% - 64px, 1360px); margin: 0 auto; padding: 30px 0 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-head h2 { margin: 0; font-size: 21px; line-height: 1.25; }
.page-head p { margin: 5px 0 0; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { min-height: 104px; padding: 17px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.stat span { display: block; color: var(--muted); font-size: 12px; }
.stat strong { display: block; margin-top: 7px; font-size: 29px; font-variant-numeric: tabular-nums; }
.character-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(225px, 1fr)); gap: 12px; }
.character-card { min-height: 132px; padding: 17px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: var(--surface); text-align: left; }
.character-card:hover { border-color: #99c6a7; box-shadow: 0 10px 23px rgba(25, 74, 42, .09); }
.character-card strong { display: block; font-size: 16px; }
.character-card > span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.capacity { display: flex; justify-content: space-between; margin-top: 21px; padding-top: 11px; border-top: 1px solid var(--line); color: var(--green-dark); font-weight: 800; }
.capacity span { color: var(--muted); font-size: 12px; font-weight: 400; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
table { width: 100%; min-width: 680px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 11px 13px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: #58675c; background: #f1f5ef; font-size: 12px; font-weight: 800; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.muted { color: var(--muted); }
.item-title { display: block; font-weight: 800; }
.item-id { display: block; max-width: 380px; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.tag { display: inline-block; padding: 2px 7px; border-radius: 3px; color: #506052; background: #ebefea; font-size: 11px; font-weight: 800; }
.tag.done { color: #16643f; background: #dff1d9; }
.tag.failed { color: #962f2a; background: var(--red-pale); }
.tag.waiting { color: #836000; background: var(--yellow-pale); }
.toolbar { display: flex; align-items: center; gap: 8px; }
.toolbar input { min-width: 190px; }
.inline-actions { display: flex; align-items: center; gap: 6px; }
.inline-actions .primary, .inline-actions .secondary, .inline-actions .danger { min-height: 31px; padding: 5px 8px; font-size: 12px; }
.empty { padding: 52px 18px; border: 1px dashed var(--line-strong); border-radius: 6px; color: var(--muted); background: rgba(255,255,255,.45); text-align: center; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 20; max-width: min(380px, calc(100vw - 40px)); padding: 11px 14px; border-radius: 5px; color: #fff; background: #29342c; box-shadow: var(--shadow); }
.toast.bad { background: var(--red); }

@media (max-width: 820px) {
  .shell { display: block; }
  .side { min-height: auto; padding: 13px 14px; }
  .brand { padding: 3px 5px 12px; }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-label, .side-bottom { display: none; }
  .topbar { min-height: 78px; }
  .topbar-inner { width: min(100% - 32px, 1360px); min-height: 78px; }
  .topbar-title h1 { font-size: 19px; }
  .topbar-actions { gap: 10px; }
  .service-state { display: none; }
  .login-layout { width: min(100% - 28px, 460px); min-height: calc(100dvh - 78px); padding: 28px 0 46px; }
  .auth-frame { padding: 23px 20px; }
  .app-view { width: min(100% - 32px, 1360px); padding-top: 22px; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .toolbar { width: 100%; flex-wrap: wrap; }
  .toolbar input { flex: 1 1 180px; min-width: 0; }
}
