/* ── Dark Mode ── */
body.dark-mode {
    --primary: #60a5fa;
    --primary-dark: #93c5fd;
    --primary-light: #1e3a5f;
    --success: #4ade80;
    --success-light: #14532d;
    --warning: #fbbf24;
    --warning-light: #78350f;
    --danger: #f87171;
    --danger-light: #7f1d1d;
    --info: #38bdf8;
    --info-light: #0c4a6e;
    --gray-50: #1f2937;
    --gray-100: #111827;
    --gray-200: #374151;
    --gray-300: #4b5563;
    --gray-400: #6b7280;
    --gray-500: #9ca3af;
    --gray-600: #d1d5db;
    --gray-700: #e5e7eb;
    --gray-800: #f3f4f6;
    --gray-900: #f9fafb;
    background: #0f172a;
    color: #e2e8f0;
}

body.dark-mode .navbar {
    background: #1e293b;
    border-bottom-color: #334155;
}

body.dark-mode .nav-brand a { color: #f1f5f9; }

body.dark-mode .card,
body.dark-mode .stat-card,
body.dark-mode .timeline-content,
body.dark-mode .dropdown-content {
    background: #1e293b;
    border-color: #334155;
}

body.dark-mode .form-control {
    background: #0f172a;
    border-color: #475569;
    color: #e2e8f0;
}

body.dark-mode .btn-outline {
    background: #1e293b;
    border-color: #475569;
    color: #cbd5e1;
}

body.dark-mode .btn-outline:hover {
    background: #334155;
    color: #f1f5f9;
}

body.dark-mode thead th {
    background: #0f172a;
    color: #94a3b8;
    border-bottom-color: #334155;
}

body.dark-mode tbody td { border-bottom-color: #1e293b; color: #cbd5e1; }
body.dark-mode tbody tr:hover { background: #263447; }

body.dark-mode .samples-section { background: #0f172a; border-color: #334155; }
body.dark-mode .timeline-samples { background: #0f172a; }
body.dark-mode .audit-entry { background: #0f172a; }
body.dark-mode .type-tag { background: #1e293b; border-color: #334155; }

body.dark-mode .login-wrapper { background: #0f172a; }
body.dark-mode .login-card { background: #1e293b; }

body.dark-mode .alert-success { background: #14532d; color: #86efac; border-color: #166534; }
body.dark-mode .alert-danger  { background: #7f1d1d; color: #fca5a5; border-color: #991b1b; }
body.dark-mode .alert-warning { background: #78350f; color: #fcd34d; border-color: #92400e; }
body.dark-mode .alert-info    { background: #0c4a6e; color: #7dd3fc; border-color: #155e75; }

/* dark mode toggle button */
.dark-toggle {
    background: none;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    color: var(--gray-600);
    transition: all 0.15s;
}
.dark-toggle:hover { background: var(--gray-100); }

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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --info: #0891b2;
    --info-light: #cffafe;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
}

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

/* ── Navbar ── */
.navbar {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.nav-brand a {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--gray-900);
}

.nav-links {
    display: flex;
    gap: 0.25rem;
    margin-left: 2rem;
    flex: 1;
}

.nav-links > a, .nav-dropdown > a {
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    color: var(--gray-600);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.15s;
}

.nav-links > a:hover, .nav-dropdown > a:hover,
.nav-links > a.active, .nav-dropdown > a.active {
    background: var(--primary-light);
    color: var(--primary);
}

.nav-dropdown { position: relative; }
.dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 180px;
    z-index: 200;
    padding: 0.25rem 0;
}
.dropdown-content a {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--gray-700);
    font-size: 0.875rem;
}
.dropdown-content a:hover { background: var(--gray-50); }
.nav-dropdown:hover .dropdown-content { display: block; }

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-info { font-size: 0.875rem; color: var(--gray-600); }

.role-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}
.role-admin { background: var(--danger-light); color: var(--danger); }
.role-manager { background: var(--warning-light); color: var(--warning); }
.role-sales_rep { background: var(--primary-light); color: var(--primary); }
.role-customer_service { background: #f3e8ff; color: #7c3aed; }

/* ── Container ── */
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }

/* ── Cards ── */
.card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--gray-100);
}

.card-header h2, .card-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-800);
}

/* ── Stats Grid ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--gray-900);
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    line-height: 1.4;
}

.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline { background: white; color: var(--gray-700); border-color: var(--gray-300); }
.btn-outline:hover { background: var(--gray-50); color: var(--gray-700); }
.btn-sm { padding: 0.25rem 0.625rem; font-size: 0.8rem; }
.btn-icon { padding: 0.375rem; }

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0.375rem;
}

.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
    color: var(--gray-800);
    background: white;
    transition: border-color 0.15s;
}

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

select.form-control { appearance: auto; }
textarea.form-control { min-height: 80px; resize: vertical; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--gray-100);
}

/* ── Tables ── */
.table-wrapper { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

thead th {
    background: var(--gray-50);
    padding: 0.625rem 0.75rem;
    text-align: left;
    font-weight: 600;
    color: var(--gray-600);
    border-bottom: 2px solid var(--gray-200);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

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

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

/* ── Alerts ── */
.flash-messages { margin-bottom: 1rem; }
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
}

.alert-success { background: var(--success-light); color: #166534; border: 1px solid #bbf7d0; }
.alert-danger { background: var(--danger-light); color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: var(--info-light); color: #155e75; border: 1px solid #a5f3fc; }

.alert-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0.5;
    color: inherit;
}

/* ── Page Header ── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
}

/* ── Timeline ── */
.timeline { position: relative; padding-left: 1.5rem; }
.timeline::before {
    content: '';
    position: absolute;
    left: 0.5rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--gray-200);
}

.timeline-item {
    position: relative;
    padding-bottom: 1.25rem;
    padding-left: 1rem;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -1.125rem;
    top: 0.5rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid white;
    box-shadow: 0 0 0 2px var(--primary-light);
}

.timeline-date {
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-bottom: 0.25rem;
}

.timeline-content {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
}

.timeline-type {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--primary-light);
    color: var(--primary);
    margin-bottom: 0.375rem;
}

.timeline-notes {
    font-size: 0.875rem;
    color: var(--gray-600);
    margin-top: 0.375rem;
}

.timeline-meta {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--gray-400);
}

.timeline-samples {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: var(--gray-50);
    border-radius: 4px;
    font-size: 0.8rem;
}

.timeline-samples strong { color: var(--gray-700); }

.timeline-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

/* ── Status Badges ── */
.status-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-completed { background: var(--success-light); color: var(--success); }
.status-pending { background: var(--warning-light); color: var(--warning); }
.status-follow_up { background: var(--info-light); color: var(--info); }
.status-no_response { background: var(--gray-100); color: var(--gray-500); }
.status-sample_approved { background: var(--success-light); color: var(--success); }
.status-sample_rejected { background: var(--danger-light); color: var(--danger); }
.status-trial_ongoing { background: var(--info-light); color: var(--info); }

/* ── Samples Section in Form ── */
.samples-section {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem;
    background: var(--gray-50);
    margin-top: 0.5rem;
}

.sample-row {
    display: grid;
    grid-template-columns: 1fr 150px 40px;
    gap: 0.5rem;
    align-items: end;
    margin-bottom: 0.5rem;
}

.sample-row .form-group { margin-bottom: 0; }

/* ── Search ── */
.search-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.search-bar input { flex: 1; }

/* ── Customer Detail ── */
.customer-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.info-item label {
    font-size: 0.75rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.info-item p {
    font-size: 0.9rem;
    color: var(--gray-800);
    margin-top: 0.125rem;
}

/* ── Login ── */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--gray-100);
}

.login-card {
    background: white;
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 380px;
}

.login-card h1 {
    font-size: 1.25rem;
    text-align: center;
    margin-bottom: 0.25rem;
    color: var(--gray-900);
}

.login-card .subtitle {
    text-align: center;
    color: var(--gray-500);
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
}

/* ── Type Tags for Dashboard ── */
.type-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.type-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 999px;
    font-size: 0.8rem;
}

.type-tag .count {
    font-weight: 700;
    color: var(--primary);
}

/* ── Audit Log ── */
.audit-section {
    margin-top: 0.75rem;
    border-top: 1px dashed var(--gray-200);
    padding-top: 0.5rem;
}

.audit-toggle {
    background: none;
    border: none;
    font-size: 0.75rem;
    color: var(--gray-400);
    cursor: pointer;
    padding: 0;
}

.audit-toggle:hover { color: var(--primary); }

.audit-log {
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.audit-entry {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    padding: 0.375rem 0.5rem;
    border-radius: 4px;
    background: var(--gray-50);
}

.audit-created { border-left: 3px solid var(--success); }
.audit-edited  { border-left: 3px solid var(--warning); }
.audit-deleted { border-left: 3px solid var(--danger); }

.audit-action {
    font-weight: 700;
    font-size: 0.65rem;
    letter-spacing: 0.05em;
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
}

.audit-created .audit-action { background: var(--success-light); color: var(--success); }
.audit-edited  .audit-action { background: var(--warning-light); color: var(--warning); }
.audit-deleted .audit-action { background: var(--danger-light);  color: var(--danger);  }

.audit-who  { color: var(--gray-700); font-weight: 500; }
.audit-when { color: var(--gray-400); margin-left: auto; }
.audit-snapshot { width: 100%; color: var(--gray-500); font-style: italic; margin-top: 0.1rem; }

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

.empty-state p { font-size: 0.9rem; }

/* ── Responsive ── */
@media (max-width: 768px) {
    .navbar { flex-wrap: wrap; height: auto; padding: 0.75rem; gap: 0.5rem; }
    .nav-links { margin-left: 0; order: 3; width: 100%; }
    .form-row { grid-template-columns: 1fr; }
    .customer-info-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .sample-row { grid-template-columns: 1fr; }
}
