:root {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-soft: #f8f9fc;
    --text: #111827;
    --muted: #697386;
    --line: #e2e6ee;
    --brand: #315efb;
    --brand-dark: #2448d8;
    --danger: #b42318;
    --danger-bg: #fff1f0;
    --success: #067647;
    --success-bg: #ecfdf3;
    --warning: #9a6700;
    --warning-bg: #fff8db;
    --shadow: 0 18px 50px rgba(20, 28, 45, 0.08);
    --radius: 20px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at top left, #eef2ff 0, transparent 32rem), var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
body.modal-open { overflow: hidden; }
a { color: var(--brand); }
button, input, textarea, select { font: inherit; }
button, select { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

.topbar {
    max-width: 1440px;
    margin: 0 auto;
    padding: 28px 32px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}
.topbar h1 { margin: 5px 0 0; font-size: clamp(24px, 3vw, 38px); letter-spacing: -.04em; }
.eyebrow { color: var(--brand); font-size: 12px; font-weight: 800; letter-spacing: .16em; }
.admin-link {
    display: inline-flex;
    align-items: center;
    min-height: 42px;
    padding: 0 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255,255,255,.8);
    color: var(--text);
    text-decoration: none;
    font-weight: 700;
}

.page-shell, .admin-shell { max-width: 1440px; margin: 0 auto; padding: 16px 32px 60px; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(420px, .82fr); gap: 22px; align-items: stretch; }
.panel, .result-section, .admin-card {
    background: var(--surface);
    border: 1px solid rgba(220,225,235,.8);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.panel { padding: 24px; }
.panel-heading { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.panel-heading h2, .result-heading h2, .admin-card h2 { margin: 0; font-size: 22px; }
.panel-heading p, .admin-card p { margin: 5px 0 0; color: var(--muted); font-size: 14px; }
.step-badge {
    width: 38px; height: 38px; display: grid; place-items: center;
    border-radius: 12px; background: #eef2ff; color: var(--brand); font-weight: 900;
}

.drop-zone {
    min-height: 560px;
    border: 2px dashed #ccd3e1;
    border-radius: 18px;
    background: linear-gradient(145deg, #fbfcff, #f4f6fb);
    display: grid;
    place-items: center;
    overflow: hidden;
    transition: border-color .2s, background .2s, transform .2s;
}
.drop-zone:hover, .drop-zone.dragging { border-color: var(--brand); background: #f0f4ff; transform: translateY(-1px); }
.drop-zone.has-image { border-style: solid; background: #121722; }
.empty-preview { text-align: center; color: var(--muted); padding: 30px; display: grid; gap: 10px; }
.empty-preview strong { color: var(--text); font-size: 18px; }
.upload-icon { width: 64px; height: 64px; border-radius: 20px; background: #e9eeff; color: var(--brand); font-size: 38px; display: grid; place-items: center; margin: 0 auto 6px; }
.image-preview { width: 100%; height: 100%; max-height: 690px; object-fit: contain; }
.file-meta { display: flex; justify-content: space-between; gap: 15px; margin-top: 12px; color: var(--muted); font-size: 13px; }

.field-label, label > span { display: block; font-weight: 750; font-size: 14px; margin-bottom: 8px; }
textarea, input, select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}
textarea { padding: 14px; resize: vertical; line-height: 1.65; }
input, select { min-height: 44px; padding: 0 12px; }
textarea:focus, input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(49,94,251,.12); }
.char-counter { text-align: right; color: var(--muted); font-size: 12px; margin-top: 5px; }
.options-grid, .form-grid { display: grid; gap: 14px; }
.options-grid { grid-template-columns: 1fr 1fr; margin: 16px 0; }
.two-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three-cols { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.optimized-box { background: var(--surface-soft); border: 1px solid var(--line); border-radius: 15px; padding: 14px; margin: 18px 0; }
.optimized-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 13px; font-weight: 800; margin-bottom: 10px; }
.optimized-box textarea { background: #fff; }

.primary-button, .secondary-button, .primary-link {
    border-radius: 13px;
    min-height: 48px;
    padding: 0 18px;
    border: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-decoration: none;
    font-weight: 800;
}
.primary-button { width: 100%; flex-direction: column; background: var(--brand); color: white; box-shadow: 0 12px 24px rgba(49,94,251,.2); }
.primary-button:hover:not(:disabled), .primary-link:hover { background: var(--brand-dark); }
.primary-button small { font-size: 11px; opacity: .8; font-weight: 500; }
.primary-button.compact { width: auto; min-width: 130px; flex-direction: row; }
.primary-link { background: var(--brand); color: #fff; }
.secondary-button { background: #fff; color: var(--text); border: 1px solid var(--line); }
.text-button { border: 0; padding: 0; background: transparent; color: var(--brand); font-weight: 750; text-decoration: none; }

.status-box { display: flex; align-items: center; gap: 14px; margin-top: 15px; padding: 14px; background: #f0f4ff; border-radius: 13px; }
.status-box p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.spinner { width: 24px; height: 24px; border: 3px solid #cbd7ff; border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.notice { border-radius: 13px; padding: 14px 16px; margin-bottom: 18px; line-height: 1.55; }
.notice.error { color: var(--danger); background: var(--danger-bg); border: 1px solid #fecdca; }
.notice.success { color: var(--success); background: var(--success-bg); border: 1px solid #abefc6; }
.notice.warning { color: var(--warning); background: var(--warning-bg); border: 1px solid #f4dd83; }

.result-section { margin-top: 22px; padding: 24px; }
.result-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.result-actions, .admin-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.result-card { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; background: #10151f; border-radius: 16px; overflow: hidden; }
.result-card > img { width: 100%; max-height: 760px; object-fit: contain; display: block; }
.result-info { background: #fff; padding: 20px; }
.result-info p { color: var(--muted); }
.result-info pre { white-space: pre-wrap; word-break: break-word; font: inherit; line-height: 1.6; color: #344054; }
details summary { cursor: pointer; font-weight: 800; }

.modal { position: fixed; inset: 0; z-index: 50; background: rgba(5,8,15,.9); display: grid; place-items: center; padding: 36px; }
.modal[hidden] { display: none; }
.modal img { max-width: 96vw; max-height: 92vh; object-fit: contain; border-radius: 10px; }
.modal-close { position: absolute; top: 18px; right: 22px; width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(255,255,255,.3); background: rgba(0,0,0,.35); color: white; font-size: 28px; }

.admin-shell { max-width: 1120px; }
.admin-card { padding: 26px; }
.narrow-card { max-width: 820px; margin: 0 auto; }
.admin-card-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.settings-section { border-top: 1px solid var(--line); margin-top: 24px; padding-top: 22px; }
.settings-section h3 { margin: 0 0 15px; font-size: 17px; }
.settings-section > label, .form-grid label { display: block; margin-bottom: 14px; }
.admin-actions { margin-top: 24px; }
.admin-body .primary-button { margin-top: 18px; }

@media (max-width: 980px) {
    .workspace { grid-template-columns: 1fr; }
    .drop-zone { min-height: 420px; }
    .result-card { grid-template-columns: 1fr; }
    .result-info { order: -1; }
    .three-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    .topbar, .page-shell, .admin-shell { padding-left: 16px; padding-right: 16px; }
    .topbar { align-items: flex-start; }
    .admin-link { min-height: 38px; padding: 0 11px; font-size: 13px; }
    .panel, .result-section, .admin-card { padding: 17px; border-radius: 16px; }
    .drop-zone { min-height: 330px; }
    .options-grid, .two-cols, .three-cols { grid-template-columns: 1fr; }
    .result-heading { align-items: flex-start; flex-direction: column; }
    .result-actions { width: 100%; }
    .result-actions > * { flex: 1; }
    .modal { padding: 14px; }
}
