:root {
    --bg: #eceef1;
    --surface: #ffffff;
    --surface-2: #f4f5f7;
    --hover: #f0f1f4;
    --selected: #eef0f3;
    --line: #e7e9ed;
    --ink: #1f2023;
    --ink-2: #5d6168;
    --ink-3: #9a9ea6;
    --accent: #ffdb4d;
    --accent-hover: #ffd21f;
    --accent-soft: #fff2bf;
    --link: #1a6dd8;
    --danger: #e5484d;
    --brand: #ff0000;
    --select: #4c9dff;
    --radius: 16px;
    --rail-w: 60px;
    --shadow: 0 12px 40px rgba(20, 24, 31, .16);
    --dock-shadow: 0 8px 28px rgba(20, 24, 31, .12);
    color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0; background: var(--bg); color: var(--ink);
    font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; flex: none; }
a { color: var(--link); }
[hidden], .hidden { display: none !important; }
.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }
.spinner {
    width: 28px; height: 28px; border-radius: 50%;
    border: 3px solid rgba(0, 0, 0, .08); border-top-color: var(--ink-2);
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.boot { position: fixed; inset: 0; display: grid; place-items: center; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 36px; padding: 0 16px; border-radius: 10px; border: 0;
    background: var(--surface-2); font-weight: 550;
}
.btn:hover { background: var(--hover); }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); color: #1b1b1b; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-link { background: none; color: var(--ink-2); height: auto; padding: 8px; }
.icon-btn {
    display: inline-grid; place-items: center; width: 32px; height: 32px;
    border: 0; border-radius: 8px; background: none; color: var(--ink-2);
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.on svg { color: #e0a800; }
.input {
    width: 100%; height: 42px; padding: 0 14px; border-radius: 10px;
    border: 1px solid var(--line); background: var(--surface); outline: none;
}
.input:focus { border-color: #c9ccd2; box-shadow: 0 0 0 3px rgba(255, 219, 77, .45); }

.login {
    min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 32px 16px;
}
.login-card {
    width: 100%; max-width: 380px; background: var(--surface); border-radius: 20px;
    padding: 32px 28px 24px; box-shadow: 0 10px 30px rgba(0, 0, 0, .06); text-align: center;
}
.login-brand h1 { margin: 12px 0 4px; font-size: 22px; font-weight: 650; }
.login-brand p { margin: 0 0 22px; }
.login-logo { width: 44px; height: 48px; }
.login-checking { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 24px 0; }
.login-profile { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.login-avatar {
    width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
    background: var(--accent-soft); font-size: 22px; font-weight: 600; margin-bottom: 8px; overflow: hidden;
}
.login-avatar img { width: 100%; height: 100%; object-fit: cover; }
.login-profile-name { font-size: 17px; font-weight: 600; }
.login-profile-phone { margin-bottom: 16px; }
.login-tabs { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 16px; }
.login-tab { flex: 1; height: 32px; border: 0; border-radius: 8px; background: none; color: var(--ink-2); font-weight: 500; }
.login-tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.login-panel { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.login-panel p { margin: 0; }
.qr-box {
    width: 232px; height: 232px; display: grid; place-items: center;
    border: 1px solid var(--line); border-radius: 14px; padding: 12px;
}
.qr-box img, .qr-box canvas, .qr-box svg { width: 100% !important; height: auto !important; display: block; }
.login-status { min-height: 18px; margin: 14px 0 0; }
.login-error { margin: 10px 0 0; color: var(--danger); font-size: 13px; }
.login-foot { margin-top: 18px; display: flex; align-items: center; justify-content: center; gap: 12px; }

.app { display: flex; height: 100vh; height: 100dvh; padding: 8px 8px 8px 0; }
.rail {
    width: var(--rail-w); flex: none; display: flex; flex-direction: column; align-items: center;
    padding: 6px 0 4px;
}
.rail-logo { display: grid; place-items: center; width: 40px; height: 40px; margin-bottom: 14px; }
.rail-logo img { width: 26px; height: 28px; }
.rail-services { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.rail-item {
    position: relative; display: grid; place-items: center; width: 40px; height: 40px;
    border-radius: 12px; color: #4a4e55; text-decoration: none;
}
.rail-item svg { width: 21px; height: 21px; }
.rail-item:hover { background: rgba(0, 0, 0, .06); color: var(--ink); }
.rail-item.active { background: var(--surface); color: var(--brand); box-shadow: 0 1px 4px rgba(0, 0, 0, .06); }
.rail-item .tip {
    position: absolute; left: 48px; top: 50%; transform: translateY(-50%); white-space: nowrap;
    background: #2a2c31; color: #fff; font-size: 12px; padding: 4px 9px; border-radius: 6px;
    opacity: 0; pointer-events: none; z-index: 30;
}
.rail-item:hover .tip { opacity: 1; }
.rail-bottom { margin-top: auto; position: relative; }
.rail-avatar, .user-avatar {
    width: 34px; height: 34px; border-radius: 50%; border: 0; padding: 0; overflow: hidden;
    display: grid; place-items: center; background: var(--accent-soft);
    font-size: 13px; font-weight: 600; color: #5a4700;
}
.rail-avatar img, .user-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.user-avatar { width: 44px; height: 44px; font-size: 16px; }
.user-menu {
    position: absolute; left: 46px; bottom: 0; width: 230px; background: var(--surface);
    border-radius: 14px; box-shadow: var(--shadow); padding: 12px; z-index: 40;
}
.user-menu-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.user-menu-name { font-weight: 600; }
.user-menu-item {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border: 0;
    border-radius: 8px; background: none; text-align: left;
}
.user-menu-item:hover { background: var(--hover); }
.workspace {
    flex: 1; min-width: 0; display: flex; background: var(--surface); border-radius: var(--radius);
    overflow: hidden; box-shadow: 0 1px 2px rgba(0, 0, 0, .04); position: relative;
}

.cabinet { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 22px 28px 28px; }
.cabinet-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-end; margin-bottom: 18px; }
.cabinet-head h2 { margin: 0; font-size: 26px; font-weight: 650; }
.cabinet-head p { margin: 4px 0 0; }
.cabinet-actions { display: flex; align-items: center; gap: 8px; }
.search {
    display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px;
    background: var(--surface-2); border-radius: 10px; color: var(--ink-3);
}
.search svg { width: 16px; height: 16px; }
.search input { border: 0; outline: none; background: none; width: 180px; color: var(--ink); }
.board-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; overflow: auto; }
.board-card {
    text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 14px;
    padding: 0; overflow: hidden; display: flex; flex-direction: column; min-height: 168px;
}
.board-card:hover { border-color: #d5d8de; box-shadow: 0 8px 20px rgba(20, 24, 31, .06); }
.board-card-preview {
    height: 104px; background:
        radial-gradient(circle, #e4e7ec 1px, transparent 1.2px) 0 0 / 16px 16px,
        #f7f8fa;
    display: grid; place-items: center; color: var(--ink-3);
}
.board-card-preview svg { width: 36px; height: 36px; }
.board-card-body { padding: 10px 12px 12px; display: flex; align-items: flex-start; gap: 8px; }
.board-card-main { flex: 1; min-width: 0; }
.board-card-title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-card-meta { color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.card-menu { position: relative; }
.card-pop {
    position: fixed; z-index: 40; width: 180px;
    background: #fff; border-radius: 12px; box-shadow: var(--shadow); padding: 6px;
}
.card-pop button {
    display: flex; width: 100%; text-align: left; border: 0; background: none;
    padding: 8px 10px; border-radius: 8px;
}
.card-pop button:hover { background: var(--hover); }
.card-pop .danger { color: var(--danger); }
.cabinet-empty { margin: auto; text-align: center; color: var(--ink-2); }
.cabinet-empty svg { width: 48px; height: 48px; color: var(--ink-3); }
.star-on { color: #e0a800; }

.board { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.board-top {
    display: flex; align-items: center; gap: 8px; height: 52px; padding: 0 12px 0 14px;
    border-bottom: 1px solid var(--line); flex: none;
}
.board-title {
    display: inline-flex; align-items: center; gap: 4px; max-width: min(420px, 50vw);
    height: 34px; padding: 0 10px; border: 0; border-radius: 10px; background: none; font-weight: 650; font-size: 15px;
}
.board-title:hover, .board-title[aria-expanded="true"] { background: var(--hover); }
.board-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-title svg { width: 16px; height: 16px; color: var(--ink-3); }
.board-top-spacer { flex: 1; }
.save-state { min-width: 72px; }
.menu {
    position: absolute; top: 48px; left: 14px; z-index: 20; width: 240px;
    background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 6px;
}
.menu button {
    display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
    border: 0; background: none; padding: 8px 10px; border-radius: 8px;
}
.menu button:hover { background: var(--hover); }
.menu .danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }

.board-body { flex: 1; min-height: 0; display: flex; }
.pages {
    width: 212px; flex: none; border-right: 1px solid var(--line); display: flex; flex-direction: column;
    background: #fff; min-height: 0;
}
.board-body.pages-hidden .pages { display: none; }
.pages-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 4px 12px; }
.pages-head strong { font-size: 13px; }
.page-list { overflow: auto; padding: 6px 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.page-card {
    border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 6px; text-align: left;
}
.page-card.on { border-color: var(--select); box-shadow: 0 0 0 1px var(--select); }
.page-card canvas { width: 100%; height: 78px; border-radius: 6px; background: #f7f8fa; display: block; }
.page-card-row { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.page-card-row span { flex: 1; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-more { width: 28px; height: 28px; border-radius: 8px; color: var(--ink-2); }
.page-more svg { width: 16px; height: 16px; }
.page-more:hover, .page-more.on { background: var(--hover); color: var(--ink); }
.page-more.on svg { color: var(--ink); }
.page-menu {
    position: fixed; z-index: 40; min-width: 176px;
    background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 6px;
}
.page-menu button {
    display: flex; width: 100%; text-align: left; border: 0; background: none;
    padding: 8px 12px; border-radius: 10px; font-size: 14px;
}
.page-menu button:hover { background: var(--hover); }
.page-menu button.danger { color: var(--danger); }

.stage { flex: 1; min-width: 0; position: relative; background: #f6f7f9; overflow: hidden; user-select: none; }
#surface { width: 100%; height: 100%; display: block; touch-action: none; cursor: default; }
.stage.hand-tool #surface { cursor: grab; }
.stage.panning #surface, .stage.moving #surface { cursor: grabbing !important; }
.stage.drawing #surface { cursor: crosshair; }

.tool-dock {
    position: absolute; left: 12px; top: 12px; z-index: 4;
    display: flex; flex-direction: column; gap: 2px; padding: 6px;
    background: #fff; border-radius: 16px; box-shadow: var(--dock-shadow);
}
.tool {
    width: 36px; height: 36px; border: 0; border-radius: 10px; background: none; color: #3c4048;
    display: grid; place-items: center;
}
.tool svg { width: 20px; height: 20px; }
.tool:hover { background: var(--hover); }
.tool.on { background: var(--accent-soft); color: #1b1b1b; }
.pop {
    position: absolute; left: 64px; top: 168px; z-index: 6; background: #fff;
    border-radius: 12px; box-shadow: var(--dock-shadow); padding: 6px; display: flex; gap: 4px;
}
.pop button { width: 36px; height: 36px; border: 0; border-radius: 8px; background: var(--surface-2); }
.pop button.on { outline: 2px solid var(--select); }

.sel-bar {
    position: absolute; z-index: 5; display: flex; align-items: center; gap: 4px;
    padding: 4px; background: #fff; border-radius: 12px; box-shadow: var(--dock-shadow);
}
.swatch {
    width: 22px; height: 22px; border-radius: 50%; border: 1px solid rgba(0,0,0,.12); padding: 0;
}
.swatch.on { outline: 2px solid var(--select); outline-offset: 1px; }
.sel-bar .tool { width: 32px; height: 32px; }

.prop-card {
    position: absolute; z-index: 5; width: 240px; max-height: min(420px, 70%);
    overflow: auto; background: #fff; border-radius: 14px; box-shadow: var(--dock-shadow); padding: 12px;
}
.prop-card h4 { margin: 0 0 8px; font-size: 13px; }
.prop-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.prop-row label { font-size: 12px; color: var(--ink-2); }
.prop-row input[type="text"], .prop-row textarea, .prop-row select {
    width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: #fff;
}
.prop-row textarea { min-height: 72px; resize: vertical; }
.prop-colors { display: flex; flex-wrap: wrap; gap: 6px; }
.prop-actions { display: flex; gap: 6px; }
.prop-actions .btn { flex: 1; height: 32px; font-size: 12.5px; }
.check { flex-direction: row; align-items: center; gap: 8px; }
.check input { width: auto; }

.text-editor {
    position: absolute; z-index: 6; margin: 0; border: 1px solid var(--select); border-radius: 8px;
    padding: 10px; resize: none; background: #fff; color: var(--ink); outline: none; overflow: hidden;
    line-height: 1.35; cursor: text; caret-color: var(--ink);
}
.text-editor::placeholder { color: var(--ink-3); }

.board-bottom {
    position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 4;
    display: flex; justify-content: space-between; pointer-events: none;
}
.pager, .zoom-bar {
    pointer-events: auto; display: flex; align-items: center; gap: 2px;
    background: #fff; border-radius: 12px; box-shadow: var(--dock-shadow); padding: 4px;
}
#page-indicator, .zoom-label {
    min-width: 52px; text-align: center; font-size: 12.5px; color: var(--ink-2); border: 0; background: none;
}
.board-body.pages-hidden #show-pages { color: var(--ink); }

.modal {
    position: fixed; inset: 0; z-index: 60; background: rgba(20, 24, 31, .35);
    display: flex; justify-content: center; align-items: flex-start;
    padding: 24px; overflow: auto;
}
.modal-card {
    width: min(980px, 100%); max-height: none; min-height: 0; margin: auto;
    background: #fff; border-radius: 18px; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.templates-card { width: min(960px, 100%); height: min(680px, calc(100dvh - 48px)); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px 18px; flex: none; }
.modal-head h3 { margin: 0; font-size: 18px; }
.templates-body { display: flex; min-height: 0; flex: 1; overflow: hidden; }
.template-cats { width: 210px; flex: none; padding: 8px; border-right: 1px solid var(--line); overflow: auto; }
.template-cats button {
    display: block; width: 100%; text-align: left; border: 0; background: none;
    padding: 8px 10px; border-radius: 10px; color: var(--ink-2);
}
.template-cats button.on { background: #e8f1ff; color: var(--ink); font-weight: 600; }
.template-grid { flex: 1; overflow: auto; padding: 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; align-content: start; }
.template-card { border: 0; background: #f6f7fb; border-radius: 14px; padding: 8px 8px 10px; text-align: left; }
.template-card:hover { outline: 2px solid rgba(76, 157, 255, .7); }
.template-card canvas { width: 100%; height: 112px; border-radius: 10px; background: #fff; display: block; }
.template-card span { display: block; margin-top: 8px; font-size: 13px; font-weight: 550; }
.history-card { width: min(420px, 100%); max-height: calc(100dvh - 48px); }
.history-list { overflow: auto; padding: 4px 10px 14px; min-height: 0; }
.history-list button {
    display: block; width: 100%; text-align: left; border: 0; background: none;
    padding: 8px 10px; border-radius: 8px;
}
.history-list button:hover { background: var(--hover); }

.lang-btn { border: 0; background: none; color: var(--ink-3); font-size: 12px; padding: 2px 4px; border-radius: 4px; text-transform: uppercase; }
.lang-btn:hover, .lang-btn[aria-expanded="true"] { color: var(--ink); background: var(--hover); }
.lang-menu {
    position: fixed; z-index: 90; width: 210px; max-height: min(360px, calc(100vh - 24px));
    overflow: auto; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 6px;
}
.lang-option {
    display: flex; width: 100%; text-align: left; border: 0; background: none;
    padding: 8px 10px; border-radius: 8px;
}
.lang-option:hover { background: var(--hover); }
.lang-option.active { background: var(--accent-soft); font-weight: 600; }
.dialog-backdrop { position: fixed; inset: 0; z-index: 70; background: rgba(15, 17, 20, .35); display: grid; place-items: center; padding: 16px; }
.dialog { width: 100%; max-width: 380px; background: var(--surface); border-radius: 16px; padding: 22px; box-shadow: var(--shadow); }
.dialog p { margin: 0 0 14px; font-size: 15px; }
.dialog .input { margin-bottom: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast {
    position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 80;
    background: #25272c; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13.5px;
}

@media (max-width: 800px) {
    .app { padding: 0; }
    .rail { display: none; }
    .workspace { border-radius: 0; }
    .cabinet { padding: 16px; }
    .cabinet-head { flex-direction: column; align-items: stretch; }
    .search input { width: 100%; }
    .pages { position: absolute; z-index: 7; top: 52px; bottom: 0; left: 0; box-shadow: var(--dock-shadow); }
    .tool-dock { flex-direction: row; left: 8px; right: 8px; top: auto; bottom: 64px; width: max-content; max-width: calc(100% - 16px); overflow: auto; }
    .pop { left: 8px; top: auto; bottom: 112px; }
}
