:root {
    --primary: #2F6BFF;
    --primary-hover: #1A56DB;
    --primary-light: #E8F0FF;
    --bg: #F5F6F8;
    --bg-hover: #EEF2F8;
    --card-bg: #ffffff;
    --text: #1F2329;
    --text-secondary: #646A73;
    --text-tertiary: #9EA6B2;
    --border: #E4E9F0;
    --border-light: #F0F3F8;
    --error: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius: 8px;
    --radius-sm: 4px;
    --radius-lg: 12px;
    --shadow: 0 1px 4px rgba(31,35,41,0.06);
    --shadow-md: 0 2px 8px rgba(31,35,41,0.08);
    --shadow-lg: 0 4px 16px rgba(31,35,41,0.10);
    --ps-w: 72px;
    --ss-w: 100px;
    --ss-bg: #f8fafc;
    --sidebar-bg: #0F1C3F;
    --sidebar-text: #8FA3CC;
    --sidebar-item-hover: rgba(255,255,255,0.07);
    --sidebar-item-active: rgba(47,107,255,0.15);
}
* { margin: 0; padding: 0; box-sizing: border-box; scrollbar-width: none; }
::-webkit-scrollbar { display: none; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; line-height: 1.6; font-size: 15px; }
.hidden { display: none !important; }

/* === Auth === */
.auth-container { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(135deg, #1A56DB 0%, #2F6BFF 50%, #5B8FFF 100%); }
.auth-card { background: var(--card-bg); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 420px; padding: 40px; animation: fadeUp .4s ease-out; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.auth-logo { text-align: center; margin-bottom: 32px; }
.auth-logo h1 { font-size: 28px; font-weight: 700; color: var(--primary); }
.auth-logo p { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }
.auth-tabs { display: flex; background: var(--bg); border-radius: var(--radius); padding: 4px; margin-bottom: 28px; }
.auth-tab { flex: 1; padding: 10px; text-align: center; border: none; background: transparent; cursor: pointer; font-size: 14px; font-weight: 500; color: var(--text-secondary); border-radius: 6px; transition: all .2s; }
.auth-tab.active { background: var(--card-bg); color: var(--primary); box-shadow: 0 1px 3px rgb(0 0 0 / 0.1); }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 4px; color: var(--text); }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; outline: none; background: var(--bg); transition: border-color .2s, box-shadow .2s; color: var(--text); }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); background: #fff; }
.form-group textarea { resize: vertical; min-height: 60px; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 8px 16px; border: none; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; cursor: pointer; transition: all .2s; gap: 6px; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost { background: transparent; color: var(--text-secondary); padding: 6px 10px; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-loading { position: relative; color: transparent !important; }
.btn-loading::after { content: ''; position: absolute; width: 18px; height: 18px; border: 2px solid #fff; border-top-color: transparent; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 16px; display: none; }
.alert.show { display: block; }
.alert-error { background: rgb(239 68 68 / .1); color: var(--error); border: 1px solid rgb(239 68 68 / .2); }
.alert-success { background: rgb(34 197 94 / .1); color: #16a34a; border: 1px solid rgb(34 197 94 / .2); }

/* === App Layout (Three-Column) === */
.app-layout { display: flex; min-height: 100vh; }

/* --- Primary Sidebar: 72px module icon bar --- */
.primary-sidebar { width: var(--ps-w); background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 210; }
.ps-header { height: 56px; display: flex; align-items: center; justify-content: center; border-bottom: 1px solid rgba(255,255,255,0.06); }
.ps-logo { font-size: 15px; font-weight: 700; color: #fff; letter-spacing: -0.3px; }
.ps-nav { flex: 1; padding: 8px 0; overflow-y: auto; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.nav-module { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; width: 60px; padding: 8px 0; border-radius: 8px; color: var(--sidebar-text); text-decoration: none; cursor: pointer; transition: all .15s; position: relative; }
.nav-module:hover { background: var(--sidebar-item-hover); color: rgba(255,255,255,0.90); }
.nav-module.active { background: var(--sidebar-item-active); color: #fff; }
.nav-module.active::before { content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 3px; height: 24px; background: var(--primary); border-radius: 0 3px 3px 0; }
.nav-module svg { flex-shrink: 0; }
.nav-module-label { font-size: 11px; line-height: 1; white-space: nowrap; }
.ps-footer { padding: 10px 0; border-top: 1px solid rgba(255,255,255,0.06); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.ps-avatar { width: 32px; height: 32px; background: var(--primary); color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.ps-logout { background: none; border: 1px solid rgba(255,255,255,0.12); color: var(--sidebar-text); border-radius: var(--radius-sm); cursor: pointer; padding: 4px; display: flex; align-items: center; justify-content: center; transition: all .2s; }
.ps-logout:hover { background: rgba(239,68,68,0.18); color: #fca5a5; border-color: rgba(239,68,68,0.25); }

/* --- Sub Sidebar: 100px page nav --- */
.sub-sidebar { width: var(--ss-w); background: var(--ss-bg); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: fixed; top: 0; left: var(--ps-w); bottom: 0; z-index: 200; transition: transform .25s ease; }
.sub-sidebar.hidden { transform: translateX(calc(-1 * var(--ss-w))); }
.ss-header { height: 56px; display: flex; align-items: center; justify-content: space-between; padding: 0 10px; border-bottom: 1px solid var(--border-light); }
.ss-title { font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-toggle { background: none; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; padding: 4px; display: flex; align-items: center; color: var(--text-secondary); transition: all .2s; }
.ss-toggle:hover { background: var(--bg-hover); color: var(--text); }
.ss-nav { flex: 1; padding: 6px; overflow-y: auto; }
.ss-nav-item { display: flex; align-items: center; gap: 6px; padding: 8px 8px; border-radius: 6px; color: var(--text-secondary); text-decoration: none; cursor: pointer; transition: all .15s; font-size: 13px; margin-bottom: 1px; position: relative; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-nav-item:hover { background: var(--bg-hover); color: var(--text); }
.ss-nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 500; }
.ss-nav-item.active::before { content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 3px; height: 16px; background: var(--primary); border-radius: 0 2px 2px 0; }
.ss-nav-divider { height: 1px; background: var(--border-light); margin: 6px 8px; }

/* 旺店通分组样式 */
.ss-nav-group { margin-bottom: 4px; }
.ss-nav-group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 8px;
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    background: transparent;
    user-select: none;
}
.ss-nav-group-header:hover { background: var(--bg-hover); }
.ss-nav-group-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: transform .2s ease;
    flex-shrink: 0;
}
.ss-nav-group-arrow.expanded { transform: rotate(0deg); }
.ss-nav-group-arrow:not(.expanded) { transform: rotate(-90deg); }
.ss-nav-group-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}
.ss-nav-group-content {
    display: none;
    padding-left: 8px;
    margin-top: 2px;
}
.ss-nav-group-content.expanded { display: block; }
.ss-nav-group-content .ss-nav-item {
    padding-left: 14px;
}

.ss-footer { padding: 8px 8px; border-top: 1px solid var(--border-light); }
.ss-user-info { margin-bottom: 4px; }
.ss-username { font-size: 12px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-role { font-size: 10px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-tenant { font-size: 10px; color: var(--primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; font-weight: 500; cursor: pointer; transition: opacity .2s; }
.ss-tenant:hover { opacity: 0.7; text-decoration: underline; }
.ss-change-pwd { background: none; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; padding: 3px 4px; display: inline-flex; align-items: center; color: var(--text-secondary); transition: all .2s; font-size: 11px; }
.ss-change-pwd:hover { background: var(--bg-hover); color: var(--text); }

/* --- Main Content: dynamic margin --- */
.main-content { flex: 1; margin-left: calc(var(--ps-w) + var(--ss-w)); min-height: 100vh; min-width: 0; overflow-x: hidden; transition: margin-left .25s ease; background: #f5f7fa; }
.main-content.ss-collapsed { margin-left: var(--ps-w); }

/* Sub-sidebar expand button (shown when sub-sidebar is collapsed) */
.ss-expand-btn {
    position: fixed;
    top: 50%;
    left: var(--ps-w);
    transform: translateY(-50%);
    z-index: 199;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    cursor: pointer;
    padding: 8px 4px;
    display: flex;
    align-items: center;
    color: var(--text-secondary);
    transition: all .2s;
    box-shadow: 2px 0 8px rgba(0,0,0,0.06);
}
.ss-expand-btn:hover { background: var(--bg-hover); color: var(--text); }
.ss-expand-btn.hidden { display: none; }
.top-bar { height: 56px; background: var(--card-bg); box-shadow: 0 1px 0 var(--border); display: flex; align-items: center; padding: 0 24px; gap: 12px; position: sticky; top: 0; z-index: 100; }
.sidebar-toggle { display: none; background: none; border: none; cursor: pointer; color: var(--text-secondary); padding: 4px; }
.page-title { font-size: 17px; font-weight: 600; color: var(--text); }
.page-wrap { padding: 7px 24px 20px; height: 100%; display: flex; flex-direction: column; }
.page { animation: fadeUp .3s ease-out; }

/* === Card === */
.card { background: var(--card-bg); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden; }
.card-header { padding: 14px 20px; border-bottom: 1px solid var(--border-light); display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { font-size: 15px; font-weight: 600; color: var(--text); }
.card-body { padding: 16px 20px; }
.empty-text { color: var(--text-secondary); font-size: 14px; text-align: center; padding: 20px 0; }
.mt-16 { margin-top: 16px; }

/* === Content Card (table wrapper) === */
.content-card { background: var(--card-bg); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden; }
.content-card-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--border-light); }
.content-card-title { font-size: 15px; font-weight: 600; color: var(--text); }
.content-card-actions { display: flex; align-items: center; gap: 8px; }
.user-filter-tabs { display: flex; background: var(--bg); border-radius: var(--radius-sm); padding: 2px; gap: 2px; }
.user-filter-tabs .btn { border-radius: 4px; padding: 4px 10px; font-size: 12px; }
.user-filter-tabs .btn.active { background: var(--card-bg); color: var(--primary); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }
.content-card-body { padding: 0; overflow-x: auto; }
.content-card-body.with-padding { padding: 16px 20px; }

/* === Filter Card === */
.filter-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; box-shadow: var(--shadow); }
.filter-card label { font-size: 14px; color: var(--text-secondary); font-weight: 500; white-space: nowrap; }
.filter-card select,
.filter-card input[type="text"],
.filter-card input[type="date"],
.filter-card input[type="month"] { padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; background: var(--bg); color: var(--text); outline: none; transition: border-color .2s; }
.filter-card select:focus,
.filter-card input:focus { border-color: var(--primary); background: #fff; }
.filter-card .checkbox-inline { display: flex; align-items: center; gap: 4px; font-size: 14px; cursor: pointer; }

/* === Toolbar === */
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.toolbar h3 { font-size: 16px; font-weight: 600; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; }
.toolbar-select { padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; background: var(--bg); outline: none; }
.filter-row { display: flex; gap: 8px; align-items: center; }
.filter-row select, .filter-row input { padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; background: #fff; }

/* === Log table (shared) === */
.log-table-wrap { overflow-x: auto; }
.log-table { width: 100%; border-collapse: collapse; background: var(--card-bg); font-size: 14px; }
.log-table th, .log-table td { padding: 10px 16px; text-align: left; border-bottom: 1px solid var(--border-light); }
.log-table th { background: #F8FAFB; font-weight: 600; color: var(--text-secondary); font-size: 13px; white-space: nowrap; }
.log-table tr:last-child td { border-bottom: none; }
.log-table tbody tr:hover { background: var(--bg-hover); }
.log-status { display: inline-block; padding: 2px 8px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 600; }
.log-status.success { background: #dcfce7; color: #166534; }
.log-status.failed { background: #fee2e2; color: #991b1b; }
.log-status.retry { background: #fef9c3; color: #854d0e; }
.log-resp { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--text-secondary); }

/* === Pagination === */
.pagination { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 16px; }
.pagination button { padding: 6px 12px; border: 1px solid var(--border); background: var(--card-bg); border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; }
.pagination button:hover { background: var(--primary-light); }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }

/* === Modal === */
.modal-overlay { position: fixed; inset: 0; background: rgb(0 0 0 / .5); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; animation: fadeIn .2s; }
@keyframes fadeIn { from { opacity: 0; } }
.modal { background: var(--card-bg); border-radius: var(--radius-lg); width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; animation: fadeUp .3s ease-out; }
.modal.modal-wide { max-width: 900px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 0; }
.modal-header h3 { font-size: 17px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 24px; color: var(--text-secondary); cursor: pointer; padding: 0 4px; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px 24px 24px; }
.modal-body .btn-primary { margin-top: 8px; }
.checkbox-group { display: flex; flex-wrap: wrap; gap: 8px; }
.checkbox-label { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; transition: all .15s; }
.checkbox-label:has(input:checked) { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
.checkbox-label input { accent-color: var(--primary); }

/* === Toggle Switch (global) === */
.toggle-switch { position: relative; display: inline-block; width: 40px; height: 22px; vertical-align: middle; cursor: pointer; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: #D0D7E3; border-radius: 22px; transition: background .2s; }
.toggle-slider::before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,0.15); }
.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }
.toggle-switch input:disabled + .toggle-slider { opacity: 0.5; cursor: not-allowed; }

/* === Stat Cards === */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: var(--card-bg); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); padding: 20px; position: relative; overflow: hidden; }
.stat-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--primary); }
.stat-card:nth-child(2)::before { background: var(--success); }
.stat-card:nth-child(3)::before { background: var(--warning); }
.stat-card:nth-child(4)::before { background: var(--error); }
.stat-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.stat-num { font-size: 28px; font-weight: 700; color: var(--text); }

/* === Home module cards === */
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }

/* === Form grid / actions (used by customer & other modules) === */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.form-actions { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.filter-card { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; padding: 12px 16px; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); }
.filter-card select, .filter-card input[type="text"] { padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; background: var(--bg); outline: none; min-width: 120px; color: var(--text); }
.filter-card select:focus, .filter-card input[type="text"]:focus { border-color: var(--primary); background: #fff; }
.batch-header { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.batch-table-container { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.module-card { background: var(--card-bg); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); padding: 24px 20px; cursor: pointer; transition: all .2s; position: relative; }
.module-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.module-card-icon { width: 48px; height: 48px; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; margin-bottom: 16px; }
.module-card-icon svg { width: 24px; height: 24px; }
.module-card-title { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.module-card-desc { font-size: 14px; color: var(--text-secondary); line-height: 1.5; }
/* Module card locked state (tenant not enabled) */
.module-card.locked { cursor: not-allowed; pointer-events: none; opacity: 0.7; }
.module-card.locked:hover { border-color: var(--border); box-shadow: var(--shadow); transform: none; }
.module-card-lock { position: absolute; top: 12px; right: 12px; width: 20px; height: 20px; color: var(--text-secondary); display: none; }
.module-card.locked .module-card-lock { display: block; }
.module-card-locked-text { font-size: 12px; color: var(--text-secondary); margin-top: 8px; display: none; }
.module-card.locked .module-card-locked-text { display: block; }

/* === Responsive === */
@media (max-width: 768px) {
    .primary-sidebar { transform: translateX(-100%); }
    .primary-sidebar.open { transform: translateX(0); }
    .sub-sidebar { transform: translateX(calc(-1 * var(--ps-w) - var(--ss-w))); }
    .sub-sidebar.open { transform: translateX(0); }
    .main-content, .main-content.ss-collapsed { margin-left: 0; }
    .sidebar-toggle { display: block; }
    .ss-expand-btn { left: 0; }
    .form-row { grid-template-columns: 1fr; }
    .module-grid { grid-template-columns: 1fr; }
    .stats-row { grid-template-columns: 1fr 1fr; }
}
