/* ── Global ─────────────────────────────────────── */
:root {
    --primary: #4F46E5;
    --primary-light: #6366F1;
    --primary-dark: #4338CA;
    --success: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    --gray-50: #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-500: #6B7280;
    --gray-700: #374151;
    --gray-900: #111827;
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
        'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    min-height: 100vh;
}

/* ── Navbar ─────────────────────────────────────── */
.navbar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    box-shadow: 0 2px 12px rgba(79, 70, 229, 0.25);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: white;
    font-weight: 700;
    font-size: 1.15rem;
    text-decoration: none;
}

.navbar-brand svg { width: 28px; height: 28px; }

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.nav-links a {
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    padding: 0.5rem 0.85rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-links a:hover, .nav-links a.active {
    background: rgba(255,255,255,0.15);
    color: white;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: white;
    font-size: 0.875rem;
}

.nav-user span { opacity: 0.9; }

/* Hamburger */
.hamburger {
    display: none;
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.5rem;
}

.hamburger svg { width: 24px; height: 24px; }

/* Mobile menu */
.mobile-menu {
    display: none;
    background: var(--primary-dark);
    padding: 0.5rem 1rem 1rem;
}

.mobile-menu.open { display: block; }

.mobile-menu a {
    display: block;
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.95rem;
    margin-bottom: 2px;
}

.mobile-menu a:hover { background: rgba(255,255,255,0.1); }

@media (max-width: 768px) {
    .nav-links, .nav-user > span { display: none; }
    .hamburger { display: block; }
}

/* ── Cards ──────────────────────────────────────── */
.card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    border: 1px solid var(--gray-200);
    overflow: hidden;
    transition: box-shadow 0.2s, transform 0.2s;
}

.card:hover {
    box-shadow: 0 8px 25px rgba(0,0,0,0.08);
    transform: translateY(-2px);
}

.card-body { padding: 1.25rem; }

/* ── Container Card Grid ────────────────────────── */
.record-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.25rem;
}

@media (max-width: 640px) {
    .record-grid { grid-template-columns: 1fr; }
}

.record-card-img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    background: var(--gray-100);
}

.record-card-number {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: 0.5px;
    font-family: 'Courier New', monospace;
}

.weight-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin: 0.75rem 0;
}

.weight-item {
    background: var(--gray-50);
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    text-align: center;
}

.weight-item .label {
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-bottom: 2px;
}

.weight-item .value {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--gray-700);
}

.weight-item.net {
    background: linear-gradient(135deg, #ECFDF5, #D1FAE5);
}

.weight-item.net .value { color: #065F46; }

/* ── Buttons ────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    line-height: 1.4;
}

.btn:active { transform: scale(0.97); }

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

.btn-success {
    background: var(--success);
    color: white;
}
.btn-success:hover { background: #059669; }

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover { background: #DC2626; }

.btn-outline {
    background: white;
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
}
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-500); }

.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 8px;
}

/* ── Forms ──────────────────────────────────────── */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 0.4rem;
}

.form-input {
    width: 100%;
    padding: 0.65rem 0.85rem;
    border: 1.5px solid var(--gray-200);
    border-radius: 8px;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: white;
    color: var(--gray-900);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-input::placeholder { color: var(--gray-500); }

textarea.form-input { resize: vertical; min-height: 80px; }

select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236B7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

/* ── Image Upload ───────────────────────────────── */
.upload-area {
    border: 2px dashed var(--gray-200);
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--gray-50);
}

.upload-area:hover {
    border-color: var(--primary);
    background: #EEF2FF;
}

.upload-area.has-image {
    border-style: solid;
    border-color: var(--primary);
    padding: 0.5rem;
}

.upload-area svg {
    width: 48px;
    height: 48px;
    color: var(--gray-500);
    margin-bottom: 0.75rem;
}

.upload-preview {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    object-fit: contain;
}

/* ── AI Recognition ─────────────────────────────── */
.ai-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    margin-top: 0.75rem;
}

.ai-status.loading {
    background: #EEF2FF;
    color: var(--primary);
}

.ai-status.success {
    background: #ECFDF5;
    color: #065F46;
}

.ai-status.error {
    background: #FEF2F2;
    color: #991B1B;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Table ──────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.9rem;
}

.data-table thead th {
    background: var(--gray-50);
    padding: 0.85rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--gray-700);
    border-bottom: 2px solid var(--gray-200);
    white-space: nowrap;
}

.data-table tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-700);
}

.data-table tbody tr:hover { background: var(--gray-50); }

.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    border: 1px solid var(--gray-200);
    background: white;
}

/* ── Pagination ─────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.pagination a, .pagination span {
    padding: 0.45rem 0.85rem;
    border-radius: 8px;
    font-size: 0.85rem;
    text-decoration: none;
    border: 1px solid var(--gray-200);
    color: var(--gray-700);
    transition: all 0.2s;
}

.pagination a:hover { background: var(--gray-100); }

.pagination .active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.pagination .disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* ── Flash Messages ─────────────────────────────── */
.flash-msg {
    padding: 0.85rem 1.15rem;
    border-radius: 10px;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.flash-success { background: #ECFDF5; color: #065F46; border: 1px solid #A7F3D0; }
.flash-danger { background: #FEF2F2; color: #991B1B; border: 1px solid #FECACA; }
.flash-warning { background: #FFFBEB; color: #92400E; border: 1px solid #FDE68A; }
.flash-info { background: #EEF2FF; color: #3730A3; border: 1px solid #C7D2FE; }

/* ── Filter Bar ─────────────────────────────────── */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
    padding: 1.25rem;
    background: white;
    border-radius: 12px;
    border: 1px solid var(--gray-200);
    margin-bottom: 1.5rem;
}

.filter-bar .form-group { margin-bottom: 0; flex: 1; min-width: 160px; }

/* ── Auth Pages ─────────────────────────────────── */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 1rem;
}

.auth-card {
    background: white;
    border-radius: 16px;
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.auth-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    text-align: center;
    margin-bottom: 0.5rem;
}

.auth-subtitle {
    font-size: 0.9rem;
    color: var(--gray-500);
    text-align: center;
    margin-bottom: 2rem;
}

/* ── Modal ──────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-overlay.open { display: flex; }

.modal-box {
    background: white;
    border-radius: 16px;
    padding: 2rem;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

/* ── Empty State ────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--gray-500);
}

.empty-state svg {
    width: 80px;
    height: 80px;
    color: var(--gray-300);
    margin-bottom: 1rem;
}

.empty-state h3 {
    font-size: 1.15rem;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
}

/* ── Utilities ──────────────────────────────────── */
.container { max-width: 1280px; margin: 0 auto; padding: 1.5rem 1rem; }
.page-title { font-size: 1.5rem; font-weight: 700; color: var(--gray-900); margin-bottom: 1.25rem; }
.text-mono { font-family: 'Courier New', monospace; }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-muted { color: var(--gray-500); }
.text-sm { font-size: 0.85rem; }
.text-center { text-align: center; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.flex-wrap { flex-wrap: wrap; }

/* ── Responsive table on mobile ─────────────────── */
@media (max-width: 640px) {
    .filter-bar { flex-direction: column; }
    .filter-bar .form-group { min-width: 100%; }
    .auth-card { padding: 1.75rem; }
    .container { padding: 1rem 0.75rem; }
    .weight-row { grid-template-columns: repeat(2, 1fr); gap: 0.35rem; }
}

/* ── Upload Source Buttons (拍照 / 相册) ──────────── */
.upload-btn-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.85rem 1rem;
    border: 1.5px dashed var(--gray-300, #D1D5DB);
    border-radius: 10px;
    background: var(--gray-50);
    color: var(--gray-700, #374151);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 48px;
}

.upload-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #EEF2FF;
}

.upload-btn svg { width: 20px; height: 20px; }

/* ── Action Sheet (底部操作菜单) ──────────────────── */
.action-sheet {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 300;
    align-items: flex-end;
    justify-content: center;
}

.action-sheet.open { display: flex; }

.action-sheet-box {
    background: white;
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 480px;
    padding: 0.5rem 1rem calc(1rem + env(safe-area-inset-bottom, 0));
    animation: slideUp 0.25s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.action-sheet-title {
    text-align: center;
    font-size: 0.85rem;
    color: var(--gray-500);
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--gray-100, #F3F4F6);
}

.action-sheet-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 1rem;
    border: none;
    background: none;
    font-size: 1.05rem;
    color: var(--gray-900, #111827);
    cursor: pointer;
    border-bottom: 1px solid var(--gray-100, #F3F4F6);
    min-height: 52px;
}

.action-sheet-btn:hover { background: var(--gray-50); }
.action-sheet-btn.danger { color: var(--danger); }
.action-sheet-btn.cancel {
    border-bottom: none;
    color: var(--gray-500);
    border-radius: 0 0 16px 16px;
}

/* ── Image Lightbox (全屏查看) ────────────────────── */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    z-index: 400;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}

.lightbox.open { display: flex; }

.lightbox img {
    max-width: 95vw;
    max-height: 90vh;
    border-radius: 8px;
    object-fit: contain;
}

.lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.15);
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Multi Image Thumbs (集装箱多图) ──────────────── */
.thumb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.thumb-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--gray-200);
    background: var(--gray-50);
}

.thumb-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: zoom-in;
    display: block;
}

.thumb-item .thumb-del {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.55);
    color: white;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.thumb-item .thumb-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-50);
}

.thumb-item.marked-del img { opacity: 0.35; }
.thumb-item.marked-del::after {
    content: '将删除';
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: var(--danger);
    color: white;
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 4px;
}
