/* =====================================================================
   style.css — logicsim 现代化主题
   引入 CSS 变量、圆角、阴影、暗色模式、响应式布局。
   ===================================================================== */

:root {
    /* 布局尺寸 */
    --header-h: 200px;
    --bottom-h: 150px;
    --left-w: 180px;
    --right-w: 300px;
    --resize-w: 6px;
    --mini-w: 300px;

    /* 颜色（浅色） */
    --bg: #eef2f7;
    --surface: #ffffff;
    --surface-2: #f4f6fa;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e2e8f0;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --accent: #0ea5e9;
    --green: #16a34a;
    --green-hover: #15803d;
    --blue: #2563eb;
    --blue-hover: #1d4ed8;
    --amber: #f59e0b;
    --amber-hover: #d97706;
    --danger: #dc2626;
    --success: #16a34a;

    /* 阴影与圆角 */
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .10);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, .08), 0 2px 4px rgba(16, 24, 40, .06);
    --radius: 12px;
    --radius-sm: 8px;

    /* 字体 */
    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Microsoft YaHei", "Noto Sans SC", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", "Consolas",
        "Liberation Mono", Menlo, "Courier New", monospace;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #263449;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #334155;
    --primary: #818cf8;
    --primary-hover: #a5b4fc;
    --accent: #38bdf8;
    --green: #22c55e;
    --green-hover: #16a34a;
    --blue: #3b82f6;
    --blue-hover: #60a5fa;
    --amber: #fbbf24;
    --amber-hover: #f59e0b;
    --danger: #f87171;
    --success: #4ade80;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .3);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, .5), 0 3px 6px rgba(0, 0, 0, .4);
}

/* 首屏（JS 尚未设置 data-theme 时）跟随系统偏好 */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --bg: #0f172a;
        --surface: #1e293b;
        --surface-2: #263449;
        --text: #e2e8f0;
        --muted: #94a3b8;
        --border: #334155;
        --primary: #818cf8;
        --primary-hover: #a5b4fc;
        --accent: #38bdf8;
        --green: #22c55e;
        --green-hover: #16a34a;
        --blue: #3b82f6;
        --blue-hover: #60a5fa;
        --amber: #fbbf24;
        --amber-hover: #f59e0b;
        --danger: #f87171;
        --success: #4ade80;
    }
}

* { box-sizing: border-box; }

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-ui);
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
}

input, textarea, select {
    font-family: var(--font-mono);
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    font-size: 13px;
    outline: none;
    -webkit-user-select: text;
    user-select: text;
    transition: border-color .15s, box-shadow .15s;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, .18);
}

textarea { resize: vertical; }

/* ---- 顶层布局 ---- */
.joint-app {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    position: relative;
    background: var(--bg);
    color: var(--text);
}

.app-header {
    position: relative;
    flex: none;
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    z-index: 20;
}

.app-body {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ---- 迷你地图 ---- */
.mini-map {
    position: absolute;
    left: 0;
    top: 0;
    width: var(--mini-w);
    height: var(--header-h);
    box-sizing: border-box;
    border-right: 1px solid var(--border);
    background: var(--surface-2);
}

#mini-paper { position: absolute; }

#mini-view {
    border: 2px solid #31d0c6;
    position: absolute;
    background-color: rgba(250, 200, 200, 0.2);
    cursor: move;
}

#mini-resize {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 10px;
    height: 10px;
    cursor: nwse-resize;
    margin: 0 -7px -7px 0;
    border-radius: 50%;
    border: 2px solid #31d0c6;
    background-color: #fff;
}

/* ---- 工具栏 ---- */
.title-container {
    position: absolute;
    left: var(--mini-w);
    right: 0;
    top: 0;
    bottom: 0;
    box-sizing: border-box;
    background: var(--surface);
    overflow: auto;
}

.toolbar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 100%;
    padding: 10px 14px;
    box-sizing: border-box;
}

.toolbar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.toolbar-row.grow { flex: 1; min-height: 0; }

.spacer { flex: 1; }

.mode-select { min-width: 190px; }

.filename-input { width: 150px; }

.expr-input {
    flex: 1;
    min-height: 56px;
    font-size: 14px;
}

.model-details summary {
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
}

.model-area {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 6px;
}

.model-input {
    width: 100%;
    min-height: 90px;
    font-family: var(--font-mono);
}

.model-buttons { display: flex; gap: 8px; }

/* ---- 按钮 ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}

.btn:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(1px); }

.btn-green { background: var(--green); border-color: var(--green); color: #fff; }
.btn-green:hover { background: var(--green-hover); border-color: var(--green-hover); }

.btn-blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-blue:hover { background: var(--blue-hover); border-color: var(--blue-hover); }

.btn-parse { background: var(--amber); border-color: var(--amber); color: #fff; }
.btn-parse:hover { background: var(--amber-hover); border-color: var(--amber-hover); }

.btn-ghost { background: transparent; }
.btn-block { width: 100%; }

/* ---- 左侧组件面板 ---- */
.left-container {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--left-w);
    padding: 14px 12px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    overflow: auto;
    z-index: 10;
}

.panel-title {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .4px;
    text-transform: uppercase;
    color: var(--muted);
    margin: 14px 0 8px;
}

.left-container .panel-title:first-child { margin-top: 0; }

.component-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.component-list li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    font-size: 13px;
}

.legend-dot {
    flex: none;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, .18);
}

.var-list { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 12px;
    font-family: var(--font-mono);
}

.muted { color: var(--muted); font-size: 12px; }

/* ---- 画布 ---- */
.main-container {
    position: absolute;
    top: 0;
    left: var(--left-w);
    right: calc(var(--right-w) + var(--resize-w));
    bottom: var(--bottom-h);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    background: var(--surface-2);
}

#app-resize {
    position: absolute;
    top: 0;
    right: var(--right-w);
    bottom: var(--bottom-h);
    width: var(--resize-w);
    background: var(--border);
    cursor: ew-resize;
    border-radius: 3px;
}

#app-resize:hover { background: var(--danger); }

/* ---- 右侧检查器 ---- */
.right-container {
    position: absolute;
    top: 0;
    right: 0;
    bottom: var(--bottom-h);
    width: var(--right-w);
    padding: 14px 12px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    overflow: auto;
    z-index: 10;
}

.field { margin-bottom: 10px; }

.field label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
}

.field input, .field textarea { width: 100%; }
.field textarea { min-height: 48px; }

/* ---- 真值表 ---- */
.truth-table-wrap {
    max-height: 340px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.tt-meta { font-size: 12px; color: var(--muted); margin-bottom: 6px; }

.truth-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 13px;
}

.truth-table th, .truth-table td {
    padding: 5px 8px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.truth-table thead th {
    background: var(--surface);
    position: sticky;
    top: 0;
    font-weight: 700;
}

.tt-result { font-weight: 700; color: var(--primary); }

.truth-table tbody tr.tt-true td { background: rgba(34, 197, 94, .14); }
.truth-table tbody tr.tt-true .tt-result { color: var(--success); }

/* ---- 帮助文字 ---- */
.help-text {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.8;
    margin-top: 14px;
}

.help-text code {
    background: var(--surface-2);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 11px;
}

/* ---- 底部状态栏 ---- */
.bottom-container {
    position: absolute;
    left: var(--left-w);
    right: 0;
    bottom: 0;
    height: var(--bottom-h);
    display: flex;
    align-items: center;
    padding: 0 18px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    box-sizing: border-box;
    overflow: auto;
}

#status { margin: 0; font-size: 13px; color: var(--text); }

/* ---- 响应式 ---- */
@media (max-width: 900px) {
    .left-container { display: none; }
    .main-container { left: 0; }
    .bottom-container { left: 0; }
}

@media (max-width: 560px) {
    .mini-map { display: none; }
    .title-container { left: 0; }
}
