:root {
    --primary: #8C2F2B;
    --primary-dark: #6E211E;
    --gold: #C9A227;
    --paper: #F7F2E9;
    --card: #FFFDF8;
    --ink: #2B2118;
    --muted: #8A7C6C;
    --line: #EDE3D4;
    --line-strong: #DED0BB;
    --green: #4E7A63;
    --red: #B3413B;
    --shadow: 0 8rpx 30rpx rgba(62, 40, 25, .08);
    --radius: 14px;
    font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
    font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--paper);
    color: var(--ink);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
[hidden] { display: none !important; }
a { color: var(--primary); }

/* ---------- 通用控件 ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: 1px solid transparent; border-radius: 9px; padding: 10px 18px;
    font-size: 14px; font-weight: 600; cursor: pointer; transition: .16s ease;
    white-space: nowrap; line-height: 1.3;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); color: #FFF6E8; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--primary); }
.btn-ghost:hover { background: #F6EDE0; }
.btn-plain { background: #F4EDE2; color: var(--ink); }
.btn-plain:hover { background: #ECE0CF; }
.btn-danger { background: transparent; border-color: #E8C4C1; color: var(--red); }
.btn-danger:hover { background: #FBEFEE; }
.btn-sm { padding: 7px 13px; font-size: 13px; border-radius: 8px; }
.btn-xs { padding: 5px 10px; font-size: 12px; border-radius: 7px; font-weight: 500; }
.btn-block { width: 100%; }

.input, .textarea, .select {
    width: 100%; background: #FFFDF8; border: 1px solid var(--line-strong);
    border-radius: 9px; padding: 10px 13px; outline: none; transition: .15s;
}
.input { height: 42px; }
.textarea { min-height: 96px; resize: vertical; line-height: 1.65; }
.select { height: 42px; cursor: pointer; }
.input:focus, .textarea:focus, .select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(140,47,43,.10); }
.input::placeholder, .textarea::placeholder { color: #B2A492; }
.field-label { display: block; font-weight: 600; font-size: 13px; margin: 0 0 7px; }
.field-label .req { color: var(--red); }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.6; }
.form-error { color: var(--red); font-size: 13px; background: #FBEFEE; border: 1px solid #EED4D1; border-radius: 8px; padding: 9px 12px; margin: 12px 0; }
.form-ok { color: var(--green); font-size: 13px; background: #EDF5EF; border: 1px solid #CDE3D3; border-radius: 8px; padding: 9px 12px; margin: 12px 0; }

.switch { position: relative; display: inline-block; vertical-align: middle; width: 42px; height: 24px; flex: 0 0 42px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #D9CDBB; border-radius: 99px; cursor: pointer; transition: .2s; }
.switch span::after { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(18px); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 2px 12px rgba(62,40,25,.04); }
.card-head { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-title { font-size: 16px; font-weight: 700; }
.card-body { padding: 22px; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.tag { display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.tag-on { background: #EDF5EF; color: var(--green); }
.tag-off { background: #F1ECE4; color: var(--muted); }
.tag-gold { background: #F8F0D8; color: #96761A; }

/* ---------- 登录 ---------- */
.login-view { display: grid; grid-template-columns: minmax(320px, 42%) 1fr; min-height: 100vh; }
.login-side {
    background: linear-gradient(155deg, #7A2724 0%, #4A211D 55%, #2E1A17 100%);
    color: #F7EEDF; padding: 56px 54px; display: flex; flex-direction: column; justify-content: space-between;
    position: relative; overflow: hidden;
}
.login-side::after {
    content: '漢'; position: absolute; right: -40px; bottom: -90px; font-size: 340px;
    color: rgba(255,255,255,.045); font-weight: 700; line-height: 1; pointer-events: none;
}
.login-brand { position: relative; z-index: 1; }
.login-seal, .side-seal {
    width: 54px; height: 54px; border-radius: 14px; background: var(--gold); color: #3A1C17;
    display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 700;
}
.login-brand h1 { font-size: 27px; margin: 22px 0 6px; letter-spacing: 2px; font-weight: 700; }
.login-brand p { margin: 0; color: rgba(247,238,223,.72); letter-spacing: 3px; font-size: 13px; }
.login-poem { position: relative; z-index: 1; font-size: 24px; line-height: 2; letter-spacing: 5px; color: rgba(247,238,223,.9); border-left: 2px solid var(--gold); padding-left: 22px; }
.login-foot { position: relative; z-index: 1; font-size: 12px; color: rgba(247,238,223,.55); letter-spacing: 1px; }
.login-main { display: flex; align-items: center; justify-content: center; padding: 40px; background: var(--paper); }
.login-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 40px 36px; box-shadow: 0 16px 50px rgba(62,40,25,.09); }
.login-kicker { font-size: 11px; letter-spacing: 4px; color: var(--gold); font-weight: 700; }
.login-card h2 { font-size: 25px; margin: 10px 0 8px; }
.login-sub { color: var(--muted); line-height: 1.7; margin: 0 0 28px; font-size: 13px; }
.login-card .field-label { margin-top: 18px; }
.login-card .btn-block { margin-top: 22px; height: 46px; font-size: 15px; letter-spacing: 3px; }
.login-tip { margin-top: 16px; font-size: 12px; line-height: 1.7; background: #FBF3DF; border: 1px solid #EFDFB6; color: #8A6D1C; padding: 10px 12px; border-radius: 9px; }
.login-note { margin-top: 22px; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- 主框架 ---------- */
.app-view { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: #3B2420; color: #F3E7D7; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side-brand { display: flex; align-items: center; gap: 12px; padding: 22px 20px; border-bottom: 1px solid rgba(255,255,255,.08); }
.side-seal { width: 40px; height: 40px; border-radius: 11px; font-size: 20px; flex: 0 0 40px; }
.side-title { font-weight: 700; letter-spacing: 1px; font-size: 15px; }
.side-sub { font-size: 11px; color: rgba(243,231,215,.55); letter-spacing: 1px; margin-top: 2px; }
.side-nav { flex: 1; overflow-y: auto; padding: 8px 10px 12px; }
.side-nav::-webkit-scrollbar { width: 5px; }
.side-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.16); border-radius: 9px; }
.nav-group { font-size: 11px; letter-spacing: 2px; color: rgba(243,231,215,.42); padding: 8px 12px 4px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border-radius: 9px; cursor: pointer; color: rgba(243,231,215,.78); font-size: 13px; transition: .15s; margin-bottom: 1px; }
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: var(--primary); color: #FFF6E8; font-weight: 600; }
.nav-icon { width: 22px; height: 22px; border-radius: 6px; background: rgba(255,255,255,.10); display: flex; align-items: center; justify-content: center; font-size: 11px; flex: 0 0 22px; }
.nav-item.active .nav-icon { background: rgba(255,255,255,.20); }
.nav-badge { margin-left: auto; font-size: 11px; background: rgba(255,255,255,.14); padding: 1px 7px; border-radius: 99px; }
.side-foot { padding: 14px 16px 18px; border-top: 1px solid rgba(255,255,255,.08); }
.cloud-status { font-size: 11.5px; color: rgba(243,231,215,.62); display: flex; align-items: center; gap: 7px; margin-bottom: 12px; }
.cloud-status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); flex: 0 0 7px; }
.cloud-status.ok .dot { background: #7FC08C; }
.cloud-status.bad .dot { background: #E08A84; }
.side-logout { width: 100%; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.10); color: #F3E7D7; border-radius: 8px; padding: 8px; cursor: pointer; font-size: 12.5px; }
.side-logout:hover { background: rgba(255,255,255,.16); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 74px; background: rgba(255,253,248,.92); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 30px; position: sticky; top: 0; z-index: 20; backdrop-filter: blur(8px); }
.page-title { font-size: 19px; font-weight: 700; }
.page-desc { font-size: 12px; color: var(--muted); margin-top: 3px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.saved-label { font-size: 12px; color: var(--muted); }
.whoami { font-size: 12.5px; background: #F2E8DA; border: 1px solid var(--line); color: var(--primary); padding: 6px 12px; border-radius: 99px; font-weight: 600; text-decoration: none; cursor: pointer; }
.whoami:hover { background: #EADBC6; }
.content { padding: 26px 30px 60px; max-width: 1440px; width: 100%; }

/* ---------- 概览 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; position: relative; overflow: hidden; }
.stat::after { content: ''; position: absolute; right: -18px; top: -18px; width: 76px; height: 76px; border-radius: 50%; background: rgba(201,162,39,.09); }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 8px; letter-spacing: 1px; }
.stat-foot { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.quick-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.quick { background: var(--card); border: 1px solid var(--line); border-radius: 11px; padding: 15px 16px; cursor: pointer; display: flex; align-items: center; gap: 12px; transition: .15s; }
.quick:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow); }
.quick-icon { width: 36px; height: 36px; border-radius: 9px; background: #F6E9DC; color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 700; }
.quick-text b { display: block; font-size: 14px; }
.quick-text span { font-size: 11.5px; color: var(--muted); }

/* ---------- 表格 ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.toolbar .input, .toolbar .select { width: auto; min-width: 150px; height: 38px; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-weight: 600; color: var(--muted); background: #FAF5EC; padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; font-size: 12.5px; }
td { padding: 12px 16px; border-bottom: 1px solid #F3ECDF; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FDF9F2; }
.td-ellipsis { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb { width: 54px; height: 40px; border-radius: 7px; object-fit: cover; background: #EEE4D5; display: block; }
.thumb-empty { width: 54px; height: 40px; border-radius: 7px; background: #F1E8DA; display: flex; align-items: center; justify-content: center; color: #B8A78F; font-size: 11px; }
.row-ops { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { padding: 56px 20px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 6px; }

/* ---------- 表单 / 单模块 ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px 22px; }
.form-row { min-width: 0; }
.form-row.full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.notice { background: #FBF3DF; border: 1px solid #EFDFB6; color: #7A621C; border-radius: 10px; padding: 13px 16px; font-size: 13px; line-height: 1.7; margin-bottom: 20px; }

/* ---------- 图片控件 ---------- */
.img-editor { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.img-preview { width: 180px; height: 118px; border: 1px dashed var(--line-strong); border-radius: 10px; object-fit: cover; background: #F6EFE4; }
.img-preview-empty { width: 180px; height: 118px; border: 1px dashed var(--line-strong); border-radius: 10px; background: #F6EFE4; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
.img-tools { flex: 1; min-width: 220px; }
.img-source { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.img-status { margin: 0 0 10px; padding: 9px 12px; border-radius: 8px; font-size: 12px; line-height: 1.65; }
.img-status[hidden] { display: none !important; }
.img-status.pending { background: #F3EFE6; color: #7A6242; border: 1px solid #E4D7C1; }
.img-status.ok { background: #EDF5EF; color: #2F6B43; border: 1px solid #CDE3D3; }
.img-status.err { background: #FBEFEE; color: #9B3B34; border: 1px solid #EED4D1; }
.preset-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.preset { width: 62px; height: 46px; border-radius: 7px; overflow: hidden; border: 2px solid transparent; cursor: pointer; padding: 0; background: none; }
.preset img { width: 100%; height: 100%; object-fit: cover; display: block; }
.preset.active { border-color: var(--primary); }
.preset-label { font-size: 12px; color: var(--muted); margin-top: 12px; }

/* ---------- 抽屉 / 弹窗 ---------- */
.drawer-mask, .modal-mask { position: fixed; inset: 0; background: rgba(35,22,17,.42); z-index: 60; }
.drawer-mask { display: flex; justify-content: flex-end; }
.drawer { width: min(660px, 94vw); height: 100%; background: var(--paper); box-shadow: -12px 0 40px rgba(0,0,0,.16); display: flex; flex-direction: column; animation: slideIn .2s ease; }
@keyframes slideIn { from { transform: translateX(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer-head { padding: 20px 26px; border-bottom: 1px solid var(--line); background: var(--card); display: flex; align-items: center; justify-content: space-between; }
.drawer-head h3 { margin: 0; font-size: 18px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 24px 26px; }
.drawer-foot { padding: 16px 26px; background: var(--card); border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.icon-btn { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.icon-btn:hover { color: var(--ink); }
.modal-mask { display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { width: min(440px, 94vw); background: var(--card); border-radius: 14px; padding: 26px; box-shadow: 0 20px 60px rgba(0,0,0,.22); }
.modal h3 { margin: 0 0 10px; font-size: 18px; }
.modal p { color: var(--muted); line-height: 1.7; margin: 0 0 22px; font-size: 13.5px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; }

.toast-root { position: fixed; top: 22px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #34231E; color: #FFF6E8; padding: 11px 20px; border-radius: 9px; font-size: 13.5px; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: fadeIn .18s ease; }
.toast.ok { background: #3F6B52; }
.toast.err { background: #96332F; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
    .login-view { grid-template-columns: 1fr; }
    .login-side { display: none; }
    .app-view { grid-template-columns: 68px minmax(0, 1fr); }
    .side-brand > div:not(.side-seal), .nav-item span:not(.nav-icon), .nav-group, .nav-badge, .cloud-status span:last-child, .side-logout { display: none; }
    .sidebar { align-items: center; }
    .side-brand { padding: 18px 0; border: none; }
    .side-nav { padding: 10px 6px; width: 100%; }
    .nav-item { justify-content: center; padding: 10px 0; }
    .topbar { padding: 0 16px; }
    .content { padding: 18px 16px 50px; }
}
