* { box-sizing: border-box; }

:root {
    --bg: #f5f5f4;
    --surface: #ffffff;
    --surface-muted: #f0efeb;
    --text: #111827;
    --muted: #6b7280;
    --line: rgba(0, 0, 0, 0.10);
    --line-strong: rgba(0, 0, 0, 0.16);
    --accent: #111827;
    --danger: #9b2c2c;
    --radius: 10px;
    --font: "PingFang SC", "Helvetica Neue", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.6 var(--font);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--text); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 13px; }

/* 布局 */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 200px;
    flex: 0 0 200px;
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}
.brand { font-size: 16px; font-weight: 600; letter-spacing: 0.02em; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a { padding: 8px 10px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.sidebar nav a:hover { background: var(--surface-muted); text-decoration: none; color: var(--text); }
.sidebar nav a.on { background: var(--surface-muted); color: var(--text); }
.sidebar-foot { margin-top: auto; display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

.main { flex: 1; min-width: 0; padding: 28px 32px 64px; }
.main h1 { font-size: 22px; margin: 0 0 20px; font-weight: 600; }

.plain-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.plain-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; }
.plain-head h1 { margin: 0 0 6px; font-size: 22px; }
.plain-head p { margin: 0 0 20px; color: var(--muted); font-size: 13px; }

/* 面板 */
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}
.panel h2 { font-size: 15px; margin: 0 0 14px; font-weight: 600; }
.panel-danger { border-color: rgba(155, 44, 44, 0.25); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-head h2 { margin: 0; }
.back { margin: 0 0 12px; font-size: 13px; color: var(--muted); }

/* 表单 */
.stack { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
label.full { grid-column: 1 / -1; }
label.checkbox { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
input[type="text"], input[type="number"], input[type="password"], select, textarea {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: 14px/1.5 var(--font);
    padding: 9px 10px;
    outline: none;
}
textarea { font-family: var(--mono); font-size: 13px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.form-actions { display: flex; gap: 10px; margin-top: 16px; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 180px; }
.inline { display: inline; }

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    padding: 0 14px;
    border-radius: 8px;
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--text);
    font: 500 13px/1 var(--font);
    cursor: pointer;
}
.btn:hover { background: var(--surface-muted); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #000; }
.btn-ghost { border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-muted); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-ghost { color: var(--danger); border-color: rgba(155, 44, 44, 0.3); background: transparent; }
.btn-block { width: 100%; }

/* 表格 */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; }
.table tr:last-child td { border-bottom: none; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.ellipsis { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 其他 */
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.tag-on { border-color: var(--line-strong); color: var(--text); background: var(--surface-muted); }
.hint { color: var(--muted); font-size: 12px; margin: 0 0 12px; }
.flash { padding: 10px 12px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; border: 1px solid var(--line); background: var(--surface-muted); }
.flash-error { border-color: rgba(155, 44, 44, 0.3); color: var(--danger); background: rgba(155, 44, 44, 0.05); }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 16px; margin: 0 0 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.code {
    background: #0f1115;
    color: #e5e5e5;
    border-radius: 8px;
    padding: 14px;
    font: 12px/1.7 var(--mono);
    overflow: auto;
    max-height: 420px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    margin: 0;
}
[hidden] { display: none !important; }

/* 可视化排版 */
.layout-actions { display: flex; align-items: center; gap: 10px; }
.layout-actions .hint { margin: 0; }
.layout-stage {
    position: relative;
    width: 100%;
    background: var(--surface-muted);
    border: 1px dashed var(--line-strong);
    border-radius: 10px;
    overflow: hidden;
}
.layout-surface { position: relative; transform-origin: top left; }
.layout-card {
    position: absolute;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 10px;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    cursor: grab;
    user-select: none;
    touch-action: none;
    overflow: hidden;
    box-sizing: border-box;
}
.layout-card:hover { border-color: var(--accent); }
.layout-card.dragging { cursor: grabbing; border-color: var(--accent); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14); z-index: 10; }
.layout-card.is-off { opacity: 0.45; }
.layout-card .lc-title {
    min-height: 18px;
    padding-right: 58px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.layout-card .lc-actions {
    position: absolute;
    top: 5px;
    right: 6px;
    display: flex;
    gap: 3px;
}
.layout-card .lc-action {
    padding: 2px 4px;
    border: 0;
    border-radius: 3px;
    background: var(--surface-muted);
    color: var(--muted);
    font: 10px/1.4 var(--font);
    cursor: pointer;
    touch-action: auto;
}
.layout-card .lc-action:hover { color: var(--accent); }
.layout-card .lc-action.lc-delete:hover { color: var(--danger); }
.layout-card .lc-action:disabled { cursor: wait; opacity: 0.5; }
.layout-card .lc-meta {
    font: 11px/1.4 var(--mono);
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.layout-resize {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 18px;
    height: 18px;
    cursor: nwse-resize;
    touch-action: none;
}
.layout-resize::after {
    content: '';
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    border-bottom-right-radius: 2px;
}

/* 历史弹窗 */
.modal-mask {
    position: fixed; inset: 0;
    background: rgba(17, 24, 39, 0.45);
    display: none; align-items: center; justify-content: center;
    z-index: 100; padding: 24px;
}
.modal-mask.open { display: flex; }
.modal {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    width: min(720px, 100%);
    max-height: 90vh; overflow: hidden;
    display: flex; flex-direction: column;
}
.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-close { background: none; border: 0; font-size: 18px; color: var(--muted); cursor: pointer; }
.modal-body { padding: 20px; overflow: auto; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.modal-foot .hint { margin-right: auto; font-size: 12px; }
.history-chart { width: 100%; height: 260px; }
.history-summary { font: 12px/1.6 var(--mono); color: var(--muted); margin-top: 8px; }
.history-meta { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.history-meta b { color: var(--text); font-weight: 600; }


@media (max-width: 720px) {
    .shell { flex-direction: column; }
    .sidebar { width: 100%; flex: none; flex-direction: row; align-items: center; gap: 16px; overflow-x: auto; }
    .sidebar nav { flex-direction: row; }
    .sidebar-foot { margin: 0 0 0 auto; }
    .main { padding: 20px 16px 48px; }
}
