:root {
    --brand: #f28a18;
    --brand-dark: #c75d0a;
    --ink: #182334;
    --muted: #687487;
    --line: #dfe4ea;
    --soft: #f4f6f8;
    --panel: #ffffff;
    --navy: #183a59;
    --green: #16845b;
    --danger: #c43d3d;
    --shadow: 0 8px 24px rgba(25, 36, 52, 0.08);
    --sidebar: 220px;
    --topbar: 64px;
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    color: var(--ink);
    background: var(--soft);
    font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
    font-size: 14px;
    letter-spacing: 0;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.hidden { display: none !important; }
.muted { color: var(--muted); }

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-lockup strong { font-size: 17px; white-space: nowrap; }

.brand-mark {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 6px;
    background: var(--brand);
    color: #fff;
    font-size: 18px;
    font-weight: 700;
}

.topbar {
    position: fixed;
    z-index: 30;
    top: 0;
    right: 0;
    left: 0;
    display: flex;
    height: var(--topbar);
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    border-bottom: 1px solid var(--line);
    background: #fff;
}

.topbar-actions { display: flex; align-items: center; gap: 14px; }

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #aeb7c3;
}

.status-badge.ready .status-dot { background: var(--green); }
.status-badge.error .status-dot { background: var(--danger); }
.user-name { font-weight: 600; }

.icon-button {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #fff;
    color: var(--ink);
    font-size: 18px;
}

.icon-button:hover { border-color: var(--brand); color: var(--brand-dark); }

.sidebar {
    position: fixed;
    z-index: 20;
    top: var(--topbar);
    bottom: 0;
    left: 0;
    width: var(--sidebar);
    padding: 24px 14px;
    border-right: 1px solid var(--line);
    background: var(--navy);
}

.nav-item {
    display: flex;
    width: 100%;
    min-height: 46px;
    align-items: center;
    gap: 12px;
    margin-bottom: 5px;
    padding: 0 14px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: #cfd9e2;
    text-align: left;
}

.nav-item:hover, .nav-item.active { background: rgba(255,255,255,0.11); color: #fff; }
.nav-item.active { box-shadow: inset 3px 0 0 var(--brand); }
.nav-index { color: #8fa6b8; font-size: 11px; }
.nav-item.active .nav-index { color: #ffc16f; }

.main-content {
    min-height: 100vh;
    padding: calc(var(--topbar) + 28px) 28px 36px calc(var(--sidebar) + 28px);
}

.view { display: none; width: 100%; max-width: 1540px; margin: 0 auto; }
.view.active { display: block; }

.view-header, .section-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
}

.view-header h1, .section-heading h2 { margin: 2px 0 0; font-size: 26px; line-height: 1.3; }
.section-heading h2 { font-size: 20px; }
.eyebrow { margin: 0; color: var(--brand-dark); font-size: 11px; font-weight: 700; }
.header-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.button {
    min-height: 38px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: 4px;
    font-weight: 600;
}

.button.primary { border-color: var(--brand); background: var(--brand); color: #fff; }
.button.primary:hover { border-color: var(--brand-dark); background: var(--brand-dark); }
.button.secondary { border-color: var(--line); background: #fff; color: var(--ink); }
.button.secondary:hover { border-color: #aeb8c3; }
.button.text-button { min-height: 32px; padding: 0 8px; background: transparent; color: var(--brand-dark); }
.button:disabled { cursor: not-allowed; opacity: 0.48; }
.button.full { width: 100%; }

.editor-layout {
    display: grid;
    grid-template-columns: minmax(390px, 0.82fr) minmax(500px, 1.18fr);
    gap: 18px;
    align-items: stretch;
}

.form-panel, .result-panel, .resource-section, .cover-controls, .canvas-stage {
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
}

.form-panel { display: flex; flex-direction: column; gap: 18px; padding: 22px; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field { min-width: 0; }
.field label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 600; }

.field input, .field select, .field textarea, .auth-form input, .source-output {
    width: 100%;
    border: 1px solid #cfd6de;
    border-radius: 4px;
    background: #fff;
    color: var(--ink);
    outline: 0;
}

.field input, .field select, .auth-form input { height: 40px; padding: 0 11px; }
.field textarea, .source-output { min-height: 80px; padding: 10px 11px; line-height: 1.65; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .auth-form input:focus, .source-output:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(242,138,24,0.13); }
.field-hint { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }

.segmented { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; }
.segment {
    min-height: 40px;
    border: 1px solid #cfd6de;
    background: #fff;
    color: var(--muted);
}
.segment:first-child { border-radius: 4px 0 0 4px; }
.segment:last-child { border-radius: 0 4px 4px 0; }
.segment + .segment { border-left: 0; }
.segment.active { border-color: var(--brand); background: #fff7ed; color: var(--brand-dark); font-weight: 700; }
.segment.active + .segment { border-left: 1px solid var(--brand); }

.check-row { display: flex; align-items: flex-start; gap: 9px; line-height: 1.5; color: #4c5868; }
.check-row input { width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--brand); }

.result-panel { min-height: 650px; overflow: hidden; }
.result-toolbar { display: flex; height: 58px; align-items: center; justify-content: space-between; padding: 0 16px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; align-self: stretch; gap: 20px; }
.tab { position: relative; border: 0; background: transparent; color: var(--muted); font-weight: 600; }
.tab.active { color: var(--ink); }
.tab.active::after { position: absolute; right: 0; bottom: 0; left: 0; height: 3px; background: var(--brand); content: ""; }

.empty-state, .loading-state {
    display: flex;
    min-height: 590px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 30px;
    text-align: center;
}
.empty-state.compact { min-height: 260px; }
.empty-state h2, .loading-state h2 { margin: 14px 0 4px; font-size: 18px; }
.empty-state p, .loading-state p { margin: 0; color: var(--muted); }
.empty-number { color: #ccd3da; font-size: 56px; font-weight: 700; }

.spinner {
    width: 34px;
    height: 34px;
    border: 3px solid #e1e5e9;
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-content { min-height: 590px; }
.result-tab-pane { display: none; }
.result-tab-pane.active { display: block; }
.article-meta { padding: 22px 22px 16px; border-bottom: 1px solid var(--line); }
.article-meta h2 { margin: 0 0 8px; font-size: 20px; line-height: 1.45; }
.article-meta p { margin: 0; color: var(--muted); line-height: 1.65; }
.keyword-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.keyword-row span { padding: 4px 8px; border-radius: 3px; background: #edf3f6; color: var(--navy); font-size: 12px; }
#articlePreview { display: block; width: 100%; height: 440px; border: 0; background: #fff; }
.source-switch { display: flex; width: 210px; margin: 20px 20px 0; }
.source-switch .segment { flex: 1; }
.source-output { display: block; width: calc(100% - 40px); min-height: 470px; margin: 14px 20px 20px; font-family: Consolas, monospace; font-size: 13px; }
#result-checks { padding: 24px; }
#result-checks h2 { margin: 0 0 16px; font-size: 19px; }
.check-list { margin: 0; padding: 0; list-style: none; }
.check-list li { position: relative; margin-bottom: 10px; padding: 12px 14px 12px 38px; border: 1px solid var(--line); border-radius: 4px; line-height: 1.55; }
.check-list li::before { position: absolute; top: 12px; left: 14px; color: var(--green); content: "✓"; font-weight: 700; }
.notice-box { margin-top: 18px; padding: 13px 14px; border-left: 3px solid var(--brand); background: #fff7ed; line-height: 1.6; }

.resource-section { margin-top: 18px; padding: 20px 22px 22px; }
.resource-grid { display: grid; grid-template-columns: 1fr 1.5fr 180px; gap: 14px; }

.cover-layout { display: grid; grid-template-columns: 330px minmax(560px, 1fr); gap: 18px; }
.cover-controls { padding: 22px; }
.cover-controls .field { margin-bottom: 18px; }
.template-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.template-swatch { min-height: 64px; padding: 8px; border: 1px solid var(--line); border-radius: 4px; background: #fff; color: var(--ink); text-align: left; }
.template-swatch.active { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.swatch { display: block; height: 18px; margin-bottom: 7px; border-radius: 2px; }
.swatch.signal { background: linear-gradient(90deg, #f28a18 0 33%, #e84e3f 33% 66%, #183a59 66%); }
.swatch.tech { background: linear-gradient(90deg, #1358a5 0 33%, #18a9b8 33% 66%, #11263b 66%); }
.swatch.market { background: linear-gradient(90deg, #ffbf27 0 33%, #f26f1b 33% 66%, #2251a3 66%); }
.swatch.resource { background: linear-gradient(90deg, #16845b 0 33%, #ef6b52 33% 66%, #203a4d 66%); }
.cover-spec { display: grid; gap: 5px; padding: 13px; border: 1px solid var(--line); border-radius: 4px; background: var(--soft); color: var(--muted); font-size: 12px; }
.cover-spec strong { color: var(--ink); }
.canvas-stage { display: grid; min-height: 600px; place-items: center; padding: 24px; overflow: auto; background: #e8edf1; }
#coverCanvas { display: block; width: min(100%, 960px); height: auto; aspect-ratio: 3 / 2; background: #fff; box-shadow: var(--shadow); }

.draft-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.draft-card { display: flex; min-height: 190px; flex-direction: column; padding: 18px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.draft-card h2 { margin: 10px 0 8px; font-size: 17px; line-height: 1.45; }
.draft-card p { margin: 0 0 16px; color: var(--muted); line-height: 1.55; }
.draft-meta { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; }
.draft-actions { display: flex; gap: 8px; margin-top: auto; }
.draft-actions .button { flex: 1; }
.tag { display: inline-flex; align-self: flex-start; padding: 4px 7px; border-radius: 3px; background: #edf3f6; color: var(--navy); font-size: 12px; }
.tag.vip { background: #fff0df; color: var(--brand-dark); }

.guide-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.guide-grid section { position: relative; min-height: 210px; padding: 28px 28px 28px 82px; border-bottom: 1px solid var(--line); }
.guide-grid section:nth-child(odd) { border-right: 1px solid var(--line); }
.guide-grid section:nth-last-child(-n+2) { border-bottom: 0; }
.guide-grid h2 { margin: 0 0 10px; font-size: 18px; }
.guide-grid p { margin: 0; color: var(--muted); line-height: 1.8; }
.guide-number { position: absolute; top: 28px; left: 28px; color: var(--brand); font-size: 14px; font-weight: 700; }

.toast {
    position: fixed;
    z-index: 100;
    right: 24px;
    bottom: 24px;
    max-width: 360px;
    padding: 12px 16px;
    transform: translateY(20px);
    border-radius: 4px;
    background: var(--ink);
    color: #fff;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: var(--danger); }

.auth-body, .setup-shell { min-height: 100vh; }
.auth-shell, .setup-shell { display: grid; min-height: 100vh; place-items: center; padding: 28px; background: #eef2f4; }
.auth-panel, .setup-panel { width: min(100%, 420px); padding: 30px; border: 1px solid var(--line); border-radius: 6px; background: #fff; box-shadow: var(--shadow); }
.auth-panel h1, .setup-panel h1 { margin: 28px 0 7px; font-size: 25px; }
.auth-panel > p, .setup-panel > p { line-height: 1.7; }
.auth-form { display: grid; gap: 9px; margin-top: 24px; }
.auth-form label { margin-top: 6px; font-size: 13px; font-weight: 600; }
.auth-form .button { margin-top: 12px; }
.alert { margin-top: 18px; padding: 10px 12px; border-radius: 4px; }
.alert.error { border: 1px solid #efc2c2; background: #fff2f2; color: #9f2525; }
.setup-panel code { color: var(--brand-dark); }
.setup-panel pre { overflow: auto; padding: 12px; border-radius: 4px; background: #182334; color: #fff; }

@media (max-width: 1180px) {
    :root { --sidebar: 190px; }
    .editor-layout { grid-template-columns: 1fr; }
    .result-panel { min-height: 620px; }
    .cover-layout { grid-template-columns: 290px minmax(480px, 1fr); }
    .resource-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .resource-grid .small { grid-column: span 2; max-width: 220px; }
    .draft-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
    :root { --topbar: 58px; }
    .topbar { padding: 0 14px; }
    .topbar .brand-lockup strong { font-size: 14px; }
    .status-badge, .user-name { display: none; }
    .sidebar { top: var(--topbar); right: 0; bottom: auto; width: auto; height: 52px; padding: 6px 10px; border-right: 0; background: var(--navy); white-space: nowrap; overflow-x: auto; scrollbar-width: none; }
    .sidebar::-webkit-scrollbar { display: none; }
    .nav-item { display: inline-flex; width: auto; min-height: 40px; margin: 0 4px 0 0; padding: 0 12px; }
    .main-content { padding: calc(var(--topbar) + 76px) 14px 28px; }
    .view-header { align-items: flex-start; flex-direction: column; }
    .header-actions { width: 100%; }
    .header-actions .button { flex: 1; }
    .field-row, .resource-grid, .guide-grid { grid-template-columns: 1fr; }
    .resource-grid .small { grid-column: auto; max-width: none; }
    .cover-layout { grid-template-columns: 1fr; }
    .canvas-stage { min-height: 0; padding: 12px; }
    .draft-list { grid-template-columns: 1fr; }
    .guide-grid section, .guide-grid section:nth-child(odd), .guide-grid section:nth-last-child(-n+2) { border-right: 0; border-bottom: 1px solid var(--line); }
    .guide-grid section:last-child { border-bottom: 0; }
}

@media (max-width: 520px) {
    .main-content { padding-right: 10px; padding-left: 10px; }
    .view-header h1 { font-size: 23px; }
    .form-panel { padding: 16px; }
    .result-toolbar { align-items: flex-start; height: auto; padding: 0 10px; }
    .tabs { gap: 10px; min-height: 52px; overflow-x: auto; }
    .tab { white-space: nowrap; }
    .result-toolbar .text-button { align-self: center; }
    .article-meta { padding: 16px; }
    .template-grid { grid-template-columns: 1fr; }
    .auth-shell, .setup-shell { padding: 14px; }
    .auth-panel, .setup-panel { padding: 22px; }
}
