/* Genetics Tracker — Lab Genética
   Clean, functional UI for lab technicians */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --red: #dc2626;
    --green: #16a34a;
    --amber: #d97706;
    --radius: 6px;
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin: 0;
    background: var(--gray-50);
    color: var(--gray-800);
    font-size: 14px;
}

.navbar {
    background: var(--gray-800);
    color: white;
    padding: 0 24px;
    display: flex;
    align-items: center;
    height: 52px;
    gap: 32px;
}
.nav-brand a { color: white; text-decoration: none; font-size: 18px; font-weight: 700; }
.nav-links { display: flex; gap: 16px; align-items: center; }
.nav-links a { color: #d1d5db; text-decoration: none; font-size: 14px; }
.nav-links a:hover { color: white; }

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

/* Buttons */
.btn-primary {
    background: var(--primary); color: white; border: none;
    padding: 8px 16px; border-radius: var(--radius); cursor: pointer;
    text-decoration: none; font-size: 14px; display: inline-block;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
    background: white; color: var(--gray-700); border: 1px solid var(--gray-300);
    padding: 8px 16px; border-radius: var(--radius); cursor: pointer;
    text-decoration: none; font-size: 14px; display: inline-block;
}
.btn-secondary:hover { background: var(--gray-100); }
.btn-lg { padding: 12px 24px; font-size: 16px; }

/* Dashboard */
.dashboard-header { margin-bottom: 20px; }
.dashboard-header h1 { margin: 0 0 4px; }
.subtitle { color: var(--gray-600); margin: 0; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: white; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 16px; }
.stat-card h3 { margin: 0 0 12px; font-size: 14px; color: var(--gray-600); text-transform: uppercase; letter-spacing: 0.5px; }

.stats-table { width: 100%; font-size: 13px; }
.stats-table td { padding: 3px 0; }
.stats-table .num { text-align: right; font-weight: 600; }

.quick-actions { display: flex; flex-direction: column; gap: 10px; }

/* Tables */
.data-table { width: 100%; background: white; border-collapse: collapse; border: 1px solid var(--gray-200); border-radius: var(--radius); overflow: hidden; }
.data-table th, .data-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--gray-100); }
.data-table th { background: var(--gray-50); font-size: 12px; text-transform: uppercase; color: var(--gray-600); letter-spacing: 0.5px; }
.data-table tr:hover td { background: #f0f7ff; }
.data-table code { background: var(--gray-100); padding: 2px 6px; border-radius: 3px; font-size: 12px; }
.data-table .actions { white-space: nowrap; }

/* Badges & Status */
.badge { padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.badge-genetic_profiles { background: #e0e7ff; color: #3730a3; }
.badge-veterinary { background: #d1fae5; color: #065f46; }
.badge-sanger { background: #fef3c7; color: #92400e; }
.badge-str { background: #fce7f3; color: #9d174d; }
.badge-ngs { background: #e0e7ff; color: #1e3a5f; }
.badge-pcr { background: #ffe4e6; color: #9f1239; }
.badge-other { background: var(--gray-100); color: var(--gray-600); }

.status { padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.status-received { background: #dbeafe; color: #1e40af; }
.status-extracted { background: #ddd6fe; color: #5b21b6; }
.status-quantified { background: #fef3c7; color: #92400e; }
.status-diluted { background: #e0e7ff; color: #3730a3; }
.status-plated { background: #d1fae5; color: #065f46; }
.status-pcr_done { background: #fee2e2; color: #991b1b; }
.status-sequenced { background: #dbeafe; color: #1e3a40; }
.status-analyzed { background: #fce7f3; color: #9d174d; }
.status-reported { background: #d1fae5; color: #065f46; }
.status-archived { background: var(--gray-200); color: var(--gray-600); }

/* Forms */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-header h1 { margin: 0; }
.create-form-container { display: grid; grid-template-columns: 1fr 320px; gap: 24px; }
.sample-form { background: white; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 24px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 16px; }
.form-group { display: flex; flex-direction: column; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--gray-600); margin-bottom: 4px; text-transform: uppercase; }
.form-group input, .form-group select, .form-group textarea {
    padding: 8px 10px; border: 1px solid var(--gray-300); border-radius: var(--radius);
    font-size: 14px; font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,0.2);
}
.form-group input[readonly] { background: var(--gray-50); color: var(--gray-600); font-family: monospace; }
.form-group small { color: var(--gray-600); font-size: 11px; margin-top: 2px; }
.form-actions { margin-top: 20px; display: flex; gap: 8px; align-items: center; }

.label-preview { background: white; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 16px; }
.label-preview h3 { margin: 0 0 12px; font-size: 13px; color: var(--gray-600); text-transform: uppercase; }
.label-canvas { border: 1px solid var(--gray-200); padding: 10px; text-align: center; border-radius: var(--radius); }
.label-canvas canvas { max-width: 100%; }
.label-text { margin-top: 6px; }
.label-text strong { font-size: 12px; font-family: monospace; }
.label-text small { display: block; color: var(--gray-600); font-size: 11px; }

/* Search */
.search-bar { margin-bottom: 16px; }
.search-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search-form input[type="text"] { flex: 1; min-width: 200px; padding: 8px 10px; border: 1px solid var(--gray-300); border-radius: var(--radius); font-size: 14px; }
.search-form select { padding: 8px 10px; border: 1px solid var(--gray-300); border-radius: var(--radius); font-size: 14px; }
.results-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; color: var(--gray-600); font-size: 13px; }

/* Detail */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); gap: 16px; }
.detail-card { background: white; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 16px; }
.detail-card h3 { margin: 0 0 12px; font-size: 13px; color: var(--gray-600); text-transform: uppercase; }
.detail-table { width: 100%; font-size: 13px; }
.detail-table th { text-align: left; color: var(--gray-600); padding: 3px 8px 3px 0; white-space: nowrap; width: 120px; }
.detail-table td { padding: 3px 0; }

/* Status actions */
.status-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.status-btn { padding: 4px 10px; border: 1px solid var(--gray-300); border-radius: var(--radius); background: white; cursor: pointer; font-size: 12px; }
.status-btn:hover { background: var(--gray-100); }
.status-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* Barcode scan input */
.barcode-scan-input {
    width: 100%; padding: 8px 10px; border: 2px dashed var(--gray-300);
    border-radius: var(--radius); font-size: 14px; font-family: monospace;
}
.barcode-scan-input:focus { outline: none; border-color: var(--primary); }

/* Pagination */
.pagination { display: flex; gap: 4px; margin-top: 16px; }
.pagination a { padding: 6px 12px; border: 1px solid var(--gray-300); border-radius: var(--radius); text-decoration: none; color: var(--gray-700); font-size: 13px; }
.pagination a.active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination a:hover:not(.active) { background: var(--gray-100); }

/* Empty state */
.empty-state { text-align: center; color: var(--gray-600); padding: 40px 0; }

/* Error */
.error-page { text-align: center; padding: 60px 0; }

/* Timeline */
.timeline { padding-left: 20px; border-left: 2px solid var(--gray-200); }
.timeline-item { position: relative; padding: 8px 0 8px 20px; font-size: 13px; }
.timeline-item .dot { position: absolute; left: -26px; top: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--gray-300); }
.timeline-item.completed .dot { background: var(--green); }
.timeline-item .label { font-weight: 600; }
.timeline-item .date { display: block; color: var(--gray-600); font-size: 11px; }

/* ── Phase 4: Plate Grid ────────────────────────────────────── */

.plate-grid-wrapper { overflow-x: auto; }
.plate-grid { display: inline-block; background: white; border: 2px solid var(--gray-800); border-radius: var(--radius); padding: 8px; }
.plate-col-header { display: flex; gap: 1px; margin-bottom: 1px; }
.plate-col-header .corner { width: 28px; }
.plate-col-header .col-num {
    width: 56px; text-align: center; font-size: 11px; font-weight: 700;
    color: var(--gray-600); padding: 2px 0;
}
.plate-row { display: flex; gap: 1px; margin-bottom: 1px; }
.row-label {
    width: 28px; display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; color: var(--gray-600);
}

.well {
    width: 56px; height: 48px;
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    border-radius: 3px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.15s; overflow: hidden; position: relative;
}
.well:hover { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,0.3); z-index: 2; }
.well.filled { border-color: #94a3b8; }
.well .well-pos { font-size: 9px; color: #94a3b8; position: absolute; top: 1px; left: 3px; }
.well .well-barcode { font-size: 11px; font-family: monospace; font-weight: 700; }
.well .well-conc { font-size: 9px; color: var(--gray-600); }

/* Well sample type colors */
.well-blood { background: #dbeafe; }
.well-swab { background: #d1fae5; }
.well-tissue { background: #ffe4e6; }
.well-extracted_dna { background: #fef3c7; }
.well-ffpe { background: #fce7f3; }
.well-other { background: var(--gray-100); }

/* Plate legend */
.plate-legend .legend-dot {
    display: inline-block; width: 14px; height: 14px;
    border-radius: 3px; vertical-align: middle; margin-right: 4px;
}

/* Plate type/status badges on plates */
.badge-extraction { background: #dbeafe; color: #1e40af; }
.badge-dilution { background: #e0e7ff; color: #3730a3; }
.badge-library_prep { background: #ddd6fe; color: #5b21b6; }
.badge-sequencing { background: #d1fae5; color: #065f46; }

.status-preparing { background: var(--gray-100); color: var(--gray-600); }
.status-ready { background: #dbeafe; color: #1e40af; }
.status-in_progress { background: #fef3c7; color: #92400e; }
.status-completed { background: #d1fae5; color: #065f46; }

/* Header actions bar */
.header-actions { display: flex; gap: 8px; align-items: center; }

/* Flash messages */
.flash-success {
    background: #d1fae5; color: #065f46; padding: 10px 16px;
    border-radius: var(--radius); margin-bottom: 16px; font-weight: 600;
}
.warnings { margin-bottom: 16px; }
.warning-item {
    background: #fef3c7; color: #92400e; padding: 8px 12px;
    border-radius: var(--radius); margin-bottom: 4px; font-size: 13px;
}

/* Modal */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
}
.modal-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.4);
}
.modal-content {
    position: relative; background: white; border-radius: var(--radius);
    padding: 24px; max-width: 480px; width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-content h3 { margin: 0 0 12px; }

/* Print styles for labels */
@media print {
    body { background: white; }
    .navbar, .container > *:not(.label-area) { display: none !important; }
    .label-area { margin: 0; padding: 0; }
}

/* ── Dashboard 2.0 KPI Cards ─────────────────────────────────── */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi-card { border-radius: var(--radius); padding: 20px; text-align: center; color: white; }
.kpi-card .kpi-num { font-size: 32px; font-weight: 800; line-height: 1.2; }
.kpi-card .kpi-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.85; margin-top: 4px; }
.kpi-blue { background: linear-gradient(135deg, #2563eb, #1d4ed8); }
.kpi-green { background: linear-gradient(135deg, #16a34a, #15803d); }
.kpi-amber { background: linear-gradient(135deg, #d97706, #b45309); }
.kpi-purple { background: linear-gradient(135deg, #7c3aed, #6d28d9); }

/* ── Pipeline Funnel ────────────────────────────────────────── */
.pipeline-funnel { display: flex; flex-direction: column; gap: 4px; }
.pipeline-row { display: flex; align-items: center; gap: 8px; }
.pipeline-label { font-size: 11px; width: 110px; text-align: right; color: var(--gray-600); flex-shrink: 0; white-space: nowrap; }
.pipeline-bar-bg { flex: 1; height: 16px; background: var(--gray-100); border-radius: 8px; overflow: hidden; }
.pipeline-bar { height: 100%; border-radius: 8px; min-width: 4px; transition: width 0.6s ease; }
.pipeline-num { font-size: 12px; font-weight: 700; width: 30px; color: var(--gray-800); }

/* ── Lineage Tree ───────────────────────────────────────────── */
.lineage-tree { padding: 16px 0; }
.tree-node { display: inline-flex; flex-direction: column; align-items: center; margin: 0 12px; }
.tree-node-card {
    background: white; border: 2px solid var(--gray-200); border-radius: var(--radius);
    padding: 8px 14px; text-align: center; min-width: 120px; cursor: pointer;
    transition: border-color 0.15s; font-size: 12px;
}
.tree-node-card:hover { border-color: var(--primary); }
.tree-node-card.root { border-color: var(--primary); border-width: 2px; }
.tree-node-card .tn-barcode { font-family: monospace; font-weight: 700; font-size: 13px; }
.tree-node-card .tn-type { font-size: 10px; color: var(--gray-600); }
.tree-node-card .tn-rel { font-size: 9px; color: var(--amber); text-transform: uppercase; margin-top: 2px; }
.tree-children { display: flex; gap: 24px; justify-content: center; margin-top: 16px; padding-top: 16px; border-top: 2px solid var(--gray-200); position: relative; }

/* ── Section links ──────────────────────────────────────────── */
.section-links .btn-secondary { justify-content: center; }

/* ── Responsive: Tablet ────────────────────────────────────────── */
@media (max-width: 768px) {
    .navbar { padding: 0 12px; gap: 12px; overflow-x: auto; }
    .nav-links { gap: 8px; flex-shrink: 0; }
    .nav-links a { font-size: 12px; white-space: nowrap; }
    .nav-brand a { font-size: 15px; }

    .container { padding: 16px 12px; }

    .detail-grid { grid-template-columns: 1fr; }
    .create-form-container { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .header-actions { width: 100%; flex-wrap: wrap; }

    .stats-grid { grid-template-columns: 1fr; }
    .kpi-row { grid-template-columns: repeat(2, 1fr); }
    .form-row { grid-template-columns: 1fr; }

    .data-table { display: block; overflow-x: auto; }
    .detail-table th { width: 90px; }

    .well { width: 36px; height: 32px; }
    .well .well-barcode { font-size: 8px; }
    .well .well-conc { display: none; }
    .plate-col-header .col-num { width: 36px; font-size: 9px; }
}

/* ── Responsive: Mobile ────────────────────────────────────────── */
@media (max-width: 480px) {
    .navbar { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 6px; }
    .nav-links { flex-wrap: wrap; gap: 4px; }
    .nav-links a { font-size: 11px; padding: 3px 6px; }
    .nav-links .btn-primary { font-size: 11px; padding: 4px 8px; }

    .container { padding: 12px 8px; }

    .pipeline-label { width: 80px; font-size: 10px; }
    .kpi-row { grid-template-columns: 1fr 1fr; gap: 8px; }
    .kpi-card { padding: 12px; }
    .kpi-card .kpi-num { font-size: 24px; }

    .data-table th, .data-table td { padding: 6px 8px; font-size: 12px; }
    .tree-children { flex-direction: column; align-items: center; }
    .tree-node { margin: 4px 0; }
}
