/* ===== 小组件面板样式（固定布局，不可拖拽） ===== */

/* 标签：轻微强调，区别于普通分组 */
.tab-widgets {
    border-color: color-mix(in srgb, var(--sd-accent) 40%, var(--sd-border));
    font-weight: 600;
}

/* 面板容器 */
.widget-board {
    width: 100%;
    /* 小组件统一设计变量：柔和填充 / 分隔 / 悬浮 / 阴影 */
    --w-fill: #f6f8fb;
    --w-fill-strong: #eef2f8;
    --w-line: #eef1f6;
    --w-hover: #f1f5fc;
    --w-radius: 12px;
    --w-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 12px rgba(15, 23, 42, .05);
    --w-shadow-hover: 0 2px 6px rgba(15, 23, 42, .06), 0 14px 30px rgba(15, 23, 42, .11);
}

/* 固定网格：三列（左 3 / 中 5 / 右 4），高度填满视口、不出现外层滚动 */
.widget-grid {
    display: grid;
    grid-template-columns: 3fr 5fr 4fr;
    grid-template-rows: repeat(6, 1fr);
    grid-template-areas:
        "clock   weather note"
        "clock   weather note"
        "todo    weather note"
        "todo    calendar almanac"
        "todo    calendar almanac"
        "todo    calendar almanac";
    gap: 12px;
    height: calc(100vh - 196px);
    min-height: 480px;
}

/* ===== 通用组件卡片 ===== */
.widget {
    position: relative;
    background: var(--sd-card-bg);
    border: 1px solid var(--sd-border);
    border-radius: var(--w-radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--w-shadow);
    transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
    min-width: 0;
    min-height: 0;
}

.widget:hover {
    transform: translateY(-2px);
    border-color: color-mix(in srgb, var(--sd-accent) 28%, var(--sd-border));
    box-shadow: var(--w-shadow-hover);
}

/* 所有控件统一继承主页字体，避免按钮/输入框回退到 Arial */
.widget-grid button,
.widget-grid input,
.widget-grid textarea,
.widget-grid select {
    font-family: inherit;
}

.widget-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--w-line);
}

.widget-title {
    display: flex;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--sd-text);
    letter-spacing: .4px;
}
.widget-title::before {
    content: '';
    width: 3px;
    height: 13px;
    border-radius: 2px;
    background: var(--sd-accent);
    margin-right: 8px;
}

.widget-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 2px 16px 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.widget-mini-btn {
    border: 1px solid var(--sd-border);
    background: #fff;
    color: var(--sd-muted);
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
}
.widget-mini-btn:hover { color: var(--sd-accent); border-color: var(--sd-accent); }

/* ===== 固定布局：各组件落位 ===== */
#wgt-clock    { grid-area: clock; }
#wgt-weather  { grid-area: weather; }
#wgt-note     { grid-area: note; }
#wgt-todo     { grid-area: todo; }
#wgt-calendar { grid-area: calendar; }
#wgt-almanac  { grid-area: almanac; }

/* ===== 时钟 ===== */
#wgt-clock .widget-body {
    align-items: center;
    justify-content: center;
    text-align: center;
}
.clock-time {
    font-size: clamp(30px, 3.4vw, 44px);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 1px;
    line-height: 1.1;
}
.clock-date {
    margin-top: 6px;
    font-size: 13px;
    color: var(--sd-muted);
}

/* ===== 天气（紧凑，占满组件高度） ===== */
.weather-wrap { width: 100%; height: 100%; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
.w-loading, .w-error { color: var(--sd-muted); font-size: 13px; padding: 10px 0; }
.w-city { font-size: 15px; font-weight: 600; flex: 0 0 auto; }
.w-main { display: flex; align-items: center; gap: 10px; margin: 3px 0; flex: 0 0 auto; }
.w-icon { width: 44px; height: 44px; flex: 0 0 auto; }
.w-temp { font-size: 29px; font-weight: 700; font-variant-numeric: tabular-nums; }
.w-desc { font-size: 12px; color: var(--sd-muted); }

/* 日出日落一行 */
.w-sun {
    flex: 0 0 auto;
    display: flex; justify-content: space-between;
    font-size: 11px; color: var(--sd-muted);
    background: var(--w-fill); border-radius: 8px;
    padding: 5px 10px; margin: 5px 0;
}
/* 指标网格：小格紧凑排列 */
.w-metrics {
    flex: 0 0 auto;
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 4px; margin: 2px 0;
}
.w-metric {
    background: var(--w-fill); border-radius: 8px;
    text-align: center; padding: 5px 2px;
    transition: background .15s ease, transform .15s ease;
}
.w-metric:hover { background: var(--w-fill-strong); }
.w-metric .m-label { display: block; font-size: 10px; color: var(--sd-muted); }
.w-metric .m-value { display: block; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }

.w-days {
    display: flex; gap: 5px; margin-top: 6px;
    flex: 1 1 auto; min-height: 62px;
    overflow-x: auto; padding-bottom: 2px; align-items: stretch;
}
.w-day {
    flex: 1 1 0; min-width: 44px;
    display: flex; flex-direction: column; justify-content: center;
    text-align: center;
    background: var(--w-fill);
    border-radius: 8px;
    padding: 4px 3px;
    transition: background .15s ease, transform .15s ease;
}
.w-day:hover { background: var(--w-fill-strong); transform: translateY(-1px); }
.w-day .d-name { font-size: 10px; color: var(--sd-muted); }
.w-day img { width: 22px; height: 22px; }
.w-day .d-pop { font-size: 10px; color: #3b82f6; }
.w-day .d-temp { font-size: 11px; font-variant-numeric: tabular-nums; }

/* 城市选择弹层 */
.city-picker {
    position: absolute;
    top: 40px; right: 14px;
    width: 250px;
    background: #fff;
    border: 1px solid var(--sd-border);
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, .18);
    padding: 10px;
    z-index: 20;
}
.city-picker input {
    width: 100%;
    border: 1px solid var(--sd-border);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
}
.city-picker input:focus { outline: none; border-color: var(--sd-accent); }
.city-results { margin-top: 8px; max-height: 190px; overflow-y: auto; }
.city-item {
    padding: 7px 8px;
    font-size: 13px;
    border-radius: 7px;
    cursor: pointer;
}
.city-item:hover { background: var(--w-hover); color: var(--sd-accent); }
.city-empty { font-size: 12px; color: var(--sd-muted); padding: 8px; }

/* ===== 备忘录 ===== */
#noteText {
    width: 100%;
    flex: 1 1 auto;
    border: none;
    resize: none;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.7;
    color: var(--sd-text);
    background: transparent;
}
#noteText:focus { outline: none; }

/* ===== 待办 ===== */
.todo-input-row { display: flex; gap: 6px; flex: 0 0 auto; }
.todo-input-row input {
    flex: 1 1 auto;
    min-width: 0;
    border: 1px solid var(--sd-border);
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 13px;
    font-family: inherit;
}
.todo-input-row input:focus { outline: none; border-color: var(--sd-accent); }
.todo-input-row button {
    border: none;
    background: var(--sd-accent);
    color: #fff;
    font-size: 13px;
    padding: 7px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
}
.todo-list {
    list-style: none;
    margin: 8px 0 0;
    overflow-y: auto;
    flex: 1 1 auto;
}
.todo-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 4px;
    border-radius: 8px;
    transition: background .15s ease;
}
.todo-item:hover { background: var(--w-hover); }
.todo-check { width: 16px; height: 16px; accent-color: var(--sd-accent); cursor: pointer; flex: 0 0 auto; }
.todo-content { flex: 1 1 auto; font-size: 13px; word-break: break-all; }
.todo-item.done .todo-content { text-decoration: line-through; color: var(--sd-muted); }
.todo-del {
    border: none; background: none; color: var(--sd-muted);
    cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 4px;
}
.todo-del:hover { color: #ef4444; }
.todo-empty { font-size: 12px; color: var(--sd-muted); padding: 12px 0; text-align: center; }

/* ===== 日历（格子随组件高度自适应） ===== */
.cal-wrap {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.cal-head {
    flex: 0 0 auto;
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 6px;
}
.cal-nav {
    border: 1px solid var(--sd-border); background: #fff;
    width: 24px; height: 24px; border-radius: 7px; cursor: pointer;
    color: var(--sd-text); font-size: 13px;
}
.cal-nav:hover { border-color: var(--sd-accent); color: var(--sd-accent); }
.cal-month { font-size: 13px; font-weight: 600; }
.cal-week {
    flex: 0 0 auto;
    display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px;
}
.cal-week span {
    text-align: center; font-size: 11px; color: var(--sd-muted); padding: 2px 0;
}
.cal-days {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: repeat(6, 1fr);
    gap: 2px;
}
.cal-cell {
    min-width: 0; min-height: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    font-size: 12px;
    border-radius: 8px;
    cursor: pointer;
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
    padding: 1px 0;
    transition: background .15s ease;
}
.cal-solar { font-size: 12px; }
.cal-lunar {
    font-size: 10px; color: var(--sd-muted);
    max-width: 100%;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal-cell.other { color: #cbd5e1; }
.cal-cell.other .cal-lunar { color: #d8dee8; }
.cal-cell:hover { background: var(--w-hover); }
.cal-cell.other:hover { background: var(--w-fill); }
.cal-cell.today {
    background: var(--sd-accent); color: #fff; font-weight: 700;
    box-shadow: 0 4px 10px color-mix(in srgb, var(--sd-accent) 35%, transparent);
}
.cal-cell.today .cal-lunar { color: rgba(255,255,255,.85); }
/* 节气 / 农历初一 强调 */
.cal-cell.jieqi .cal-lunar { color: #2563eb; font-weight: 600; }
.cal-cell.today.jieqi .cal-lunar { color: #fff; }
.cal-cell.selected:not(.today) { background: var(--w-fill-strong); }

/* ===== 黄历卡片 ===== */
.almanac-wrap {
    width: 100%; height: 100%; min-height: 0;
    display: flex; flex-direction: column;
    overflow-y: auto;
}
.alm-lunar { font-size: 14px; font-weight: 700; flex: 0 0 auto; }
.alm-ganzhi {
    font-size: 11px; color: var(--sd-muted);
    margin: 3px 0 7px; flex: 0 0 auto;
}
.alm-row { font-size: 12px; margin-bottom: 6px; flex: 0 0 auto; line-height: 1.5; }
.alm-tag {
    display: inline-block; min-width: 24px; text-align: center;
    border-radius: 6px; font-size: 11px; font-weight: 700;
    padding: 2px 6px; margin-right: 8px;
}
.alm-tag.yi { background: #e7f3ec; color: #15803d; }
.alm-tag.ji { background: #fdecec; color: #b91c1c; }
.alm-text { color: var(--sd-text); }
.alm-meta {
    font-size: 11px; color: var(--sd-muted);
    border-top: 1px solid var(--w-line); padding-top: 8px;
    margin-top: auto; flex: 0 0 auto; line-height: 1.7;
}

/* ===== 游客锁定遮罩（备忘录/待办） ===== */
.widget.guest-locked .widget-body { position: relative; }
.widget.guest-locked .widget-body::after {
    content: '登录后可编辑';
    position: absolute; inset: 0;
    background: rgba(255, 255, 255, .82);
    display: flex; align-items: center; justify-content: center;
    color: var(--sd-accent); font-size: 13px; font-weight: 600;
    cursor: pointer;
}

/* ===== 精致细滚动条（内部滚动区域） ===== */
.weather-wrap,
.almanac-wrap,
.todo-list,
.city-results,
.w-days {
    scrollbar-width: thin;
    scrollbar-color: #cdd6e3 transparent;
}
.weather-wrap::-webkit-scrollbar,
.almanac-wrap::-webkit-scrollbar,
.todo-list::-webkit-scrollbar,
.city-results::-webkit-scrollbar,
.w-days::-webkit-scrollbar { width: 6px; height: 6px; }
.weather-wrap::-webkit-scrollbar-thumb,
.almanac-wrap::-webkit-scrollbar-thumb,
.todo-list::-webkit-scrollbar-thumb,
.city-results::-webkit-scrollbar-thumb,
.w-days::-webkit-scrollbar-thumb {
    background: #cdd6e3; border-radius: 3px;
}
.weather-wrap::-webkit-scrollbar-thumb:hover,
.almanac-wrap::-webkit-scrollbar-thumb:hover,
.todo-list::-webkit-scrollbar-thumb:hover { background: #b3bfd0; }
.weather-wrap::-webkit-scrollbar-track,
.almanac-wrap::-webkit-scrollbar-track,
.todo-list::-webkit-scrollbar-track,
.city-results::-webkit-scrollbar-track,
.w-days::-webkit-scrollbar-track { background: transparent; }

/* ===== 响应式：窄屏改为单列纵向堆叠 ===== */
@media (max-width: 880px) {
    .widget-grid {
        grid-template-columns: 1fr;
        grid-template-rows: none;
        grid-template-areas:
            "clock"
            "weather"
            "calendar"
            "note"
            "todo"
            "almanac";
        height: auto;
        min-height: 0;
    }
    .widget { min-height: 230px; }
    #wgt-clock { min-height: 170px; }
    .city-picker { width: calc(100% - 28px); }
}
