/* =====================================================================
   To Do · 基础样式（设计变量 / 布局 / 侧边栏 / 通用控件）
   结构参考 stock 项目：base 层放全局骨架，业务层放 todo/css/view.css
   ===================================================================== */
*,
*::before,
*::after { box-sizing: border-box; }

:root {
    --font: "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont, "PingFang SC",
            "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;

    --bg-app: #faf9f8;
    --bg-sidebar: #f3f2f1;
    --bg-main: #ffffff;
    --bg-elev: #ffffff;
    --bg-subtle: #faf9f8;
    --bg-hover: rgba(32, 31, 30, .045);
    --bg-active: rgba(32, 31, 30, .075);
    --bg-input: #ffffff;

    --border: #e8e6e4;
    --border-soft: #f0eeec;
    --border-strong: #d2d0ce;

    --text: #201f1e;
    --text-secondary: #5c5a58;
    --text-tertiary: #8a8886;
    --text-inverse: #ffffff;

    --accent: #2564cf;
    --accent-strong: #1b4fa0;
    --accent-soft: #e8f1fd;
    --accent-softer: #f3f8ff;
    --danger: #d13438;
    --danger-soft: #fdecec;
    --star: #d13438;
    --green: #107c10;
    --orange: #ca5010;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .05);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, .10);
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, .18);

    --sidebar-w: 290px;
    --content-max: 1000px;
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 10px;

    --icon-size: 18px;
}

html[data-theme="dark"] {
    --bg-app: #1b1a19;
    --bg-sidebar: #252423;
    --bg-main: #1f1e1d;
    --bg-elev: #292827;
    --bg-subtle: #252423;
    --bg-hover: rgba(255, 255, 255, .055);
    --bg-active: rgba(255, 255, 255, .09);
    --bg-input: #292827;

    --border: #3b3a39;
    --border-soft: #33312f;
    --border-strong: #4a4846;

    --text: #f3f2f1;
    --text-secondary: #c8c6c4;
    --text-tertiary: #a19f9d;
    --text-inverse: #ffffff;

    --accent: #5b93f5;
    --accent-strong: #7aa8f7;
    --accent-soft: rgba(91, 147, 245, .15);
    --accent-softer: rgba(91, 147, 245, .08);
    --danger: #f1707b;
    --danger-soft: rgba(241, 112, 123, .12);
    --star: #f1707b;
    --green: #6ccb5f;

    --shadow-md: 0 6px 20px rgba(0, 0, 0, .45);
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, .55);
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg-app);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
}

button, input, textarea, select {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    border: 0;
    background: none;
    padding: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

h1, h2, h3, p {
    margin: 0;
}

ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.icon {
    width: 1.15em;
    height: 1.15em;
    display: inline-block;
    vertical-align: -0.14em;
    flex: none;
    overflow: visible;
}

/* ------------------------------ 滚动条 ------------------------------ */
.sidebar-scroll,
.main,
.detail-scroll {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, .18) transparent;
}

.sidebar-scroll::-webkit-scrollbar,
.main::-webkit-scrollbar,
.detail-scroll::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.sidebar-scroll::-webkit-scrollbar-thumb,
.main::-webkit-scrollbar-thumb,
.detail-scroll::-webkit-scrollbar-thumb {
    background: rgba(120, 120, 120, .25);
    border-radius: 3px;
}

/* ------------------------------ 应用骨架 ------------------------------ */
.app {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

.main {
    flex: 1;
    min-width: 0;
    background: var(--bg-main);
    overflow-y: auto;
    position: relative;
}

/* ------------------------------ 侧边栏 ------------------------------ */
.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 40;
    transition: width .18s ease, transform .22s ease, flex-basis .18s ease;
}

.sidebar-top {
    height: 56px;
    flex: none;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
}

.icon-btn {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: background .15s, color .15s;
    flex: none;
}

.icon-btn .icon {
    width: 20px;
    height: 20px;
}

.icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 6px;
    min-width: 0;
    color: var(--text);
}

.brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    background: var(--accent);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(37, 100, 207, .25);
}

.brand-mark .icon {
    width: 17px;
    height: 17px;
}

.brand-text {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: .2px;
}

.sidebar-top #searchOpenBtn {
    margin-left: auto;
}

.sidebar-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 8px 10px;
}

.side-nav {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.side-item {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 40px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    position: relative;
    transition: background .13s, color .13s;
    user-select: none;
}

.side-item:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.side-item.active {
    background: var(--bg-active);
    color: var(--accent);
    font-weight: 500;
}

.side-item.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 7px;
    bottom: 7px;
    width: 3px;
    border-radius: 0 2px 2px 0;
    background: var(--accent);
}

.side-icon {
    width: 20px;
    height: 20px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    color: var(--text-tertiary);
    flex: none;
}

.side-icon .icon {
    width: 19px;
    height: 19px;
}

.side-item.active .side-icon {
    color: var(--accent);
}

.side-icon.sun-icon { color: #e9a33c; }
.side-icon.star-icon { color: #b06a2c; }
html[data-theme="dark"] .side-icon.sun-icon { color: #ffcf6d; }
html[data-theme="dark"] .side-icon.star-icon { color: #f3b06a; }

.side-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13.5px;
}

.side-count {
    font-size: 11.5px;
    color: var(--text-tertiary);
    min-width: 18px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.side-item.active .side-count {
    color: var(--accent);
}

.sidebar-divider {
    height: 1px;
    margin: 10px 10px 8px;
    background: var(--border);
    opacity: .7;
}

.sidebar-lists {
    display: flex;
    flex-direction: column;
}

.side-group {
    margin-bottom: 2px;
}

.side-group-head {
    display: flex;
    align-items: center;
    height: 32px;
    padding-left: 4px;
    border-radius: var(--radius-sm);
}

.side-group-head:hover {
    background: var(--bg-hover);
}

.group-toggle {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    height: 100%;
    padding: 0 4px;
    color: var(--text-tertiary);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .2px;
}

.group-chevron {
    width: 13px;
    height: 13px;
    transition: transform .15s;
}

.side-group.is-collapsed .group-chevron {
    transform: rotate(-90deg);
}

.side-group.is-collapsed .group-lists {
    display: none;
}

.group-name {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.side-group .row-more {
    opacity: 0;
}

.side-group:hover .row-more {
    opacity: 1;
}

.side-list-row {
    position: relative;
    display: flex;
    align-items: center;
    height: 36px;
    border-radius: var(--radius-sm);
    transition: background .13s;
}

.side-list-row:hover {
    background: var(--bg-hover);
}

.side-list-row.active {
    background: var(--bg-active);
}

.side-list-row.active .side-list {
    color: var(--accent);
    font-weight: 500;
}

.side-list-row.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    border-radius: 0 2px 2px 0;
    background: var(--accent);
}

.side-list-row .side-list {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 9px;
    height: 100%;
    padding: 0 8px 0 14px;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
}

.list-emoji {
    width: 21px;
    height: 21px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15.5px;
    flex: none;
}

.side-list .side-label {
    font-size: 13.5px;
}

.row-more {
    width: 26px;
    height: 26px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    flex: none;
    transition: background .13s, color .13s, opacity .13s;
}

.row-more .icon {
    width: 16px;
    height: 16px;
}

.row-more:hover {
    background: var(--bg-active);
    color: var(--text);
}

.list-more {
    margin-right: 4px;
    opacity: 0;
}

.side-list-row:hover .list-more,
.side-list-row.active .list-more {
    opacity: 1;
}

.group-empty {
    padding: 3px 0 5px 30px;
    color: var(--text-tertiary);
    font-size: 12px;
}

.sidebar-actions {
    margin-top: 10px;
    padding: 0 2px;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.side-action {
    display: flex;
    align-items: center;
    gap: 9px;
    height: 36px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    text-align: left;
}

.side-action .icon {
    width: 17px;
    height: 17px;
    color: var(--text-tertiary);
}

.side-action:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.sidebar-bottom {
    flex: none;
    border-top: 1px solid var(--border-soft);
    padding: 8px 8px 10px;
    background: var(--bg-sidebar);
}

.side-completed {
    height: 36px;
}

.account-row {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    padding-top: 8px;
    border-top: 1px solid var(--border-soft);
}

.account-btn {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 9px;
    height: 42px;
    padding: 0 6px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-align: left;
}

.account-btn:hover {
    background: var(--bg-hover);
}

.avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2564cf, #3a8bd6);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    flex: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .18);
}

.account-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}

.account-caret {
    width: 14px;
    height: 14px;
    color: var(--text-tertiary);
}

.account-setting {
    width: 34px;
    height: 34px;
}

/* 折叠态 */
.app.sidebar-collapsed .sidebar {
    width: 64px;
    flex-basis: 64px;
}

.app.sidebar-collapsed .sidebar .brand-text,
.app.sidebar-collapsed .sidebar .side-label,
.app.sidebar-collapsed .sidebar .side-count,
.app.sidebar-collapsed .sidebar .sidebar-lists,
.app.sidebar-collapsed .sidebar .sidebar-actions span,
.app.sidebar-collapsed .sidebar .account-name,
.app.sidebar-collapsed .sidebar .account-caret,
.app.sidebar-collapsed .sidebar .account-setting,
.app.sidebar-collapsed .sidebar .row-more,
.app.sidebar-collapsed .sidebar-divider {
    display: none;
}

.app.sidebar-collapsed .sidebar-top {
    justify-content: center;
    flex-direction: column;
    height: auto;
    padding: 10px 8px 6px;
    gap: 6px;
}

.app.sidebar-collapsed .brand {
    padding: 0;
}

.app.sidebar-collapsed .sidebar-top #searchOpenBtn {
    display: none;
}

.app.sidebar-collapsed .side-item,
.app.sidebar-collapsed .side-list-row .side-list,
.app.sidebar-collapsed .side-action {
    justify-content: center;
    padding: 0;
}

.app.sidebar-collapsed .side-item.active::before {
    left: -8px;
}

.app.sidebar-collapsed .account-row {
    justify-content: center;
}

.app.sidebar-collapsed .account-btn {
    flex: none;
    padding: 0;
}

.app.sidebar-collapsed .sidebar-actions {
    padding: 0;
}

/* 移动端遮罩 */
.sidebar-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .35);
    z-index: 35;
    opacity: 0;
    transition: opacity .2s;
}

/* ------------------------------ 通用表单 / 按钮 ------------------------------ */
.btn-primary {
    height: 42px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background .15s, box-shadow .15s;
}

.btn-primary:hover {
    background: var(--accent-strong);
}

.btn-quiet {
    height: 34px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    background: var(--bg-main);
}

.btn-quiet:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.btn-quiet .icon {
    width: 15px;
    height: 15px;
}

.link-btn {
    color: var(--accent);
    font-size: 12.5px;
    padding: 2px 4px;
    border-radius: 3px;
}

.link-btn:hover {
    background: var(--accent-soft);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

.field-input {
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    outline: none;
    font-size: 14px;
    transition: border-color .15s, box-shadow .15s;
}

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

/* ------------------------------ 提示条 ------------------------------ */
.toast-root {
    position: fixed;
    left: 50%;
    bottom: 32px;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: #323130;
    color: #fff;
    font-size: 13px;
    padding: 10px 16px;
    border-radius: 6px;
    box-shadow: var(--shadow-md);
    opacity: 0;
    transform: translateY(8px);
    animation: toast-in .22s forwards;
    max-width: 80vw;
}

.toast.is-error {
    background: var(--danger);
}

.toast.is-out {
    animation: toast-out .2s forwards;
}

@keyframes toast-in {
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
    to { opacity: 0; transform: translateY(8px); }
}

/* ------------------------------ 响应式骨架 ------------------------------ */
@media (max-width: 1180px) {
    :root { --sidebar-w: 260px; --content-max: 900px; }
}

@media (max-width: 860px) {
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: 300px;
        flex-basis: 300px;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    body.sidebar-open .sidebar-scrim {
        display: block;
        opacity: 1;
    }

    .app.sidebar-collapsed .sidebar {
        width: 300px;
        flex-basis: 300px;
        transform: translateX(-100%);
    }

    body.sidebar-open .app.sidebar-collapsed .sidebar {
        transform: translateX(0);
    }
}

/* ------------------------------ 工具类 ------------------------------ */
[hidden] { display: none !important; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}
