/**
 * ============================================================
 * [文件位置] assets/css/style.css
 * [主题] 深灰底 + 浅蓝点缀；列表行布局（弱化卡片）
 * [手机] 明细用竖向信息块，禁止横向拖拉才能看全
 * ============================================================
 */

/* ---------- [区域] 主题变量 ---------- */
:root {
    --bg: #12161c;
    --bg-soft: #181d25;
    --panel: #1b212b;
    --line: #2c3542;
    --accent: #6aa9e0;
    --accent-dim: rgba(106, 169, 224, 0.14);
    --text: #edf1f6;
    --text-2: #9aa6b5;
    --text-3: #6f7c8d;
    --danger: #e86a78;
    --ok: #4fbf95;
    --warn: #d9b15c;
    --radius: 10px;
    --topbar-h: 54px;
    --sidebar-w: 200px;
    --pad-x: 16px;
    --pad-y: 14px;
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: #8ec0eb; }

/* ---------- [区域] 顶栏 / 侧栏 ---------- */
.topbar {
    position: sticky; top: 0; z-index: 100;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 10px;
    padding: 0 var(--pad-x);
    background: var(--bg-soft);
    border-bottom: 1px solid var(--line);
}
.brand { flex: 1; font-weight: 700; font-size: 15px; color: var(--text); }
.top-user { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); }
.user-role {
    padding: 2px 8px; border-radius: 4px;
    background: var(--accent-dim); color: var(--accent);
}
.btn-link { color: var(--text-2); }
.menu-toggle {
    display: none; border: 0; width: 34px; height: 34px; border-radius: 8px;
    background: var(--panel); color: var(--text); font-size: 16px;
}

.app-shell { display: flex; min-height: calc(100vh - var(--topbar-h)); }
.sidebar {
    width: var(--sidebar-w); flex-shrink: 0;
    background: var(--bg-soft); border-right: 1px solid var(--line);
    padding: 12px 8px;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
    display: block; padding: 10px 12px; border-radius: 8px;
    color: var(--text-2); font-size: 13px;
}
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.sidebar-mask {
    display: none; position: fixed; inset: var(--topbar-h) 0 0 0;
    background: rgba(0,0,0,.45); z-index: 90;
}

.main-content {
    flex: 1; min-width: 0;
    padding: var(--pad-y) var(--pad-x) 36px;
}
.page-header { margin-bottom: 14px; }
.page-title { margin: 0; font-size: 20px; font-weight: 700; }

/* ---------- [区域] 面板（弱化卡片：无重阴影） ---------- */
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 12px;
}
.panel-title {
    margin: 0 0 12px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}
.section-card { /* 兼容旧类名 */
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    margin-top: 12px;
}
.section-title { margin: 0 0 12px; font-size: 15px; font-weight: 600; }

/* ---------- [区域] 指标条（替代大卡片宫格） ---------- */
.metric-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 12px;
}
.metric {
    background: var(--panel);
    padding: 14px 12px;
}
.metric-label { font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.metric-value { font-size: 20px; font-weight: 700; color: var(--text); word-break: break-all; }
.metric-value.accent { color: var(--accent); }
.metric-value.ok { color: var(--ok); }
.metric-value.warn { color: var(--warn); }
.metric-value.danger { color: var(--danger); }

/* 兼容旧 card 类，压成扁平指标 */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 12px;
}
.card {
    background: var(--panel);
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 14px 12px;
}
.card:hover { background: var(--panel); }
.card-label { font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.card-value { font-size: 20px; font-weight: 700; word-break: break-all; }
.card-sub { margin-top: 6px; font-size: 12px; color: var(--text-3); }
.card-accent, .card-ok, .card-warn, .card-danger { border-top: 0; }

/* ---------- [区域] 竖向记录列表（手机友好，无横向滚动） ---------- */
.record-list { display: flex; flex-direction: column; }
.record-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}
.record-item:last-child { border-bottom: 0; }
.record-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 8px;
}
.record-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    word-break: break-word;
}
.record-amount {
    flex-shrink: 0;
    font-size: 15px;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
}
.record-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    font-size: 12px;
    color: var(--text-2);
    line-height: 1.5;
}
.record-meta span { word-break: break-all; }
.record-actions {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* ---------- [区域] 桌面表格：手机隐藏，改用 record-list ---------- */
.table-wrap { overflow: visible; }
table.data-table {
    width: 100%;
    border-collapse: collapse;
}
.data-table th, .data-table td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    font-size: 13px;
    vertical-align: top;
}
.data-table th { color: var(--text-2); font-weight: 600; }
.data-table td { color: var(--text); word-break: break-word; }

.desktop-only { display: block; }
.mobile-only { display: none; }

/* ---------- [区域] 表单 / 按钮 ---------- */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    margin-bottom: 10px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 12px; color: var(--text-2); }
.form-control {
    width: 100%;
    padding: 11px 12px;
    min-height: 44px; /* 手机触控舒适高度 */
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--text);
    font-size: 16px; /* 避免 iOS 聚焦自动放大 */
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}
.form-control:focus { border-color: var(--accent); }
select.form-control { padding-right: 28px; }
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    border: 0; border-radius: 8px; padding: 11px 16px;
    min-height: 44px;
    font-size: 15px; cursor: pointer; color: var(--text);
    -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--accent); color: #0e1720; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--text-2); }
.btn-danger { background: var(--danger); }
.btn-sm { padding: 8px 12px; min-height: 36px; font-size: 13px; }
.btn-block { width: 100%; }
.toolbar {
    display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end;
    margin-bottom: 12px;
}
.muted { color: var(--text-3); font-size: 12px; }
.badge {
    display: inline-block; padding: 2px 7px; border-radius: 4px; font-size: 11px;
}
.badge-ok { background: rgba(79,191,149,.15); color: var(--ok); }
.badge-warn { background: rgba(217,177,92,.15); color: var(--warn); }
.badge-danger { background: rgba(232,106,120,.15); color: var(--danger); }

.item-rows { display: flex; flex-direction: column; gap: 8px; }
.item-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr auto;
    gap: 8px;
    align-items: end;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
}

/* ---------- [区域] 登录 / 备案 ---------- */
.auth-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 24px var(--pad-x) calc(24px + env(safe-area-inset-bottom, 0px));
    background: var(--bg);
}
.auth-wrap { width: 100%; max-width: 400px; }
.auth-card {
    width: 100%;
    background: var(--panel); border: 1px solid var(--line);
    border-radius: 12px; padding: 24px 18px;
}
.auth-card h1 { margin: 0 0 6px; font-size: 22px; }
.auth-card .auth-sub { margin: 0 0 18px; color: var(--text-2); font-size: 13px; }
.auth-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.auth-extra { margin-top: 14px; text-align: center; font-size: 14px; }
.icp-footer {
    margin-top: 18px;
    text-align: center;
    font-size: 12px;
    line-height: 1.6;
}
.icp-footer a { color: var(--text-3); }
.icp-footer a:hover { color: var(--text-2); }
.alert { padding: 10px 12px; border-radius: 8px; margin-bottom: 10px; font-size: 13px; }
.alert-error { background: rgba(232,106,120,.12); color: var(--danger); }
.alert-ok { background: rgba(79,191,149,.12); color: var(--ok); }

/* ---------- [区域] Toast 轻提示 ---------- */
.toast {
    position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%);
    z-index: 300; max-width: min(90vw, 320px);
    padding: 10px 14px; border-radius: 8px;
    background: rgba(20, 24, 30, 0.95); border: 1px solid var(--line);
    color: var(--text); font-size: 13px; text-align: center;
    box-shadow: 0 8px 20px rgba(0,0,0,.35);
}
.toast[hidden] { display: none !important; }

/* ---------- [区域] 手机底部导航 ---------- */
.bottom-nav { display: none; }

/* ---------- [区域] 手机端粘性操作条 ---------- */
.sticky-actions {
    display: none;
}

/* ---------- [区域] 弹窗 ---------- */
.modal-mask {
    position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 200;
    display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
    width: 100%; max-width: 520px; max-height: 85vh; overflow: auto;
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
}
.modal-header, .modal-footer {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.modal-footer { border-bottom: 0; border-top: 1px solid var(--line); justify-content: flex-end; flex-wrap: wrap; }
.modal-footer-stack { flex-direction: column; align-items: stretch; }
.modal-header h3 { margin: 0; font-size: 15px; }
.modal-close {
    border: 0; background: transparent; color: var(--text-2);
    font-size: 26px; line-height: 1; cursor: pointer;
    width: 40px; height: 40px;
}
.modal-body { padding: 14px; }

/* ---------- [区域] 手机端 ---------- */
@media (max-width: 900px) {
    :root {
        --pad-x: 14px;
        --bottom-nav-h: 58px;
    }
    .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
    .brand {
        font-size: 14px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .sidebar {
        position: fixed; top: var(--topbar-h); left: 0; bottom: 0; z-index: 95;
        transform: translateX(-105%); transition: transform .2s ease;
        width: min(82vw, 280px);
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-mask.show { display: block; }
    .user-name { display: none; }
    .nav-item { padding: 13px 14px; font-size: 15px; }
    .main-content {
        padding-left: max(var(--pad-x), env(safe-area-inset-left, 0px));
        padding-right: max(var(--pad-x), env(safe-area-inset-right, 0px));
        /* 给底部导航留空，避免内容被挡住 */
        padding-bottom: calc(18px + var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
    }
    .page-title { font-size: 18px; }
    .desktop-only { display: none !important; }
    .mobile-only { display: block !important; }
    .item-row { grid-template-columns: 1fr 1fr; }
    .metric-value, .card-value { font-size: 17px; }
    .metric, .card { padding: 12px 10px; }
    .record-actions .btn { flex: 1; min-width: 0; }
    .toolbar .form-control { max-width: none !important; flex: 1 1 100%; }
    .toolbar .btn { flex: 1 1 auto; }
    .table-wrap { overflow: visible; }
    table.data-table { display: none; }

    /* 底部快捷栏 */
    .bottom-nav {
        display: flex;
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 120;
        height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
        padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px));
        background: rgba(24, 29, 37, 0.96);
        border-top: 1px solid var(--line);
        backdrop-filter: blur(8px);
    }
    .bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        border: 0;
        background: transparent;
        color: var(--text-3);
        font-size: 11px;
        text-decoration: none;
        min-height: 48px;
        -webkit-tap-highlight-color: transparent;
    }
    .bottom-nav-item .bn-icon { font-size: 16px; line-height: 1; }
    .bottom-nav-item.active,
    .bottom-nav-item:active { color: var(--accent); }

    /* 销售录入等页：底部粘性保存条 */
    .sticky-actions {
        display: flex;
        position: fixed;
        left: 0; right: 0;
        bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
        z-index: 110;
        gap: 8px;
        padding: 10px var(--pad-x);
        background: rgba(18, 22, 28, 0.96);
        border-top: 1px solid var(--line);
    }
    .sticky-actions .btn { flex: 1; }
    body.has-sticky-actions .main-content {
        padding-bottom: calc(78px + var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
    }
    .toast { bottom: calc(70px + var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px)); }
}

@media (max-width: 480px) {
    :root { --pad-x: 12px; }
    .metric-row, .card-grid { grid-template-columns: 1fr 1fr; }
    .item-row { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
}
