/* =====================================================================
 * LogicSim · 现代化界面样式
 * 支持浅色 (默认) / 深色主题，通过 html.dark-theme 或 body.dark-theme 切换
 * ================================================================== */

@font-face {
    font-family: 'TsangerYuYangT03';
    src: url('./lib/TsangerYuYangT-W03.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

/* ---------- 主题变量 ---------- */
:root {
    --bg: #eef2f9;
    --bg-grad-1: #eef4ff;
    --bg-grad-2: #e6ecf7;
    --surface: #ffffff;
    --surface-2: #f6f8fc;
    --surface-3: #eef2f9;
    --border: #d8e0ee;
    --border-strong: #c2cddf;
    --text: #16202f;
    --text-soft: #5a6a80;
    --text-mute: #8896ab;
    --accent: #4a6cf7;
    --accent-2: #7c3aed;
    --accent-soft: #e8edff;
    --success: #16a34a;
    --success-soft: #dcfce7;
    --primary: #2563eb;
    --primary-soft: #dbeafe;
    --shadow: 0 10px 30px rgba(23, 43, 77, 0.10);
    --shadow-sm: 0 2px 8px rgba(23, 43, 77, 0.08);
    --radius: 12px;
    --radius-sm: 8px;
    --grid-bg: rgba(150, 250, 200, 0.28);
    color-scheme: light;
}

.dark-theme {
    --bg: #0d1220;
    --bg-grad-1: #111a2e;
    --bg-grad-2: #0b101c;
    --surface: #161f33;
    --surface-2: #1b2740;
    --surface-3: #121a2b;
    --border: #2a3855;
    --border-strong: #3a4c6e;
    --text: #e7eefb;
    --text-soft: #aab8d0;
    --text-mute: #7d8cab;
    --accent: #7c9cff;
    --accent-2: #a78bfa;
    --accent-soft: #1e2b48;
    --success: #34d399;
    --success-soft: #113a2e;
    --primary: #60a5fa;
    --primary-soft: #122a4d;
    --shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.35);
    --grid-bg: rgba(30, 30, 30, 0.25);
    color-scheme: dark;
}

/* ---------- 基础 ---------- */
html,
body,
.joint-app {
    position: relative;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    -webkit-user-select: none;
    -moz-user-select: -moz-none;
    user-select: none;
    font-family: TsangerYuYangT03, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
    overflow: hidden;
    color: var(--text);
    background: linear-gradient(160deg, var(--bg-grad-1), var(--bg-grad-2));
    transition: background-color .25s ease, color .25s ease;
}

.joint-app {
    display: flex;
    flex-direction: column;
}

/* ---------- 顶部区域 ---------- */
.app-header {
    position: relative;
    flex: 0 0 auto;
    width: 100%;
    height: 258px;
    overflow: hidden;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    z-index: 20;
    transition: background-color .25s ease, border-color .25s ease;
}

.mini-map {
    position: absolute;
    left: 0;
    top: 0;
    display: inline-block;
    width: 300px;
    height: 100%;
    padding: 0;
    background: var(--surface-3);
    border-right: 1px solid var(--border);
    box-sizing: border-box;
}

#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 var(--accent);
    background-color: var(--surface);
}

.title-container {
    position: absolute;
    top: 0;
    left: 300px;
    right: 0;
    bottom: 0;
    box-sizing: border-box;
    background: var(--surface-2);
    overflow: auto;
    padding: 12px 16px;
}

/* ---------- 顶栏 ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.brand-mark {
    color: var(--accent);
    font-size: 18px;
    line-height: 1;
}

.brand-name {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: .3px;
}

.brand-sub {
    font-size: 12px;
    color: var(--text-mute);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

/* ---------- 主题按钮 ---------- */
.icon-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform .15s ease, background-color .2s ease, border-color .2s ease, color .2s ease;
}

.icon-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-1px);
}

.icon-btn:active {
    transform: translateY(0);
}

.theme-icon {
    font-size: 15px;
    line-height: 1;
}

/* ---------- 工具栏栅格 ---------- */
.toolbar-grid {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) minmax(300px, 1.15fr);
    gap: 12px;
    align-items: start;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px 12px;
    box-shadow: var(--shadow-sm);
    transition: background-color .25s ease, border-color .25s ease;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.panel-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: .2px;
}

.hint-badge {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .5px;
    text-transform: uppercase;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: 999px;
    padding: 2px 8px;
}

/* ---------- 表单控件 ---------- */
.field {
    width: 100%;
    box-sizing: border-box;
    padding: 7px 10px;
    font-family: inherit;
    font-size: 13px;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease, background-color .2s ease;
}

.field:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.field.code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 12.5px;
    line-height: 1.55;
    resize: vertical;
    white-space: pre;
    overflow: auto;
}

#ReversePol {
    height: 62px;
}

.model-field {
    height: 96px;
    margin-bottom: 8px;
}

.field-inline {
    flex: 1 1 auto;
    min-width: 90px;
    width: auto;
}

.field-label {
    display: block;
    margin: 10px 0 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-soft);
}

#ERMemo {
    height: 76px;
    resize: vertical;
}

/* ---------- 按钮 ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    color: #fff;
    background: var(--surface-3);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
    transition: transform .12s ease, filter .15s ease, background-color .2s ease, box-shadow .2s ease;
}

.btn:hover {
    filter: brightness(1.06);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn:active {
    transform: translateY(0);
    filter: brightness(.96);
}

.btn-block {
    width: 100%;
}

.btn-success {
    background: linear-gradient(135deg, #16a34a, #22c55e);
    color: #fff;
}

.btn-primary {
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    color: #fff;
}

.btn-accent {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
}

.btn-file {
    position: relative;
    overflow: hidden;
}

.btn-file input[type=file] {
    position: absolute;
    inset: 0;
    margin: 0;
    padding: 0;
    font-size: 20px;
    cursor: pointer;
    opacity: 0;
    filter: alpha(opacity=0);
}

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

.file-row .btn {
    flex: 0 0 auto;
}

/* ---------- 主工作区 ---------- */
.app-body {
    position: relative;
    flex: 1 1 auto;
    height: calc(100% - 258px);
    min-height: 0;
}

.left-container {
    position: absolute;
    left: 0;
    top: 0;
    width: 10px;
    height: 100%;
    overflow: auto;
    background: var(--surface-3);
    border-right: 1px solid var(--border);
    z-index: 10;
}

.main-container {
    position: absolute;
    top: 0;
    left: 10px;
    right: 306px;
    bottom: 150px;
    overflow: hidden;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-sizing: border-box;
    box-shadow: var(--shadow-sm);
    background: var(--surface-3);
}

#paper-container {
    position: relative;
}

#app-resize {
    position: absolute;
    top: 0;
    right: 300px;
    bottom: 150px;
    width: 6px;
    background: transparent;
    cursor: ew-resize;
    z-index: 12;
}

.resize-grip {
    position: absolute;
    top: 50%;
    left: -14px;
    width: 28px;
    height: 30px;
    transform: translateY(-50%);
    background-image: url(assets/box-arrow-in-right.svg);
    background-size: 100%;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 6px;
    cursor: pointer;
    opacity: .85;
    transition: background-color .2s ease, opacity .2s ease;
}

.resize-grip:hover {
    opacity: 1;
    background-color: var(--accent-soft);
}

/* ---------- 属性检查器 ---------- */
.right-container {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 150px;
    width: 300px;
    box-sizing: border-box;
    overflow: auto;
    padding: 12px 14px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    transition: background-color .25s ease, border-color .25s ease;
}

.inspector-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 8px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.help-box {
    margin-top: 14px;
    padding: 10px 12px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-soft);
    background: var(--surface-2);
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
}

.help-box p {
    margin: 0 0 6px;
}

.help-box ul {
    margin: 0 0 6px;
    padding-left: 18px;
}

.help-box li {
    margin: 2px 0;
}

.help-box code {
    padding: 1px 5px;
    font-family: "SFMono-Regular", Consolas, Menlo, monospace;
    font-size: 11.5px;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: 4px;
}

/* ---------- 状态栏 ---------- */
.bottom-container {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 10px;
    width: auto;
    height: 150px;
    padding: 10px 16px;
    box-sizing: border-box;
    background: var(--surface);
    border-top: 1px solid var(--border);
    overflow: auto;
    z-index: 10;
    transition: background-color .25s ease, border-color .25s ease;
}

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

/* ---------- 滚动条 ---------- */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border: 2px solid transparent;
    background-clip: content-box;
    border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
    background-clip: content-box;
}

/* ---------- 深色主题局部修正 ---------- */
.dark-theme .btn-success {
    background: linear-gradient(135deg, #059669, #10b981);
}

.dark-theme .btn-primary {
    background: linear-gradient(135deg, #1d4ed8, #3b82f6);
}

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
    .app-header {
        height: auto;
        max-height: 70vh;
        overflow: auto;
    }

    .mini-map {
        display: none;
    }

    .title-container {
        position: static;
        padding: 10px;
    }

    .toolbar-grid {
        grid-template-columns: 1fr;
    }

    .app-body {
        height: auto;
        min-height: 400px;
    }

    .main-container {
        right: 8px;
        bottom: 8px;
    }

    .right-container,
    #app-resize,
    .bottom-container {
        display: none;
    }
}