/* 精算盘 ERP v2.0 - Style */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --sidebar-w: 220px;
    --header-h: 56px;
}
* { margin:0; padding:0; box-sizing:border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }

/* ── Login ── */
.login-wrapper { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: linear-gradient(135deg, #1e293b 0%, #334155 100%); }
.login-card { background: var(--surface); border-radius: 12px; padding: 40px; width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-card .login-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 8px; }
.login-card .login-brand img { width: 80px; height: 80px; object-fit: contain; }
.login-card .login-brand h1 { text-align: center; font-size: 22px; margin: 0; }
.login-card .sub { text-align: center; color: var(--text-muted); margin-bottom: 32px; }
.login-card .form-group { margin-bottom: 16px; }
.login-card label { display: block; margin-bottom: 4px; font-weight: 600; font-size: 13px; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
.login-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
.login-card .btn-login { width: 100%; padding: 12px; background: var(--primary); color: white; border: none; border-radius: 6px; font-size: 16px; font-weight: 600; cursor: pointer; margin-top: 8px; }
.login-card .btn-login:hover { background: var(--primary-dark); }
.login-error { color: var(--danger); font-size: 13px; text-align: center; margin-top: 8px; }

/* ── Login options ── */
.login-options { display: flex; gap: 20px; margin-bottom: 12px; }
.checkbox-label { display: flex !important; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); font-weight: 400; cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* ── App Shell ── */
.app-shell { display: none; min-height: 100vh; }
.app-shell.active { display: flex; }
.sidebar { width: var(--sidebar-w); background: #1e293b; color: #cbd5e1; position: fixed; top: 0; left: 0; bottom: 0; overflow-y: auto; z-index: 100; }
.sidebar-header { padding: 12px 16px; border-bottom: 1px solid #334155; font-size: 15px; font-weight: 700; color: white; display: flex; align-items: center; gap: 10px; }
.sidebar-header img { width: 32px; height: 32px; object-fit: contain; border-radius: 6px; background: white; padding: 2px; }
.sidebar-nav { padding: 8px 0; }
.nav-section { padding: 12px 16px 4px; font-size: 11px; color: #64748b; text-transform: uppercase; letter-spacing: 1px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; cursor: pointer; transition: background .15s; font-size: 13px; }
.nav-item:hover { background: #334155; color: white; }
.nav-item.active { background: var(--primary); color: white; }
.nav-item .icon { font-size: 16px; width: 20px; text-align: center; }

.main-area { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.header { height: var(--header-h); background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top:0; z-index: 50; }
.header .user-info { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.header .btn-logout { padding: 6px 16px; border: 1px solid var(--border); border-radius: 6px; background: none; cursor: pointer; font-size: 13px; }
.header .btn-logout:hover { background: var(--bg); }
.content { flex: 1; padding: 24px; }

/* ── Pages ── */
.page { display: none; animation: fadeIn .2s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.page-title { font-size: 20px; font-weight: 700; margin-bottom: 20px; display: flex; align-items: center; gap: 8px; }
.page-title .icon { font-size: 22px; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 16px; }
.card-header { padding: 12px 16px; font-weight: 600; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; font-size: 14px; }
.card-body { padding: 16px; }

/* ── Toolbar ── */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar select, .toolbar input[type="text"], .toolbar input[type="date"] { padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.inv-tab { border: none; border-radius: 0; background: var(--surface); color: var(--text-muted); padding: 8px 16px; font-weight: 500; cursor: pointer; transition: all .15s; }
.inv-tab.active { background: var(--primary); color: #fff; }
.inv-tab:hover:not(.active) { background: var(--bg-hover, #f0f0f0); }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer; border: 1px solid var(--border); background: var(--surface); transition: all .15s; }
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-xs { padding: 2px 8px; font-size: 11px; }
.btn-icon { padding: 6px; background: none; border: none; cursor: pointer; font-size: 16px; }

/* ── Tables ── */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 12px; background: #f1f5f9; font-weight: 600; border-bottom: 2px solid var(--border); white-space: nowrap; }
td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
tr:hover { background: #f8fafc; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

/* ── Stats Grid ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.stat-card .label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.stat-card .value { font-size: 22px; font-weight: 700; }
.stat-card .value.blue { color: var(--primary); }
.stat-card .value.green { color: var(--success); }
.stat-card .value.red { color: var(--danger); }

/* ── Forms ── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 4px; font-weight: 600; font-size: 13px; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.form-group textarea { min-height: 60px; resize: vertical; }
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

/* ── Modal ── */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 200; justify-content: center; align-items: flex-start; padding-top: 24px; padding-bottom: 24px; overflow-y: auto; }
.modal-overlay.active { display: flex; }
.modal { background: var(--surface); border-radius: 12px; width: 760px; max-width: calc(100vw - 48px); max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.modal-header { padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; font-weight: 600; font-size: 15px; flex-shrink: 0; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-shrink: 0; }
.modal-sm { width: 480px; }
.modal-lg { width: 980px; }
.modal-xl { width: 1320px; }
.modal-xxl { width: 1500px; }

/* ── Badges ── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-draft { background: #fef3c7; color: #92400e; }
.badge-confirmed, .badge-posted { background: #dcfce7; color: #166534; }
.badge-reversed { background: #fee2e2; color: #991b1b; }
.badge-cancelled { background: #e5e7eb; color: #4b5563; }
.badge-primary { background: #dbeafe; color: #1e40af; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #e0f2fe; color: #0369a1; cursor: pointer; }

/* ── Alerts ── */
.alert { padding: 10px 16px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; }
.alert-info { background: #dbeafe; color: #1e40af; }
.alert-success { background: #dcfce7; color: #166534; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-danger { background: #fee2e2; color: #991b1b; }

/* ── Tabs ── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.tab { padding: 10px 20px; cursor: pointer; font-weight: 500; font-size: 13px; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; background: none; border-left: none; border-right: none; border-top: none; border-radius: 0; font-family: inherit; color: inherit; }
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Amazon Settlement Tabs (in-result) ── */
.az-tab-content { border: 1px solid var(--border); border-top: none; border-radius: 0 0 8px 8px; padding: 12px; background: #fff; max-height: 600px; overflow: auto; }

/* ── Loading ── */
.loading { text-align: center; padding: 40px; color: var(--text-muted); }

/* ── Template Mapping Editor ── */
.mapping-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.mapping-row .col-name { flex: 0 0 200px; font-weight: 600; font-size: 12px; }
.mapping-row select { flex: 1; padding: 6px 10px; border: 1px solid var(--border); border-radius: 4px; font-size: 12px; }
.mapping-row .flag-new { color: var(--warning); font-size: 11px; }

/* ── Highlight ── */
.highlight-row { background: #fef9c3; }

/* ── Unmapped field list (clickable) ── */
.unmapped-list { max-height: 300px; overflow: auto; font-size: 13px; background: #fffbeb; border: 1px solid #fde68a; border-radius: 6px; padding: 8px; }
.unmapped-item { padding: 8px 10px; margin-bottom: 4px; border-radius: 4px; cursor: pointer; color: #92400e; transition: background .15s; }
.unmapped-item:hover { background: #fef3c7; color: #78350f; }
.unmapped-item:last-child { margin-bottom: 0; }

/* ── Amazon settlement original summary / voucher tables ── */
.az-original-summary th,
.az-original-summary td,
.az-voucher-preview th,
.az-voucher-preview td { white-space: nowrap; font-size: 12px; }
.az-original-summary th { background: #f1f5f9; position: sticky; top: 0; z-index: 1; }
.az-original-summary td:first-child,
.az-original-summary th:first-child { position: sticky; left: 0; background: #fff; z-index: 2; }
.az-original-summary th:first-child { background: #f1f5f9; }
.az-original-summary .unmapped-row { background: #fff5f5; }
.az-original-summary .unmapped-row td:nth-child(2),
.az-original-summary .unmapped-row td:nth-child(3) { color: #e11d48; font-weight: 600; }
.az-voucher-preview th { background: #f0fdf4; }
.az-voucher-preview td:nth-child(5),
.az-voucher-preview td:nth-child(8) { color: #166534; font-weight: 500; }

/* ── Settlement mapping settings table ── */
#mapping-list td { font-size: 13px; vertical-align: middle; }
#mapping-list .text-danger { color: var(--danger); font-weight: 600; }

/* ── Modal form helpers ── */
.modal-body .form-row { display: flex; gap: 16px; }
.modal-body .form-row .form-group { flex: 1; }
.modal-body select { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; }
.modal-body input[type="text"], .modal-body input[type="date"], .modal-body input[type="number"] { width: 100%; }

/* ── Mobile Responsive ── */
.hamburger { display: none; font-size: 20px; background: none; border: none; cursor: pointer; padding: 4px 8px; color: var(--text); }
.sidebar-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.4); z-index: 99; }
.sidebar-overlay.active { display: block; }

@media (max-width: 768px) {
    /* Sidebar becomes off-canvas drawer */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 200;
        width: 240px;
    }
    .sidebar.open { transform: translateX(0); }
    .hamburger { display: block; }

    /* Full width main area */
    .main-area { margin-left: 0; }

    /* Header adjustments */
    .header { padding: 0 12px; }
    .page-title { font-size: 16px; }
    .header .user-info { gap: 8px; }
    .header .btn-logout { padding: 4px 10px; font-size: 12px; }

    /* Content padding */
    .content { padding: 12px; }

    /* Toolbar: stack vertically (仅作用于直接子按钮，避免误伤 tab 按钮组) */
    .toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
    .toolbar select, .toolbar input[type="text"], .toolbar input[type="date"] { width: 100%; }
    .toolbar > .btn { width: 100%; justify-content: center; }

    /* Form rows stack */
    .form-row { flex-direction: column; gap: 0; }

    /* Cards */
    .card-header { font-size: 13px; padding: 10px 12px; }
    .card-body { padding: 12px; }

    /* Tables: make them scrollable but with smaller text */
    table { font-size: 12px; }
    th { padding: 8px 6px; }
    td { padding: 6px 6px; }

    /* Stats grid: 2 columns */
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat-card { padding: 12px; }
    .stat-card .value { font-size: 18px; }

    /* Modal: full width */
    .modal { width: 95vw !important; max-width: 95vw !important; border-radius: 8px; }
    .modal-overlay { padding-top: 12px; padding-bottom: 12px; }
    .modal-lg, .modal-xl, .modal-xxl { width: 95vw !important; max-width: 95vw !important; }

    /* Login card */
    .login-card { width: 92vw; padding: 28px 20px; margin: 16px; }
    .login-card h1 { font-size: 20px; }

    /* Tabs: scrollable */
    .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .tab { padding: 8px 12px; white-space: nowrap; font-size: 12px; }

    /* 手机端: tab 按钮组可横向滑动，不撑破页面 */
    .toolbar .tab-group { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
    .inv-tab { white-space: nowrap; flex-shrink: 0; width: auto !important; justify-content: center; }

    /* 手机端: 表格容器限制在视口内，宽表内部横向滑动 */
    .table-container { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* 手机端: flex 主区允许收缩，防止宽内容撑破布局 */
    .main-area { min-width: 0; }
    .content { min-width: 0; }

    /* 手机端: 统计卡片不超出屏幕 */
    .stats-grid { min-width: 0; }
    .stat-card { min-width: 0; overflow: hidden; }

    /* Amazon settlement tables */
    .az-original-summary th, .az-original-summary td,
    .az-voucher-preview th, .az-voucher-preview td { font-size: 11px; }
}

@media (max-width: 480px) {
    /* Extra small screens */
    .stats-grid { grid-template-columns: 1fr; }
    .login-card h1 { font-size: 18px; }
    .login-card .sub { font-size: 12px; }
    .sidebar { width: 220px; }
    .nav-item { padding: 12px 16px; font-size: 14px; }
    .nav-item .icon { font-size: 18px; }
}
