:root {
  --ink: #17251f;
  --muted: #6d7b75;
  --line: #dfe7e2;
  --canvas: #f3f6f3;
  --surface: #ffffff;
  --green: #1f7252;
  --green-2: #2b8a64;
  --green-soft: #e9f4ee;
  --coral: #e97655;
  --violet: #6f6ad8;
  --amber: #d58b27;
  --danger: #b44437;
  --shadow: 0 18px 60px rgba(24, 47, 38, .12);
}

* { box-sizing: border-box; }
html { font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; color: var(--ink); background: var(--canvas); }
body { margin: 0; min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 8px; color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.pulse-dot { width: 8px; height: 8px; border-radius: 99px; background: #51c38b; box-shadow: 0 0 0 5px rgba(81,195,139,.13); flex: 0 0 auto; }

.app-shell { display: grid; grid-template-columns: 244px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 24px 18px; color: #e9f2ed; background: #14251e; display: flex; flex-direction: column; gap: 24px; }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 16px; font-weight: 760; letter-spacing: .02em; }
.brand-mark { width: 48px; height: 48px; display: inline-grid; place-items: center; border-radius: 15px 15px 15px 5px; color: white; background: linear-gradient(145deg, #38a171, #1c6248); font-weight: 850; letter-spacing: -.04em; box-shadow: 0 12px 30px rgba(34,129,91,.28); }
.brand-mark.small { width: 36px; height: 36px; border-radius: 11px 11px 11px 4px; font-size: 13px; }
.sidebar nav { display: grid; gap: 7px; }
.nav-item { border: 0; width: 100%; padding: 11px 13px; border-radius: 10px; display: flex; gap: 11px; align-items: center; color: #aebdb6; background: transparent; text-align: left; font-size: 14px; }
.nav-item:hover, .nav-item.active { color: #fff; background: rgba(255,255,255,.08); }
.nav-item.active { box-shadow: inset 3px 0 #51c38b; }
.nav-item span { width: 18px; font-size: 17px; }
.nav-item.secondary { border-top: 1px solid rgba(255,255,255,.08); border-radius: 0; padding-top: 18px; }
.sidebar-spacer { flex: 1; }
.mode-card { padding: 15px; border: 1px solid rgba(119,190,157,.2); border-radius: 13px; background: rgba(44,106,78,.18); }
.mode-line { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.mode-card p { margin: 9px 0 0; color: #9fb0a8; font-size: 12px; line-height: 1.55; }

.main-content { padding: 38px clamp(28px, 4vw, 64px) 64px; overflow: hidden; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
h1 { margin: 0; font-size: clamp(29px, 3vw, 42px); letter-spacing: -.04em; }
.subtitle { margin: 10px 0 0; color: var(--muted); font-size: 14px; }
.header-actions { display: flex; align-items: center; gap: 14px; }
.observed-at { color: var(--muted); font-size: 12px; }
.outline-button, .primary-button, .table-action, .icon-button { border: 0; border-radius: 9px; font-weight: 700; transition: .18s ease; }
.outline-button { padding: 10px 14px; border: 1px solid #ccd8d1; color: var(--ink); background: #fff; }
.outline-button:hover { border-color: var(--green); color: var(--green); }
.primary-button { padding: 11px 17px; color: #fff; background: var(--green); box-shadow: 0 8px 18px rgba(31,114,82,.16); }
.primary-button:hover { background: #185f44; transform: translateY(-1px); }
.primary-button:disabled, .outline-button:disabled { opacity: .55; cursor: wait; transform: none; }
.full { width: 100%; display: flex; justify-content: space-between; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; margin-bottom: 22px; }
.stat-card { position: relative; min-height: 128px; padding: 19px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); overflow: hidden; }
.stat-card::before { content: ""; position: absolute; width: 74px; height: 74px; right: -20px; top: -25px; border-radius: 50%; background: var(--green-soft); }
.stat-card.coral::before { background: #fff0ea; }
.stat-card.violet::before { background: #efedff; }
.stat-card.mode { color: #edf7f1; background: #1b3429; border-color: #1b3429; }
.stat-card.mode::before { background: rgba(88,188,140,.13); }
.stat-label { display: block; color: var(--muted); font-size: 12px; font-weight: 700; }
.stat-card.mode .stat-label, .stat-card.mode small { color: #a8bbb2; }
.stat-card strong { display: block; margin: 13px 0 5px; font-size: 31px; line-height: 1; letter-spacing: -.03em; }
.stat-card.mode strong { font-size: 20px; margin-top: 19px; }
.stat-card small { color: #8a9691; font-size: 11px; }

.account-section { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); overflow: hidden; }
.section-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 20px 0; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 24px; }
.tab { padding: 0 1px 15px; border: 0; border-bottom: 2px solid transparent; color: var(--muted); background: transparent; font-weight: 700; }
.tab span { display: inline-grid; min-width: 22px; height: 20px; place-items: center; padding: 0 5px; border-radius: 10px; color: #708078; background: #edf2ef; font-size: 11px; }
.tab.active { color: var(--green); border-color: var(--green); }
.tab.active span { color: var(--green); background: var(--green-soft); }
.search-box { margin-bottom: 12px; min-width: 270px; display: flex; align-items: center; gap: 8px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: #f9fbfa; }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; }
.warning-banner { margin: 14px 20px 0; padding: 11px 13px; border-radius: 9px; color: #775419; background: #fff7e5; font-size: 12px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 13px 18px; color: #819087; background: #fafcfa; text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; }
td { padding: 15px 18px; border-top: 1px solid #edf1ee; color: #435149; font-size: 13px; }
tbody tr:hover { background: #fbfdfb; }
.account-name strong { display: block; color: var(--ink); font-size: 13px; }
.account-name small { display: block; margin-top: 4px; color: #8a9691; font-size: 11px; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }
.status-pill { display: inline-flex; padding: 5px 8px; border-radius: 6px; font-size: 11px; font-weight: 750; }
.configured { color: var(--green); background: var(--green-soft); }
.unconfigured { color: #766c57; background: #f1eee7; }
.readonly { color: #5650ba; background: #efedff; }
.table-action { padding: 7px 10px; color: var(--green); background: transparent; }
.table-action:hover { background: var(--green-soft); }
.empty-state { padding: 56px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--ink); }
.empty-state p { margin: 6px 0; font-size: 13px; }

.drawer-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(11,28,21,.38); backdrop-filter: blur(2px); }
.drawer { position: fixed; z-index: 21; top: 0; right: 0; width: min(780px, 94vw); height: 100vh; display: flex; flex-direction: column; background: #f8faf8; box-shadow: -20px 0 70px rgba(15,36,28,.2); transform: translateX(105%); transition: transform .28s cubic-bezier(.2,.8,.2,1); }
.drawer.open { transform: translateX(0); }
.drawer-header { padding: 23px 28px; display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid var(--line); background: #fff; }
.drawer-header h2 { margin: 0; font-size: 23px; letter-spacing: -.025em; }
.drawer-header .muted { margin: 6px 0 0; font-size: 12px; }
.icon-button { width: 36px; height: 36px; color: #67756e; background: #f0f3f1; font-size: 23px; }
.drawer-body { padding: 21px 28px 56px; overflow-y: auto; }
.quality-panel { padding: 16px 18px; margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.quality-panel .label { display: block; color: var(--muted); font-size: 11px; }
.quality-panel strong { display: block; margin-top: 5px; }
.quality-panel p { margin: 0; max-width: 420px; color: var(--muted); font-size: 12px; text-align: right; }
.quality-panel.pass { border-color: #acd9c3; background: #f0faf5; }
.quality-panel.fail { border-color: #edb8ae; background: #fff5f2; }
.quality-panel.unknown { border-color: #ead2a5; background: #fffaf0; }
.run-panel { padding: 16px 18px; margin-bottom: 16px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.run-panel.pass { border-color: #acd9c3; background: #f0faf5; }
.run-panel.fail { border-color: #edb8ae; background: #fff5f2; }
.run-panel.unknown { border-color: #ead2a5; background: #fffaf0; }
.run-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.run-heading .label { display: block; color: var(--muted); font-size: 11px; }
.run-heading strong { display: block; margin-top: 5px; }
.run-checks { margin-top: 12px; display: grid; gap: 7px; font-size: 11px; }
.run-check { display: flex; align-items: flex-start; gap: 8px; }
.run-mark { width: 17px; height: 17px; display: inline-grid; place-items: center; flex: 0 0 17px; border-radius: 50%; font-size: 10px; font-weight: 900; }
.run-check.ok .run-mark { color: white; background: var(--green); }
.run-check.blocked .run-mark { color: white; background: var(--danger); }
.drawer-section { padding: 21px; margin-bottom: 16px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.section-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.section-title h3 { margin: 0; font-size: 17px; }
.readonly-chip { padding: 5px 8px; border-radius: 6px; color: #5650ba; background: #efedff; font-size: 10px; font-weight: 800; }
.section-note { margin: -8px 0 17px; color: var(--muted); font-size: 12px; line-height: 1.65; }
.config-form { display: grid; gap: 15px; }
.field-grid { display: grid; gap: 14px; }
.field-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label { color: #425049; font-size: 12px; font-weight: 700; }
label input, label select, label textarea { width: 100%; margin-top: 7px; padding: 10px 11px; border: 1px solid #d5dfd9; border-radius: 8px; outline: 0; color: var(--ink); background: #fbfcfb; font-weight: 500; }
label input:focus, label select:focus, label textarea:focus { border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(43,138,100,.1); background: white; }
label small { display: block; margin-top: 5px; color: #96a19b; font-size: 10px; font-weight: 500; }
.lock-summary { min-height: 43px; padding: 9px 11px; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; border: 1px dashed #cbd8d1; border-radius: 9px; color: var(--muted); background: #f8fbf9; font-size: 11px; }
.lock-item { padding: 5px 8px; border-radius: 6px; color: var(--green); background: var(--green-soft); }
.lock-alert { color: #8b5e1a; }
.takeover-toggle { padding: 13px; display: flex; align-items: flex-start; gap: 11px; border: 1px solid #d5dfd9; border-radius: 10px; background: #f9fbfa; }
.takeover-toggle input { width: 17px; margin: 2px 0 0; }
.takeover-toggle span { display: grid; gap: 3px; }
.takeover-toggle small { margin: 0; line-height: 1.45; }
.form-actions { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.form-actions > span { font-size: 11px; }
.title-summary { margin-bottom: 12px; font-size: 11px; }
.title-list { display: grid; gap: 9px; }
.title-card { padding: 13px; display: grid; grid-template-columns: 29px minmax(0, 1fr) auto; gap: 11px; align-items: start; border: 1px solid #e4eae6; border-radius: 10px; }
.title-rank { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 8px; color: var(--green); background: var(--green-soft); font-size: 11px; font-weight: 800; }
.title-text { margin: 0; color: var(--ink); font-size: 13px; line-height: 1.55; }
.title-meta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 7px; color: var(--muted); font-size: 10px; }
.title-reason { display: block; margin-top: 7px; color: #89958f; font-size: 10px; line-height: 1.45; }
.recommendation { padding: 5px 7px; border-radius: 6px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.recommendation.reuse { color: var(--green); background: var(--green-soft); }
.recommendation.delivery_candidate { color: #6851a5; background: #f0ecfb; }
.recommendation.blocked_by_quality, .recommendation.avoid { color: var(--danger); background: #fff0ed; }
.recommendation.observe { color: #72664f; background: #f3f0e9; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: 28px; transform: translateX(-50%); padding: 11px 16px; border-radius: 9px; color: white; background: #203a2f; box-shadow: var(--shadow); font-size: 12px; }
.toast.error { background: #8f3d35; }

.login-page { display: grid; place-items: center; padding: 28px; color: white; background: #14251e; }
.login-shell { width: min(1040px, 100%); min-height: 620px; display: grid; grid-template-columns: 1.15fr .85fr; border: 1px solid rgba(255,255,255,.09); border-radius: 24px; background: radial-gradient(circle at 25% 20%, rgba(55,143,103,.25), transparent 34%), #192d24; overflow: hidden; box-shadow: 0 35px 100px rgba(0,0,0,.28); }
.login-story { padding: clamp(38px, 6vw, 76px); display: flex; flex-direction: column; align-items: flex-start; justify-content: center; }
.login-story .eyebrow { margin-top: 34px; color: #76cea4; }
.login-story h1 { margin: 4px 0 22px; font-size: clamp(38px, 5vw, 62px); line-height: 1.08; color: #f2f7f4; }
.login-copy { max-width: 500px; margin: 0; color: #acbbb4; line-height: 1.8; }
.safety-note { margin-top: 45px; display: flex; align-items: center; gap: 12px; color: #c7d5ce; font-size: 12px; }
.login-card { margin: 36px; padding: 42px; align-self: center; min-height: 470px; display: flex; flex-direction: column; justify-content: space-between; border-radius: 18px; color: var(--ink); background: white; box-shadow: var(--shadow); }
.login-card h2 { margin: 0; font-size: 26px; }
.login-card .muted { margin: 9px 0 0; font-size: 13px; }
.login-card form { display: grid; gap: 17px; margin: 34px 0; }
.form-error { min-height: 17px; margin: -7px 0; color: var(--danger); font-size: 12px; }
.login-foot { margin: 0; color: #98a49e; font-size: 10px; line-height: 1.6; }

@media (max-width: 1050px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .app-shell { grid-template-columns: 82px minmax(0, 1fr); }
  .sidebar { padding-inline: 12px; }
  .brand > span:last-child, .nav-item:not(.active) { font-size: 0; }
  .nav-item { justify-content: center; }
  .nav-item span { font-size: 18px; }
  .mode-card { display: none; }
}

@media (max-width: 720px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; padding: 12px 16px; }
  .sidebar nav { display: none; }
  .sidebar-spacer { flex: 1; }
  .nav-item.secondary { width: auto; border: 0; padding: 8px; font-size: 0; }
  .main-content { padding: 24px 14px 50px; }
  .page-header, .section-toolbar { align-items: stretch; flex-direction: column; }
  .header-actions { justify-content: space-between; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-card { min-height: 112px; }
  .search-box { min-width: 0; width: 100%; }
  .field-grid.two { grid-template-columns: 1fr; }
  .drawer-body, .drawer-header { padding-inline: 17px; }
  .quality-panel { align-items: flex-start; flex-direction: column; }
  .quality-panel p { text-align: left; }
  .login-page { padding: 0; }
  .login-shell { min-height: 100vh; display: block; border: 0; border-radius: 0; }
  .login-story { padding: 42px 25px 20px; }
  .login-story h1 { font-size: 38px; }
  .login-copy, .safety-note { display: none; }
  .login-card { margin: 20px; min-height: 430px; padding: 28px; }
}
