/* ==========================================================================
   工作台样式：扁平、无渐变、深浅双主题、桌面卡片网格 + 移动端可收起顶栏
   ========================================================================== */

/* ---------- 基础与主题变量 ---------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #f7f8fa;
    --text: #1b1f24;
    --text-2: #667085;
    --text-3: #98a2b3;
    --border: #e4e7ec;
    --accent: #2563eb;
    --accent-weak: rgba(37, 99, 235, 0.1);
    --success: #16a34a;
    --success-weak: rgba(22, 163, 74, 0.12);
    --danger: #dc2626;
    --danger-weak: rgba(220, 38, 38, 0.1);
    --warning: #b45309;
    --warning-weak: rgba(180, 83, 9, 0.1);
    --meter: #2563eb;
}

html[data-theme="dark"] {
    --bg: #0f1115;
    --surface: #171a1f;
    --surface-2: #1e2229;
    --text: #e6e8eb;
    --text-2: #9aa3af;
    --text-3: #6b7280;
    --border: #2a2f38;
    --accent: #4f83f7;
    --accent-weak: rgba(79, 131, 247, 0.16);
    --success: #34c077;
    --success-weak: rgba(52, 192, 119, 0.16);
    --danger: #f07171;
    --danger-weak: rgba(240, 113, 113, 0.14);
    --warning: #e5a94a;
    --warning-weak: rgba(229, 169, 74, 0.14);
    --meter: #4f83f7;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

ul {
    list-style: none;
}

button {
    font: inherit;
    color: inherit;
    cursor: pointer;
}

code {
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
}

.icon {
    width: 18px;
    height: 18px;
    flex: none;
    display: inline-block;
    vertical-align: -3px;
}

/* ---------- 顶栏 ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 1180px;
    margin: 0 auto;
    padding: 10px 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 15px;
    min-width: 0;
}

.brand-icon {
    color: var(--accent);
    display: inline-flex;
}

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

.topbar-clock {
    margin-left: auto;
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.topbar-time {
    font-size: 15px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.topbar-date {
    color: var(--text-2);
    font-size: 13px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-2);
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.icon-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-weak);
}

.icon-btn-danger:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: var(--danger-weak);
}

.nav-toggle {
    display: none;
}

.topbar-panel {
    display: none;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.topbar-panel-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 12px 16px 14px;
}

.panel-date {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    color: var(--text-2);
    font-size: 13px;
    margin-bottom: 10px;
}

.panel-time {
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.panel-links {
    display: flex;
    gap: 8px;
}

.panel-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 13px;
}

/* ---------- 布局与卡片 ---------- */
.layout {
    max-width: 1180px;
    margin: 0 auto;
    padding: 18px 16px 28px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.card-wide {
    grid-column: 1 / -1;
}

.card-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.card-icon {
    display: inline-flex;
    color: var(--accent);
}

.card-title {
    font-size: 14px;
    font-weight: 600;
}

.card-head-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-note {
    color: var(--text-3);
    font-size: 12px;
}

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

.empty {
    padding: 18px 12px;
    text-align: center;
    color: var(--text-3);
    font-size: 13px;
    background: var(--surface-2);
    border: 1px dashed var(--border);
    border-radius: 8px;
}

/* ---------- 时间卡 ---------- */
.clock-big {
    font-size: 38px;
    font-weight: 600;
    letter-spacing: 1px;
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
}

.clock-date {
    color: var(--text-2);
    font-size: 13px;
}

/* ---------- 统计数字 ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.stat {
    padding: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.stat-num {
    font-size: 20px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    color: var(--text-2);
    font-size: 12px;
}

/* ---------- 进度条与键值列表 ---------- */
.meter-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.meter-label {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: var(--text-2);
    font-size: 12px;
}

.meter {
    height: 6px;
    border-radius: 3px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    overflow: hidden;
}

.meter-fill {
    display: block;
    height: 100%;
    background: var(--meter);
}

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

.kv {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 13px;
}

.kv > span:first-child {
    color: var(--text-2);
    flex: none;
}

.kv > span:last-child {
    text-align: right;
    word-break: break-all;
}

/* ---------- 项目健康度 ---------- */
.proj-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 10px;
}

.proj {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--text-3);
    border-radius: 8px;
}

.proj-up {
    border-left-color: var(--success);
}

.proj-down {
    border-left-color: var(--danger);
}

.proj-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.proj-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pill {
    flex: none;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-2);
}

.proj-up .pill {
    color: var(--success);
    border-color: var(--success);
    background: var(--success-weak);
}

.proj-down .pill {
    color: var(--danger);
    border-color: var(--danger);
    background: var(--danger-weak);
}

.proj-url {
    color: var(--text-2);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.proj-meta {
    display: flex;
    gap: 10px;
    color: var(--text-3);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.proj-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 12px;
}

.proj-visit {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--accent);
}

.proj-visit .icon {
    width: 13px;
    height: 13px;
}

.proj-time {
    color: var(--text-3);
}

/* ---------- 待办 ---------- */
.todo-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 260px;
    overflow-y: auto;
}

.todo-list li {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 13px;
}

.todo-icon {
    display: inline-flex;
    color: var(--text-3);
    margin-top: 1px;
}

.todo-icon .icon {
    width: 15px;
    height: 15px;
}

.todo-list li.done .todo-text {
    color: var(--text-3);
    text-decoration: line-through;
}

.todo-list li.done .todo-icon {
    color: var(--success);
}

/* ---------- 按钮与表单 ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 34px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 13px;
    white-space: nowrap;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn:disabled {
    opacity: 0.55;
    cursor: default;
}

.btn:disabled:hover {
    border-color: var(--border);
    color: var(--text);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

.btn-primary:hover {
    color: #ffffff;
    opacity: 0.9;
    border-color: var(--accent);
}

.btn-sm {
    height: 28px;
    padding: 0 10px;
    font-size: 12px;
}

.btn-sm .icon {
    width: 14px;
    height: 14px;
}

.input {
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 13px;
}

.input:focus {
    outline: none;
    border-color: var(--accent);
}

.input-grow {
    flex: 1;
    min-width: 0;
}

.form-inline,
.form-stack {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.form-stack {
    flex-direction: column;
    align-items: stretch;
}

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

.field-label {
    color: var(--text-2);
    font-size: 13px;
}

.inline-form {
    display: inline-flex;
}

.row-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.row-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.row-form .input:not(.input-grow) {
    width: 150px;
}

.row-actions {
    display: flex;
    gap: 6px;
    margin-left: auto;
}

.row-actions .icon-btn {
    width: 30px;
    height: 30px;
}

.row-actions .icon {
    width: 15px;
    height: 15px;
}

.login-card {
    max-width: 420px;
    margin: 24px auto 0;
}

.login-tip {
    color: var(--text-2);
    font-size: 13px;
}

.todo-admin {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.todo-admin-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
}

.todo-admin-item.done .todo-text {
    color: var(--text-3);
    text-decoration: line-through;
}

.todo-admin-item form {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: none;
}

.todo-admin-item .icon-btn {
    width: 30px;
    height: 30px;
}

/* ---------- AI 日记 ---------- */
.textarea {
    width: 100%;
    min-height: 160px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    line-height: 1.6;
    resize: vertical;
}

.textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.card-actions {
    display: flex;
    gap: 6px;
    margin-left: auto;
}

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

.summary-list a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: border-color 0.15s, color 0.15s;
}

.summary-list a:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.summary-list .icon {
    width: 15px;
    height: 15px;
    color: var(--text-3);
    flex: none;
}

.summary-date {
    color: var(--text);
    font-size: 13px;
}

/* 渲染后的 Markdown 正文 */
.md-body {
    color: var(--text);
    font-size: 14px;
    line-height: 1.75;
}

.md-body h1,
.md-body h2,
.md-body h3,
.md-body h4 {
    margin: 18px 0 8px;
    line-height: 1.35;
}

.md-body h1 {
    font-size: 22px;
}

.md-body h2 {
    font-size: 18px;
}

.md-body h3 {
    font-size: 16px;
}

.md-body h4 {
    font-size: 14px;
}

.md-body p {
    margin: 10px 0;
}

.md-body ul,
.md-body ol {
    margin: 8px 0;
    padding-left: 22px;
}

.md-body li {
    margin: 4px 0;
}

.md-body blockquote {
    margin: 10px 0;
    padding: 6px 14px;
    border-left: 3px solid var(--accent);
    background: var(--surface-2);
    border-radius: 0 8px 8px 0;
    color: var(--text-2);
}

.md-body code {
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 0.92em;
}

/* ---------- 提示条 ---------- */
.alert {
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 13px;
    margin-bottom: 14px;
}

.alert-ok {
    color: var(--success);
    border-color: var(--success);
    background: var(--success-weak);
}

.alert-error {
    color: var(--danger);
    border-color: var(--danger);
    background: var(--danger-weak);
}

.alert-warn {
    color: var(--warning);
    border-color: var(--warning);
    background: var(--warning-weak);
}

/* ---------- 页脚 ---------- */
.footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 18px 16px 26px;
    color: var(--text-3);
    font-size: 12px;
}

.footer a {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.footer a:hover {
    color: var(--accent);
}

.footer .icon {
    width: 14px;
    height: 14px;
}

/* ---------- 响应式 ---------- */
@media (max-width: 1100px) {
    .grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .card-wide {
        grid-column: auto;
    }

    .nav-toggle {
        display: inline-flex;
    }

    .topbar-clock,
    .topbar-actions {
        display: none;
    }

    .topbar-panel.open {
        display: block;
    }

    .clock-big {
        font-size: 32px;
    }

    .row-form .input:not(.input-grow) {
        width: 100%;
    }

    .row-actions {
        margin-left: 0;
        width: 100%;
        justify-content: flex-end;
    }

    .form-inline .input {
        width: 100%;
        flex: none;
    }

    .form-inline .btn {
        width: 100%;
    }
}
