/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #10b981;
    --primary-hover: #059669;
    --primary-light: #d1fae5;
    --primary-dark: #065f46;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --info: #2563eb;
    --bg: #f3f4f6;
    --card-bg: #ffffff;
    --text: #1f2937;
    --text-light: #6b7280;
    --border: #d1d5db;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
    --sidebar-w: 240px;
    --topbar-h: 50px;
}

body {
    font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { color: var(--primary-hover); }
.link { font-weight: 600; }

/* ===== Login Page ===== */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #10b981 0%, #065f46 100%);
}

.login-container { width: 100%; max-width: 400px; padding: 1rem; }

.login-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
}

.login-header { text-align: center; margin-bottom: 2rem; }
.login-header h1 { font-size: 2rem; color: var(--primary); letter-spacing: 2px; }
.login-header p { color: var(--text-light); font-size: 0.875rem; margin-top: 0.25rem; }
.login-footer { text-align: center; color: rgba(255,255,255,0.7); font-size: 0.75rem; margin-top: 1.5rem; }

/* ===== App Layout (sidebar + main) ===== */
.app {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-w);
    background: #1e4d32;
    color: #e5e7eb;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform 0.25s ease;
}

.sidebar-header {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid #065f46;
    flex-shrink: 0;
}
.sidebar-header h1 { font-size: 1.25rem; color: #6ee7b7; letter-spacing: 1px; }
.sidebar-header p  { font-size: 0.7rem; color: #a7f3d0; margin-top: 2px; }

.sidebar-nav {
    list-style: none;
    flex: 1;
    padding: 0.5rem 0;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.3) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.3); border-radius: 2px; }

.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem 1rem;
    color: #d1fae5;
    font-size: 0.875rem;
    transition: background 0.15s;
}
.sidebar-nav li a:hover { background: #065f46; color: #fff; }
.sidebar-nav li a.active { background: rgba(255,255,255,0.15); color: #fff; }

.nav-icon { font-size: 0.75rem; width: 1rem; text-align: center; }
.nav-section {
    display: block;
    padding: 0.75rem 1rem 0.25rem;
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #6ee7b7;
    border-top: 1px solid #065f46;
    margin-top: 0.25rem;
}

.sidebar-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid #065f46;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.sidebar-role-badge { margin-top: 0.5rem; }
.sidebar-role-badge .sidebar-user { font-size: 0.8125rem; color: #a7f3d0; display: block; margin-bottom: 0.2rem; }
.sidebar-user { font-size: 0.8125rem; color: #a7f3d0; display: block; }
.sidebar-role {
    display: inline-block;
    font-size: 0.5625rem;
    font-weight: 700;
    color: #064e3b;
    background: #6ee7b7;
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    margin-top: 0.15rem;
}
.sidebar-footer .btn { color: #a7f3d0; border-color: #065f46; }
.sidebar-footer .btn:hover { color: #fff; border-color: #10b981; }

/* --- Topbar (mobile only) --- */
.topbar {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    background: #064e3b;
    color: #fff;
    align-items: center;
    padding: 0 1rem;
    z-index: 90;
}
.topbar-toggle { background: none; border: none; color: #fff; font-size: 1.25rem; cursor: pointer; }
.topbar-title { margin-left: 0.75rem; font-size: 1rem; font-weight: 600; letter-spacing: 1px; flex: 1; }
.topbar-user { font-size: 0.75rem; color: #a7f3d0; }

/* --- Main Content --- */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    padding: 1.5rem 2rem;
    min-height: 100vh;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.page-header h2 { font-size: 1.375rem; }
.page-header p  { color: var(--text-light); font-size: 0.875rem; width: 100%; }

/* ===== Forms ===== */
.form-group { margin-bottom: 1.25rem; }
.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
    color: var(--text);
}
.form-group input,
.form-group select {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9375rem;
    background: #fff;
    transition: border-color 0.2s;
}
.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.form-row {
    display: flex;
    gap: 1rem;
}
.form-row .form-group { flex: 1; }

.form-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    max-width: 800px;
}
.form-card fieldset {
    border: none;
    margin-bottom: 1.5rem;
}
.form-card legend {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
    width: 100%;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background-color 0.2s;
    text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-outline { background: transparent; color: var(--text-light); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg); }

/* ===== Alerts ===== */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); font-size: 0.875rem; margin-bottom: 1rem; }
.alert-error   { background: #fef2f2; color: var(--danger);  border: 1px solid #fecaca; }
.alert-info    { background: #eff6ff; color: var(--info);    border: 1px solid #bfdbfe; }
.alert-success { background: #ecfdf5; color: var(--primary-dark); border: 1px solid #a7f3d0; }

/* ===== Cards ===== */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
}
.card-body  { padding: 1.5rem 1rem; text-align: center; }
.card-stat  { font-size: 2rem; font-weight: 700; color: var(--primary); }
.card-label { font-size: 0.8125rem; color: var(--text-light); margin-top: 0.25rem; }

.card-grid-4 { grid-template-columns: repeat(4, 1fr); }
.card-grid-3 { grid-template-columns: repeat(3, 1fr); }

/* Card link variant */
.card-link { text-decoration: none; color: inherit; transition: box-shadow 0.2s, transform 0.15s; }
.card-link:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); color: inherit; }

/* Alert card (red border) */
.card-alert { border-left: 4px solid var(--danger); }
.card-alert .card-stat { color: var(--danger); }

/* Warning card (amber border) */
.card-warning { border-left: 4px solid var(--warning); }
.card-warning .card-stat { color: var(--warning); }

/* Card header badge (notification dot) */
.card-header-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 700;
    color: #fff;
    background: var(--danger);
    margin-left: 0.375rem;
    vertical-align: middle;
}
.card-header-badge-warning { background: var(--warning); }

/* ===== Text utility colors ===== */
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }

/* ===== Pipeline (horizontal bar chart) ===== */
.pipeline-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
}
.pipeline-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.375rem 0;
}
.pipeline-label {
    width: 100px;
    flex-shrink: 0;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-light);
    text-align: right;
}
.pipeline-bar-wrap {
    flex: 1;
    background: #f3f4f6;
    border-radius: 4px;
    height: 26px;
    overflow: hidden;
}
.pipeline-bar {
    height: 100%;
    border-radius: 4px;
    display: flex;
    align-items: center;
    padding: 0 0.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
    min-width: fit-content;
    transition: width 0.4s ease;
}
.pipeline-pending    { background: #9ca3af; }
.pipeline-received   { background: #3b82f6; }
.pipeline-processing { background: #f97316; }
.pipeline-ready      { background: #06b6d4; }
.pipeline-departed   { background: #8b5cf6; }
.pipeline-awaiting   { background: #eab308; color: #422006; }
.pipeline-delivered  { background: #10b981; }
.pipeline-onhold     { background: #ef4444; }

/* ===== Dashboard bottom grid ===== */
.dashboard-bottom-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
    margin-top: 0.5rem;
}

/* ===== Data Table ===== */
.table-wrapper {
    overflow-x: auto;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
    white-space: nowrap;
}
.data-table thead {
    background: #f9fafb;
    border-bottom: 2px solid var(--border);
}
.data-table th {
    padding: 0.625rem 0.75rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-light);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.data-table td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid #f3f4f6;
}
.data-table tbody tr:hover { background: #f9fafb; }
.empty-row { text-align: center; color: var(--text-light); padding: 2rem !important; }
.cell-truncate { max-width: 200px; overflow: hidden; text-overflow: ellipsis; }

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.03em;
}
.badge-lg { font-size: 0.8125rem; padding: 0.3rem 0.75rem; }
.badge-platform { background: #e0e7ff; color: #3730a3; }
.badge-info     { background: #dbeafe; color: #1e40af; }

/* Status badges (9 statuses) */
.badge-pending           { background: #f3f4f6; color: #374151; }   /* grey */
.badge-received          { background: #dbeafe; color: #1e40af; }   /* blue */
.badge-processing        { background: #ffedd5; color: #9a3412; }   /* orange */
.badge-ready_to_ship     { background: #cffafe; color: #155e75; }   /* cyan */
.badge-cargo_departed    { background: #ede9fe; color: #5b21b6; }   /* purple */
.badge-awaiting_delivery { background: #fef9c3; color: #854d0e; }   /* yellow */
.badge-delivered         { background: #d1fae5; color: #065f46; }   /* green */
.badge-on_hold           { background: #fee2e2; color: #991b1b; }   /* red */
.badge-cancelled         { background: #e5e7eb; color: #6b7280; }   /* dark grey */

/* ===== Detail Page ===== */
.actions-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
    padding: 0.75rem 1rem;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.inline-form {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.status-select {
    padding: 0.375rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8125rem;
    background: #fff;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 1rem;
}

.detail-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
}
.detail-section h3 {
    font-size: 0.9375rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary-light);
    color: var(--primary-dark);
}

.info-table { width: 100%; font-size: 0.875rem; }
.info-table th {
    text-align: left;
    padding: 0.375rem 0.75rem 0.375rem 0;
    color: var(--text-light);
    font-weight: 500;
    white-space: nowrap;
    width: 35%;
    vertical-align: top;
}
.info-table td {
    padding: 0.375rem 0;
}

.text-muted { color: var(--text-light); font-size: 0.875rem; }

.tracking-summary-mini {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

/* ===== Tracking ===== */
.tracking-search { margin-bottom: 1.5rem; }
.tracking-loading { text-align: center; padding: 2rem; color: var(--text-light); }

.tracking-status-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}
.tracking-summary { display: flex; flex-direction: column; gap: 0.5rem; font-size: 0.9375rem; }

.tracking-timeline {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
}
.tracking-timeline h3 { margin-bottom: 1rem; font-size: 1rem; }

.timeline {
    list-style: none;
    position: relative;
    padding-left: 1.5rem;
}
.timeline::before {
    content: '';
    position: absolute;
    left: 5px;
    top: 4px;
    bottom: 4px;
    width: 2px;
    background: var(--border);
}
.timeline-item {
    position: relative;
    padding-bottom: 1.25rem;
    display: flex;
    gap: 0.75rem;
}
.timeline-dot {
    width: 12px; height: 12px;
    background: var(--primary);
    border-radius: 50%;
    position: absolute;
    left: -1.5rem;
    top: 4px;
}
.timeline-item:first-child .timeline-dot { background: var(--success); }
.timeline-time { font-size: 0.75rem; color: var(--text-light); }
.timeline-desc { font-size: 0.875rem; }
.timeline-loc  { font-size: 0.75rem; color: var(--text-light); }

/* ===== Filter Bar ===== */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.filter-group { display: flex; align-items: center; }
.filter-input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8125rem;
    min-width: 240px;
    background: #fff;
    transition: border-color 0.2s;
}
.filter-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}
.filter-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8125rem;
    background: #fff;
    cursor: pointer;
}
.filter-select:focus {
    outline: none;
    border-color: var(--primary);
}

/* ===== Rule Hint ===== */
.rule-hint {
    padding: 0.5rem 0.75rem;
    margin-top: 0.5rem;
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: var(--radius);
    font-size: 0.8125rem;
    border-left: 3px solid var(--primary);
}

/* ===== Rate Comparison Panel ===== */
.rate-result-panel {
    margin-top: 0.75rem;
    padding: 1rem;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.rate-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}
.rate-table th {
    text-align: left;
    padding: 0.5rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    border-bottom: 2px solid var(--border);
}
.rate-table td {
    padding: 0.5rem 0.625rem;
    border-bottom: 1px solid #e5e7eb;
}
.rate-table tr.rate-cheapest {
    background: var(--primary-light);
}
.rate-table tr.rate-cheapest td {
    font-weight: 600;
}
.rate-total { font-weight: 700; }
.badge-cheapest {
    background: var(--primary);
    color: #fff;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.625rem;
    font-weight: 700;
    margin-left: 0.25rem;
    vertical-align: middle;
}

.pickup-ok {
    color: var(--success);
    font-weight: 600;
    font-size: 0.75rem;
}
.pickup-no {
    color: var(--warning);
    font-weight: 600;
    font-size: 0.75rem;
}
.rate-note {
    margin-top: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: #fef3c7;
    color: #92400e;
    border-radius: var(--radius);
    border-left: 3px solid var(--warning);
    font-size: 0.8125rem;
}

/* ===== Recent Shipments (Dashboard) ===== */
.section-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin: 1.5rem 0 0.75rem;
}

/* ===== Sidebar Overlay Backdrop ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 99;
}
.sidebar-overlay.visible { display: block; }

/* ===== Mobile Column Hiding ===== */
.col-hide-mobile {} /* visible by default */

/* ===== Responsive ===== */
@media (max-width: 768px) {
    /* Sidebar: slide-in overlay */
    .sidebar {
        transform: translateX(-100%);
        box-shadow: none;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
    }

    /* Topbar */
    .topbar { display: flex; }

    /* Main content */
    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: calc(var(--topbar-h) + 1rem);
    }

    /* Forms */
    .form-row { flex-direction: column; gap: 0; }
    .form-grid { grid-template-columns: 1fr; }
    .form-card { max-width: 100%; }
    .form-group input, .form-group select { font-size: 16px; } /* prevent iOS zoom */

    /* Cards */
    .card-grid { grid-template-columns: 1fr; }
    .card-grid-4 { grid-template-columns: repeat(2, 1fr); }
    .card-grid-3 { grid-template-columns: 1fr; }

    /* Detail */
    .detail-grid { grid-template-columns: 1fr; }
    .actions-bar { flex-direction: column; align-items: flex-start; }

    /* Filters */
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-input { min-width: unset; width: 100%; }
    .filter-select { width: 100%; }

    /* Tables */
    .data-table { font-size: 0.75rem; }
    .data-table th { font-size: 0.6875rem; padding: 0.5rem; }
    .data-table td { padding: 0.5rem; }
    .col-hide-mobile { display: none; }
    .cell-truncate { max-width: 120px; }

    /* Dashboard */
    .dashboard-bottom-grid { grid-template-columns: 1fr; }
    .pipeline-label { width: 80px; font-size: 0.75rem; }
    .quick-actions { gap: 0.375rem; }
    .quick-actions .btn { font-size: 0.75rem; padding: 0.375rem 0.625rem; }

    /* Inline forms */
    .inline-form-row { flex-direction: column; }
}

/* ===== Warehouse / Form Card ===== */
.form-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}
.form-group { display: flex; flex-direction: column; gap: 0.25rem; }
.form-group label { font-size: 0.8125rem; font-weight: 600; color: var(--text-muted); }
.form-group-wide { grid-column: 1 / -1; }
.form-input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.875rem;
    background: #fff;
    transition: border-color 0.2s;
}
.form-input:focus { outline: none; border-color: var(--primary); }
.form-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }
.required { color: #ef4444; }

.inline-form-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

/* Warehouse-specific badges */
.badge-wh-type     { background: #ede9fe; color: #5b21b6; }
.badge-staff-role   { background: #e0f2fe; color: #075985; }
.badge-active       { background: #d1fae5; color: #065f46; }
.badge-inactive     { background: #f3f4f6; color: #6b7280; }

.btn-danger {
    background: #ef4444;
    color: #fff;
    border: none;
    cursor: pointer;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}
.btn-danger:hover { background: #dc2626; }

/* ===== Document Upload ===== */
.upload-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.upload-controls .form-group { flex: 1; min-width: 200px; }
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s;
    margin-bottom: 1rem;
}
.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--primary);
    background: #f0fdf4;
}
.match-result {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}
.match-success { background: #f0fdf4; border-left: 4px solid #10b981; }
.match-fail    { background: #fef2f2; border-left: 4px solid #ef4444; }
.match-icon { font-weight: 700; margin-right: 0.25rem; }
.badge-doc-type { background: #fef3c7; color: #92400e; }
.text-error { color: #ef4444; }

/* ===== Document List in Detail ===== */
.doc-list { list-style: none; padding: 0; }
.doc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}
.doc-item:last-child { border-bottom: none; }
.doc-info { display: flex; align-items: center; gap: 0.5rem; flex: 1; }
.doc-meta { color: var(--text-muted); font-size: 0.75rem; }

/* ===== Incident Status Badges ===== */
.badge-open        { background: #dbeafe; color: #1e40af; }   /* blue */
.badge-in_progress { background: #ffedd5; color: #9a3412; }   /* orange (reuse processing) */
.badge-resolved    { background: #d1fae5; color: #065f46; }   /* green */
.badge-closed      { background: #e5e7eb; color: #6b7280; }   /* grey */

/* ===== Incident Category Badges ===== */
.badge-customs_hold { background: #fee2e2; color: #991b1b; }  /* red */
.badge-duty_unpaid  { background: #fef3c7; color: #92400e; }  /* amber */
.badge-absent       { background: #ffedd5; color: #9a3412; }  /* orange */
.badge-return       { background: #ede9fe; color: #5b21b6; }  /* purple */
.badge-damage       { background: #fce7f3; color: #9d174d; }  /* pink */
.badge-address      { background: #cffafe; color: #155e75; }  /* cyan */
.badge-other        { background: #f3f4f6; color: #374151; }  /* grey */

/* ===== Comment Thread ===== */
.comment-thread {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.comment-item {
    padding: 0.75rem;
    background: #f9fafb;
    border-radius: var(--radius);
    border-left: 3px solid var(--primary);
}
.comment-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-light);
    margin-bottom: 0.375rem;
}
.comment-body {
    font-size: 0.875rem;
    white-space: pre-wrap;
}

/* ===== User Status Badges ===== */
.badge-user-pending   { background: #fef3c7; color: #92400e; }
.badge-user-active    { background: #d1fae5; color: #065f46; }
.badge-user-suspended { background: #fee2e2; color: #991b1b; }

.user-actions { white-space: normal; min-width: 200px; }
.action-group { display: flex; gap: 0.375rem; align-items: center; flex-wrap: wrap; }

/* ===== Dummy Tracking & Remeasure ===== */
.badge-dummy      { background: #fef3c7; color: #92400e; }   /* amber */
.badge-remeasured { background: #d1fae5; color: #065f46; }   /* green */

.remeasure-form {
    padding: 1rem;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.remeasure-form h3 {
    font-size: 0.875rem;
    margin-bottom: 0.75rem;
    color: var(--text);
    border-bottom: none;
    padding-bottom: 0;
}

/* ===== Receiving Page (Phase 2H) ===== */
.receiving-panel {
    max-width: 500px;
    margin: 0 auto;
}
.receiving-input-section {
    text-align: center;
    padding: 2rem;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}
.receiving-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 1rem;
}
.receiving-code-input {
    width: 200px;
    text-align: center;
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: 0.5rem;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    outline: none;
    transition: border-color 0.2s;
}
.receiving-code-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.15);
}
.receiving-dots {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 1rem;
}
.dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--border);
    transition: background 0.15s;
}
.dot.filled {
    background: var(--primary);
}
.receiving-result {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}
.receiving-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.receiving-sgm {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-dark);
}
.receiving-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.25rem;
    justify-content: center;
}
.receiving-success {
    text-align: center;
    padding: 1.5rem;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: var(--radius);
    color: var(--primary-dark);
    font-weight: 600;
    font-size: 1.125rem;
}
.receiving-not-found {
    text-align: center;
    padding: 1.5rem;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    color: var(--danger);
}

/* Receiving code display in tables & detail */
.receiving-code-badge {
    display: inline-block;
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.2rem;
    background: #fef3c7;
    color: #92400e;
    padding: 0.25rem 0.625rem;
    border-radius: 6px;
    border: 2px solid #fcd34d;
}
.receiving-code-sm {
    display: inline-block;
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.1rem;
    background: #fef3c7;
    color: #92400e;
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
}

/* ===== AI Chat Popup Widget ===== */
.ai-chat-fab {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}
.ai-chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    background: var(--primary-hover);
}
.ai-chat-fab.hidden { display: none; }
.ai-chat-fab-icon { font-size: 1.5rem; line-height: 1; }

.ai-chat-widget {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 400px;
    height: 500px;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    z-index: 1001;
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border);
}
.ai-chat-widget.open {
    display: flex;
}

.ai-chat-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: #064e3b;
    color: #fff;
    flex-shrink: 0;
}
.ai-chat-widget-title {
    font-size: 0.9375rem;
    font-weight: 600;
}
.ai-chat-widget-actions {
    display: flex;
    gap: 0.25rem;
}
.ai-chat-widget-btn {
    background: none;
    border: none;
    color: #a7f3d0;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
}
.ai-chat-widget-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.ai-chat-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.ai-chat-widget-welcome {
    text-align: center;
    color: var(--text-light);
    padding: 2rem 1rem;
    font-size: 0.875rem;
}
.ai-chat-widget-welcome strong {
    color: var(--text);
    display: block;
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.ai-chat-msg {
    max-width: 90%;
}
.ai-chat-msg-user {
    margin-left: auto;
    text-align: right;
}
.ai-chat-msg-assistant {
    margin-right: auto;
}
.ai-chat-msg-label {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 0.15rem;
}
.ai-chat-msg-body {
    display: inline-block;
    padding: 0.5rem 0.75rem;
    border-radius: 10px;
    font-size: 0.8125rem;
    line-height: 1.55;
    text-align: left;
    white-space: pre-wrap;
    word-break: break-word;
}
.ai-chat-msg-user .ai-chat-msg-body {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 3px;
}
.ai-chat-msg-assistant .ai-chat-msg-body {
    background: #f3f4f6;
    color: var(--text);
    border-bottom-left-radius: 3px;
}
.ai-chat-msg-body pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 0.5rem;
    border-radius: 4px;
    overflow-x: auto;
    font-size: 0.75rem;
    margin: 0.25rem 0;
    white-space: pre;
}
.ai-chat-msg-body code {
    background: rgba(0, 0, 0, 0.08);
    padding: 0.1rem 0.25rem;
    border-radius: 3px;
    font-size: 0.8em;
}
.ai-chat-msg-body pre code {
    background: none;
    padding: 0;
}

.ai-chat-widget-loading {
    padding: 0.375rem 1rem;
    font-size: 0.8125rem;
    color: var(--text-light);
    flex-shrink: 0;
}

.ai-chat-widget-input {
    display: flex;
    align-items: flex-end;
    gap: 0.375rem;
    padding: 0.75rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.ai-chat-widget-textarea {
    flex: 1;
    resize: none;
    padding: 0.5rem 0.625rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.8125rem;
    font-family: inherit;
    line-height: 1.4;
    max-height: 100px;
    outline: none;
    transition: border-color 0.2s;
}
.ai-chat-widget-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.15);
}
.ai-chat-widget-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}
.ai-chat-widget-send:hover { background: var(--primary-hover); }
.ai-chat-widget-send:disabled { background: #9ca3af; cursor: not-allowed; }

/* Mobile: full screen chat widget */
@media (max-width: 768px) {
    .ai-chat-fab {
        bottom: 1rem;
        right: 1rem;
        width: 50px;
        height: 50px;
    }
    .ai-chat-fab-icon { font-size: 1.3rem; }

    .ai-chat-widget {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        z-index: 1100;
    }
}
