/* 沉湖鲜 · 溯源管理后台 */
:root {
    --brand: #0f3d2e;
    --brand-light: #1a5c45;
    --brand-muted: #e8f3ef;
    --accent: #c9a962;
    --accent-dark: #a8863f;
    --bg: #f0f2f5;
    --surface: #ffffff;
    --text: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --border-light: #f3f4f6;
    --success: #059669;
    --danger: #dc2626;
    --warning: #d97706;
    --info: #0284c7;
    --sidebar-w: 228px;
    --header-h: 58px;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(15, 61, 46, 0.06), 0 4px 16px rgba(15, 61, 46, 0.04);
    --shadow-lg: 0 8px 32px rgba(15, 61, 46, 0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── 登录页 ── */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(145deg, #0a2e22 0%, #0f3d2e 40%, #1a5c45 100%);
    position: relative;
    overflow: hidden;
}
.login-wrap::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse 80% 60% at 20% 80%, rgba(201, 169, 98, 0.12), transparent 50%),
                radial-gradient(ellipse 60% 40% at 90% 10%, rgba(255, 255, 255, 0.06), transparent 40%);
    pointer-events: none;
}
.login-box {
    position: relative;
    background: var(--surface);
    border-radius: 16px;
    padding: 40px 36px 36px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}
.login-brand {
    text-align: center;
    margin-bottom: 28px;
}
.login-brand img {
    display: block;
    width: min(240px, 100%);
    height: auto;
    max-height: 48px;
    margin: 0 auto 16px;
    object-fit: contain;
}
.login-brand h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--brand);
    letter-spacing: 0.02em;
}
.login-brand p {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 6px;
}
.login-hint {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 20px;
    padding: 10px 14px;
    background: var(--brand-muted);
    border-radius: 8px;
}
.login-hint a { color: var(--brand-light); font-weight: 600; text-decoration: none; }
.login-hint a:hover { text-decoration: underline; }
.login-error {
    background: #fef2f2;
    color: var(--danger);
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    border: 1px solid #fecaca;
}

/* ── 顶栏 ── */
.header {
    background: var(--brand);
    color: #fff;
    padding: 0 20px 0 0;
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(15, 61, 46, 0.2);
}
.header-left {
    display: flex;
    align-items: center;
    gap: 0;
    min-width: 0;
}
.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    height: var(--header-h);
    background: rgba(0, 0, 0, 0.12);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}
.header-brand img {
    height: 32px;
    width: auto;
    max-width: 120px;
    object-fit: contain;
    filter: brightness(1.05);
}
.header-brand-text strong {
    display: block;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
}
.header-brand-text small {
    display: block;
    font-size: 11px;
    opacity: 0.75;
    margin-top: 1px;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}
.header-ops-link {
    color: #fff;
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 20px;
    background: rgba(201, 169, 98, 0.22);
    border: 1px solid rgba(201, 169, 98, 0.45);
    white-space: nowrap;
    font-size: 12px;
    font-weight: 600;
}
.header-ops-link:hover {
    background: rgba(201, 169, 98, 0.35);
}
.header-user {
    opacity: 0.9;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
}
.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    padding: 8px 12px;
    margin-left: 4px;
}

/* ── 布局 ── */
.layout {
    display: flex;
    min-height: calc(100vh - var(--header-h));
}

/* ── 侧边栏 ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    flex-shrink: 0;
    padding: 16px 0 24px;
    overflow-y: auto;
}
.nav-group-label {
    padding: 12px 20px 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px 10px 20px;
    margin: 2px 8px;
    cursor: pointer;
    font-size: 14px;
    color: #4b5563;
    border-radius: 8px;
    border-left: none;
    transition: background 0.15s, color 0.15s;
}
.nav-item:hover {
    background: var(--brand-muted);
    color: var(--brand);
}
.nav-item.active {
    background: var(--brand-muted);
    color: var(--brand);
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--accent);
}
.nav-item .icon {
    font-size: 17px;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}
.nav-item-external { opacity: 0.85; }

/* ── 主内容 ── */
.main {
    flex: 1;
    padding: 24px 28px 40px;
    overflow-x: auto;
    min-width: 0;
}
.page { display: none; }
.page.active { display: block; }

.page-head {
    margin-bottom: 20px;
}
.page-head h2 {
    font-size: 22px;
    font-weight: 700;
    color: var(--brand);
    margin-bottom: 4px;
}
.page-head p {
    font-size: 14px;
    color: var(--text-muted);
}

/* ── 按钮 ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: #fff;
    padding: 7px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s, transform 0.1s;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { background: rgba(255, 255, 255, 0.12); }
.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #1a1a1a;
    font-weight: 600;
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-outline {
    color: var(--text);
    border-color: var(--border);
    background: var(--surface);
}
.btn-outline:hover { background: var(--border-light); border-color: #d1d5db; }
.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: 6px; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-xs { padding: 3px 8px; font-size: 11px; }

/* ── 卡片 ── */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    overflow: hidden;
    border: 1px solid var(--border-light);
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    background: #fafbfc;
}
.card-header h2, .card-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-body { padding: 20px; }
.card-body h4 {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
    font-weight: 600;
}

/* ── 统计卡片 ── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    display: flex;
    align-items: flex-start;
    gap: 14px;
    transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(15, 61, 46, 0.08);
}
.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.stat-card.gold .stat-icon { background: #fef9e7; }
.stat-card.blue .stat-icon { background: #eff6ff; }
.stat-card.green .stat-icon { background: #ecfdf5; }
.stat-card.orange .stat-icon { background: #fff7ed; }
.stat-body { min-width: 0; }
.stat-card .label { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.stat-card .value { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat-card.gold .value { color: var(--accent-dark); }
.stat-card.blue .value { color: var(--info); }
.stat-card.green .value { color: var(--success); }
.stat-card.orange .value { color: var(--warning); }
.stat-card.red .stat-icon { background: #fef2f2; }
.stat-card.red .value { color: var(--danger); }
.stat-card-clickable { cursor: pointer; }
.stat-card-clickable:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(15, 61, 46, 0.08); }
.stat-card-clickable.has-alert { border-color: #fecaca; background: linear-gradient(135deg, #fff 0%, #fff5f5 100%); }
.stat-card-clickable.has-alert .value { color: var(--danger); }

/* ── 表格 ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
    background: #f9fafb;
    text-align: left;
    padding: 11px 14px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    font-size: 12px;
}
td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}
tbody tr:hover td { background: #f9fafb; }
tbody tr:last-child td { border-bottom: none; }
code {
    background: #f3f4f6;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 12px;
    font-family: ui-monospace, 'Cascadia Code', monospace;
    color: var(--brand);
}

/* ── 徽章 ── */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-generated { background: #eff6ff; color: #1d4ed8; }
.badge-allocated { background: #fffbeb; color: #b45309; }
.badge-installed { background: #ecfdf5; color: #047857; }
.badge-shipped { background: #fef2f2; color: #b91c1c; }
.badge-approved, .badge-active { background: #ecfdf5; color: #047857; }
.badge-pending { background: #fffbeb; color: #b45309; }
.badge-disabled { background: #f3f4f6; color: #6b7280; }
.badge-farmer { background: #eff6ff; color: #1d4ed8; }
.badge-merchant { background: #fef2f2; color: #b91c1c; }
.badge-combo { background: #f5f3ff; color: #6d28d9; }
.badge-male { background: #eff6ff; color: #2563eb; }
.badge-female { background: #fdf2f8; color: #be185d; }
.badge-packing { background: #fffbeb; color: #b45309; }
.badge-delivered { background: #ecfdf5; color: #047857; }

.empty {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}
.empty .icon {
    font-size: 40px;
    margin-bottom: 12px;
    opacity: 0.45;
    display: block;
}

/* ── 表单 ── */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: #fff;
}
.form-control:focus {
    outline: none;
    border-color: var(--brand-light);
    box-shadow: 0 0 0 3px rgba(15, 61, 46, 0.1);
}
textarea.form-control { min-height: 72px; resize: vertical; font-family: ui-monospace, monospace; font-size: 13px; }
select.form-control { appearance: auto; }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 200px; }
.section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--brand);
    margin: 20px 0 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
}

/* ── 搜索栏 ── */
.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    align-items: center;
    flex-wrap: wrap;
}
.search-bar input,
.search-bar select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    background: #fff;
}
.search-bar input { min-width: 200px; }
.search-bar input:focus,
.search-bar select:focus {
    outline: none;
    border-color: var(--brand-light);
}

.filter-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-tabs .btn-sm { border-color: var(--border); color: var(--text); }
.filter-tabs .btn-sm.is-active {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

/* ── 分页 ── */
.pagination {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-top: 16px;
    flex-wrap: wrap;
}
.pagination button {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
}
.pagination button.active {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── 弹窗 ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 61, 46, 0.45);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    padding: 16px;
}
.modal-overlay.show { opacity: 1; pointer-events: auto; }
.modal {
    background: #fff;
    border-radius: 14px;
    width: 100%;
    max-width: 560px;
    max-height: 88vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal.modal-wide { max-width: 960px; }
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fafbfc;
    position: sticky;
    top: 0;
    z-index: 1;
}
.modal-header h3 { font-size: 16px; font-weight: 600; color: var(--brand); }
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
    padding: 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: #fafbfc;
}

/* ── Toast ── */
.toast {
    position: fixed;
    top: calc(var(--header-h) + 12px);
    right: 20px;
    padding: 12px 18px;
    border-radius: 10px;
    color: #fff;
    font-size: 14px;
    z-index: 300;
    transform: translateX(calc(100% + 24px));
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
    max-width: min(360px, calc(100vw - 40px));
}
.toast.show { transform: translateX(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--info); }

/* ── 时间线 / 溯源结果 ── */
.timeline {
    border-left: 2px solid var(--accent);
    padding-left: 24px;
    margin-left: 8px;
}
.timeline-item { margin-bottom: 20px; position: relative; }
.timeline-item::before {
    content: '';
    position: absolute;
    left: -30px;
    top: 6px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px var(--accent);
}
.timeline-time { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.timeline-title { font-weight: 600; font-size: 14px; }
.timeline-data {
    font-size: 13px;
    color: #4b5563;
    margin-top: 6px;
    background: #f9fafb;
    padding: 8px 12px;
    border-radius: 8px;
}
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}
.trace-ring-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-top: 12px;
}
.trace-ring-card {
    background: var(--brand-muted);
    border-radius: 10px;
    padding: 14px;
    text-align: center;
    border: 1px solid #d1e7de;
}
.trace-ring-card code {
    background: #fff;
    color: var(--brand);
    font-size: 11px;
}

.action-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.cb-list {
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
}
.cb-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 6px;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    border-radius: 4px;
}
.cb-item:last-child { border-bottom: none; }
.cb-item:hover { background: #f9fafb; }

/* ── 扫码发货 ── */
#scan-area { display: flex; flex-direction: column; gap: 16px; padding: 4px 0; }
.scan-section { display: flex; flex-direction: column; gap: 8px; }
.scan-row { display: flex; gap: 8px; align-items: center; }
.scan-input {
    flex: 1;
    padding: 10px 12px;
    font-size: 15px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    outline: none;
}
.scan-input:focus { border-color: var(--brand-light); }
.scan-tags {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    min-height: 56px;
}
.scan-empty { color: #9ca3af; font-size: 13px; padding: 4px 0; }
.ring-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--brand-muted);
    border: 1px solid #c5ddd4;
    border-radius: 16px;
    padding: 4px 10px;
    font-size: 13px;
}
.ring-tag b { color: var(--danger); cursor: pointer; font-size: 16px; font-weight: 400; }
.track-preview { font-size: 13px; color: #555; }
.track-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: 16px;
    padding: 4px 10px;
}
.carrier-tag {
    background: var(--success);
    color: #fff;
    border-radius: 10px;
    padding: 1px 6px;
    font-size: 11px;
}
.scan-tip { text-align: center; color: #9ca3af; font-size: 12px; padding: 4px 0; }
.btn-scan {
    padding: 10px 14px;
    background: var(--info);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    white-space: nowrap;
    cursor: pointer;
}
.btn-scan:active { background: #0369a1; }
.partner-display { margin-top: 4px; }
.partner-ok { color: var(--success); font-size: 14px; }

.hint-box {
    font-size: 13px;
    color: #4b5563;
    margin: 0 0 14px;
    padding: 12px 14px;
    background: #fffbeb;
    border-radius: 8px;
    border: 1px solid #fde68a;
}

.btn-block { width: 100%; padding: 12px; font-size: 15px; margin-top: 4px; }

@media (max-width: 900px) {
    .stats-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
    .menu-toggle { display: block; }
    .header-brand-text small { display: none; }
    .header-ops-link span { display: none; }
    .sidebar {
        position: fixed;
        top: var(--header-h);
        left: 0;
        height: calc(100vh - var(--header-h));
        z-index: 99;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }
    .main { padding: 16px; }
    .form-row { flex-direction: column; }
    .stats-row { grid-template-columns: 1fr 1fr; }
    .header-brand { padding: 0 12px; }
}
