/*
 * 鹏星国际采购跟单系统样式
 * 参考业务流转表系统风格：蓝白主色、卡片式区块、圆角表格
 * Version: 1.0.0
 */

:root {
    --primary: #1a5fb4;
    --primary-dark: #104a8e;
    --success: #26a269;
    --warning: #e5a50a;
    --danger: #e01b24;
    --bg: #f6f8fb;
    --card: #ffffff;
    --text: #1c1c1c;
    --text-muted: #666666;
    --border: #d8dee9;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    --header-height: 56px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ==================== 登录页 ==================== */
.login-body,
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a5fb4 0%, #1c71d8 100%);
}

.login-card {
    background: var(--card);
    width: 100%;
    max-width: 420px;
    padding: 40px 32px;
    border-radius: var(--radius);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}

.login-header {
    text-align: center;
    margin-bottom: 28px;
}

.login-header h1 {
    font-size: 20px;
    margin: 0 0 6px;
    color: var(--primary-dark);
}

.login-header p {
    margin: 0;
    color: var(--text-muted);
    font-size: 15px;
}

.login-card h1 {
    font-size: 20px;
    margin: 0 0 6px;
    color: var(--primary-dark);
    text-align: center;
}

.login-card > p {
    text-align: center;
    color: var(--text-muted);
    margin: 0 0 28px;
}

.login-card .brand {
    justify-content: center;
    margin-bottom: 16px;
}

.login-card .brand strong {
    font-size: 22px;
}

.login-form .form-group,
.login-card .form-group {
    margin-bottom: 18px;
}

.login-form label,
.login-card label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    color: var(--text-muted);
}

.login-form input,
.login-card input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
}

.login-hint {
    margin-top: 24px;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

.login-hint p { margin: 4px 0; }

/* ==================== 顶部导航 ==================== */
.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand strong {
    color: var(--primary);
    font-size: 18px;
}

.brand span {
    color: var(--text-muted);
    font-size: 14px;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.main-nav a {
    padding: 8px 14px;
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    white-space: nowrap;
}

.main-nav a:hover {
    background: #f0f4f8;
    text-decoration: none;
}

.main-nav a.active {
    background: var(--primary);
    color: #fff;
}

.user-info,
.user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: var(--text-muted);
}

.user-info a,
.user a {
    color: var(--primary);
}

.user a.active {
    color: var(--primary-dark);
    font-weight: 600;
    text-decoration: underline;
}

/* ==================== 主内容区 ==================== */
.app-main {
    padding: 24px 0 60px;
}

/* ==================== 页面标题 ==================== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 20px;
    gap: 16px;
    flex-wrap: wrap;
}

.page-header h1,
.page-header h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
}

.page-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* 详情页：操作栏置顶，与顶部导航一起冻结 */
.record-detail .page-header {
    position: sticky;
    top: var(--header-height);
    z-index: 90;
    background: var(--bg);
    padding: 12px 20px;
    margin: 0 -20px 20px;
    border-bottom: 1px solid var(--border);
}

/* ==================== 按钮 ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    transition: all .15s;
    line-height: 1.4;
}

.btn:hover { background: #f0f4f8; text-decoration: none; }

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-success {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
}

.btn-success:hover { background: #1e8449; }

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.btn-danger:hover { background: #b71c1c; }

.btn-warning {
    background: var(--warning);
    border-color: var(--warning);
    color: #fff;
}

.btn-warning:hover { background: #c2810a; }

.btn-outline,
.btn-light {
    background: #fff;
    border-color: var(--border);
    color: var(--text);
}

.btn-outline:hover,
.btn-light:hover { background: #f0f4f8; }

.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }
.btn-block { width: 100%; }

/* ==================== 卡片 / 表单区块 ==================== */
.card,
.form-section {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    border-top: 4px solid var(--primary);
}

.card.plain,
.form-section.readonly {
    border-top-color: var(--border);
    background: #fafbfc;
}

.form-section.editable {
    border-top-color: var(--success);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-wrap: wrap;
}

.card-header h2,
.card-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
}

.card-body {
    padding: 20px;
}

.section-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-status {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #ffebee;
    color: #c62828;
    font-weight: 500;
}

.section-status.done {
    background: #e8f5e9;
    color: #2e7d32;
}

.section-lock {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #eceff1;
    color: #546e7a;
    margin-left: auto;
}

/* 详情页网格 */
.record-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

/* ==================== 统计卡片 ==================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    border-top: 4px solid var(--primary);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    background: #e8f0fe;
    color: var(--primary);
}

.stat-icon.success { background: #e8f5e9; color: var(--success); }
.stat-icon.warning { background: #fff3e0; color: var(--warning); }
.stat-icon.danger { background: #ffebee; color: var(--danger); }

.stat-value {
    font-size: 26px;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    font-size: 13px;
    color: var(--text-muted);
}

/* ==================== 表单 ==================== */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.form-row:last-child { margin-bottom: 0; }

.form-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 0;
}

.form-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.form-control {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    background: #fff;
    color: var(--text);
    font-family: inherit;
    line-height: 1.5;
    width: 100%;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 95, 180, 0.1);
}

.form-control[readonly],
.form-control:disabled {
    background: #f0f2f5;
    color: var(--text-muted);
}

textarea.form-control {
    resize: vertical;
    min-height: 60px;
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
}

/* ==================== 表格 ==================== */
.table-responsive {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    min-width: 600px;
}

.data-table th,
.data-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table th {
    background: #f0f4f8;
    color: var(--text-muted);
    font-weight: 600;
}

.data-table tbody tr:hover { background: #fafbfc; }
.data-table tbody tr:last-child td { border-bottom: none; }

.data-table td .actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.sort-link {
    color: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.sort-link:hover { text-decoration: underline; }

.sort-icon {
    font-size: 12px;
}

.sort-inactive { color: #cbd5e1; }
.sort-active { color: #0f172a; }

/* 汇总行 */
.data-table tfoot .summary-row,
.items-table tfoot .summary-row {
    background: #f0f4f8;
    font-weight: 700;
}

.data-table tfoot .summary-row td,
.items-table tfoot .summary-row td {
    border-top: 2px solid var(--border);
}

/* ==================== 产品明细表格 ==================== */
.items-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 900px;
    table-layout: fixed;
}

.items-table th,
.items-table td {
    border: 1px solid var(--border);
    padding: 6px 8px;
    text-align: left;
    vertical-align: middle;
    overflow-wrap: break-word;
}

.items-table th {
    background: #f0f4f8;
    font-weight: 600;
    white-space: normal;
    word-break: break-word;
    vertical-align: bottom;
    width: auto;
    min-width: 60px;
    max-width: 110px;
}

.items-table td input,
.items-table td select,
.items-table td textarea {
    width: 100%;
    padding: 5px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
}

.items-table input[readonly],
.items-table textarea[readonly] {
    background: #f3f4f6;
    color: #6b7280;
    cursor: not-allowed;
}

.items-table td textarea {
    resize: vertical;
    min-height: 34px;
}

.items-table .row-num,
.items-table .row-no {
    text-align: center;
    background: #f8fafc;
    font-weight: 600;
}

.items-table td .btn-remove {
    padding: 4px 8px;
    font-size: 12px;
}

.calculated-cell {
    background: #f0f9ff;
    color: #0369a1;
    font-weight: 500;
    text-align: center;
    padding: 8px;
}

.import-bar {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* ==================== 筛选栏 ==================== */
.search-bar,
.filter-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.search-bar input,
.search-bar select,
.filter-bar input,
.filter-bar select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    min-width: 180px;
}

/* ==================== 徽章 ==================== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
}

.badge-primary,
.badge-draft { background: #e3f2fd; color: #1565c0; }
.badge-secondary { background: #eceff1; color: #546e7a; }
.badge-success,
.badge-completed { background: #e8f5e9; color: #2e7d32; }
.badge-warning,
.badge-in_progress { background: #fff3e0; color: #ef6c00; }
.badge-danger { background: #ffebee; color: #c62828; }
.badge-info { background: #e0f7fa; color: #00838f; }
.badge-dark { background: #263238; color: #fff; }

/* ==================== 提示 ==================== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-success { background: #e8f5e9; color: #1b5e20; border: 1px solid #c8e6c9; }
.alert-danger,
.alert-error { background: #ffebee; color: #b71c1c; border: 1px solid #ffcdd2; }
.alert-warning { background: #fff3e0; color: #ef6c00; border: 1px solid #ffe0b2; }
.alert-info { background: #e3f2fd; color: #1565c0; border: 1px solid #bbdefb; }

/* ==================== 时间轴 ==================== */
.timeline {
    position: relative;
    padding-left: 20px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 5px;
    top: 6px;
    bottom: 6px;
    width: 2px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    padding-bottom: 20px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -19px;
    top: 6px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid var(--card);
}

.timeline-date {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.timeline-content {
    background: #f8fafc;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
}

.timeline-content p { margin: 0 0 8px; }
.timeline-content p:last-child { margin-bottom: 0; }

/* ==================== 分页 ==================== */
.pagination {
    display: flex;
    gap: 6px;
    margin-top: 16px;
    justify-content: flex-end;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    font-size: 14px;
    background: #fff;
    color: var(--text);
}

.pagination a:hover { background: #f0f4f8; text-decoration: none; }

.pagination span.current {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* ==================== 进度条 ==================== */
.progress-bar {
    width: 120px;
    height: 8px;
    background: #e0e6ed;
    border-radius: 4px;
    overflow: hidden;
    display: inline-block;
    vertical-align: middle;
    margin-right: 8px;
}

.progress-bar-lg { width: 240px; height: 10px; }

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success), #4cd97a);
    transition: width .3s;
}

/* ==================== 空状态 ==================== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ==================== 页脚 ==================== */
.app-footer {
    border-top: 1px solid var(--border);
    padding: 20px 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    background: var(--card);
}

.app-footer p { margin: 0; }

/* ==================== 帮助列表 ==================== */
.help-list {
    margin: 0;
    padding-left: 20px;
    line-height: 1.8;
}

.help-list li { margin-bottom: 8px; }

/* ==================== 通知铃铛 ==================== */
.notif-bell {
    position: relative;
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    padding: 4px 8px;
    border-radius: var(--radius);
}
.notif-bell:hover { background: rgba(0,0,0,0.05); }
.notif-badge {
    position: absolute;
    top: -2px;
    right: 0;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}
.notif-item.unread { background: #f0f7ff; }

/* ==================== 内联删除表单 ==================== */
.inline-delete-form {
    display: inline !important;
}
.btn-link {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    font-size: inherit;
    text-decoration: underline;
}

/* ==================== 排序图标 ==================== */
.sort-link {
    text-decoration: none;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.sort-link:hover { text-decoration: none; }
.sort-icon { font-size: 12px; }
.sort-icon.sort-active { color: var(--primary); }
.sort-icon.sort-inactive { color: var(--text-muted); opacity: 0.5; }

/* ==================== 打印样式 ==================== */
@media print {
    .no-print, .topbar, .page-actions, .section-lock, .section-status,
    .form-section.editable, .form-section.readonly, .app-footer { display: none !important; }

    body { background: #fff; }
    .container { max-width: 100%; padding: 0; }
    .card { box-shadow: none; border: 1px solid #333; page-break-inside: avoid; }
    .record-grid { display: block; }

    @page {
        size: A4 portrait;
        margin: 15mm 15mm 20mm 15mm;
        @bottom-right {
            content: counter(page) "/" counter(pages);
            font-size: 12px;
        }
    }

    .print-page {
        page-break-before: always;
        min-height: 257mm;
    }
    .print-page:first-child {
        page-break-before: auto;
    }

    .data-table,
    .items-table,
    .print-table {
        page-break-inside: auto;
    }
    .data-table tr,
    .items-table tr,
    .print-table tr {
        page-break-inside: avoid;
    }
    .data-table thead,
    .items-table thead,
    .print-table thead {
        display: table-header-group;
    }
}

/* ==================== 响应式 ==================== */
@media (max-width: 768px) {
    .topbar-inner {
        flex-wrap: wrap;
        height: auto;
        padding: 10px 0;
        gap: 10px;
    }

    .main-nav {
        order: 3;
        width: 100%;
        overflow-x: auto;
    }

    .user-info,
    .user {
        order: 2;
        width: 100%;
        justify-content: flex-end;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-actions { width: 100%; }
    .form-row { grid-template-columns: 1fr; }
    .record-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr; }

    .search-bar,
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-bar input,
    .search-bar select,
    .filter-bar input,
    .filter-bar select {
        width: 100%;
    }
}
