:root {
    --ink: #062b3a;
    --muted: #667884;
    --teal: #009b8d;
    --teal-dark: #007d73;
    --teal-soft: #e8f7f5;
    --line: #dbe7e8;
    --surface: #ffffff;
    --background: #f3f7f7;
    --danger: #b63838;
    --shadow: 0 18px 50px rgba(5, 48, 60, .10);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    color: var(--ink);
    background: var(--background);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--background); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.eyebrow {
    display: block;
    color: var(--teal-dark);
    font-size: .74rem;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.login-shell {
    background:
        radial-gradient(circle at 10% 10%, rgba(0, 155, 141, .22), transparent 33rem),
        linear-gradient(135deg, #052f3d 0%, #06414d 52%, #007f75 100%);
}

.login-layout {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(22rem, .75fr);
    align-items: center;
    gap: clamp(2rem, 7vw, 8rem);
    max-width: 1240px;
    margin: auto;
    padding: clamp(2rem, 6vw, 6rem);
}

.login-brand { color: white; max-width: 42rem; }
.login-brand .eyebrow { color: #75e2d8; }
.login-brand h1 {
    margin: .7rem 0 1.2rem;
    font-size: clamp(3rem, 7vw, 6.8rem);
    line-height: .92;
    letter-spacing: -.06em;
}
.login-brand h1 strong { color: #71e0d5; }
.login-brand p { max-width: 32rem; font-size: 1.15rem; line-height: 1.7; color: #d3e8e9; }
.brand-points { display: flex; flex-wrap: wrap; gap: .65rem; margin-top: 2rem; }
.brand-points span {
    padding: .55rem .8rem;
    border: 1px solid rgba(255,255,255,.2);
    border-radius: 999px;
    background: rgba(255,255,255,.06);
    color: #e8f5f5;
    font-size: .83rem;
}

.login-card {
    padding: clamp(1.7rem, 4vw, 3rem);
    border: 1px solid rgba(255,255,255,.62);
    border-radius: 1.5rem;
    background: rgba(255,255,255,.97);
    box-shadow: 0 30px 90px rgba(0,0,0,.24);
}
.brand-mark { color: var(--teal-dark); font-weight: 900; font-size: 1.45rem; letter-spacing: -.05em; }
.brand-mark small { display: block; font-size: .52rem; letter-spacing: .32em; }
.login-card h2 { font-size: 2rem; margin: 2.2rem 0 .5rem; }
.login-card > p { color: var(--muted); line-height: 1.5; }
.login-card form { display: grid; gap: .72rem; margin-top: 1.7rem; }
label { font-weight: 750; font-size: .82rem; color: #294853; }
input, select {
    min-height: 2.85rem;
    padding: .7rem .85rem;
    border: 1px solid #c8d8da;
    border-radius: .65rem;
    background: white;
    color: var(--ink);
    outline: none;
}
input:focus, select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0,155,141,.13); }
.primary-button {
    min-height: 2.85rem;
    padding: .72rem 1.2rem;
    border: 0;
    border-radius: .65rem;
    background: var(--teal);
    color: white;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(0,155,141,.18);
}
.primary-button:hover { background: var(--teal-dark); }
.login-card .primary-button { margin-top: .65rem; }
.sync-note { margin: 1.5rem 0 0; font-size: .77rem; text-align: center; }
.alert {
    margin-top: 1rem;
    padding: .85rem 1rem;
    border: 1px solid #f1c4c4;
    border-radius: .6rem;
    background: #fff0f0;
    color: var(--danger);
    font-size: .85rem;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 5.3rem;
    padding: 1rem clamp(1.2rem, 4vw, 4rem);
    border-bottom: 1px solid var(--line);
    background: rgba(255,255,255,.96);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar h1 { margin: .2rem 0 0; font-size: 1.28rem; }
.user-area { display: flex; align-items: center; gap: 1rem; }
.user-area > div { display: grid; text-align: right; font-size: .83rem; }
.user-area span { color: var(--muted); font-size: .72rem; }
.ghost-button, .clear-button, .detail-button {
    min-height: 2.35rem;
    padding: .55rem .85rem;
    border: 1px solid var(--line);
    border-radius: .58rem;
    background: white;
    color: var(--ink);
    font-weight: 750;
    cursor: pointer;
    text-decoration: none;
}
.ghost-button:hover, .clear-button:hover, .detail-button:hover { border-color: var(--teal); color: var(--teal-dark); }

.dashboard { width: min(1600px, 100%); margin: auto; padding: clamp(1.3rem, 3vw, 3rem); }
.dashboard-heading { display: flex; justify-content: space-between; align-items: end; gap: 2rem; }
.dashboard-heading h2 { margin: .4rem 0 .4rem; font-size: clamp(1.8rem, 3vw, 2.7rem); letter-spacing: -.035em; }
.dashboard-heading p { margin: 0; color: var(--muted); }
.sync-badge {
    flex: 0 0 auto;
    padding: .7rem .9rem;
    border: 1px solid #bfe3df;
    border-radius: 999px;
    background: var(--teal-soft);
    color: var(--teal-dark);
    font-size: .78rem;
    font-weight: 800;
}
.sync-badge span { display: inline-block; width: .5rem; height: .5rem; margin-right: .35rem; border-radius: 50%; background: var(--teal); }

.metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin: 2rem 0;
}
.metrics article {
    min-height: 9.3rem;
    padding: 1.25rem;
    border: 1px solid var(--line);
    border-radius: 1rem;
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(6,43,58,.04);
}
.metrics span { color: var(--muted); font-size: .8rem; font-weight: 750; }
.metrics strong { display: block; margin: .5rem 0 .2rem; font-size: 2.5rem; letter-spacing: -.05em; }
.metrics small { color: #87979f; }
.metrics article:first-child { background: var(--ink); color: white; border-color: var(--ink); }
.metrics article:first-child span, .metrics article:first-child small { color: #bcd0d5; }

.content-card {
    border: 1px solid var(--line);
    border-radius: 1rem;
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.filters {
    display: grid;
    grid-template-columns: minmax(16rem, 2fr) minmax(10rem, 1fr) repeat(2, minmax(9rem, .8fr)) auto auto;
    align-items: end;
    gap: .8rem;
    padding: 1.2rem;
    border-bottom: 1px solid var(--line);
    background: #fbfdfd;
}
.filters > div { display: grid; gap: .4rem; }
.filter-button, .clear-button { display: inline-grid; place-items: center; }
.table-heading { display: flex; justify-content: space-between; align-items: center; padding: 1.2rem; }
.table-heading h3 { margin: 0; }
.table-heading p, .table-heading > span { margin: .25rem 0 0; color: var(--muted); font-size: .78rem; }
.table-wrap { overflow: auto; border-top: 1px solid var(--line); }
table { width: 100%; min-width: 1460px; border-collapse: collapse; }
.mobile-samples { display: none; }
.sample-card {
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: .9rem;
    background: var(--surface);
    box-shadow: 0 6px 18px rgba(6,43,58,.06);
}
.sample-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: .8rem;
}
.sample-card-header > div,
.sample-card-reference {
    display: grid;
    gap: .25rem;
}
.sample-card-header strong {
    font-size: 1.15rem;
    letter-spacing: -.02em;
}
.sample-card-label,
.sample-card-grid dt {
    color: var(--muted);
    font-size: .68rem;
    font-weight: 750;
    letter-spacing: .03em;
    text-transform: uppercase;
}
.sample-card-reference {
    margin-top: .9rem;
    padding: .7rem .8rem;
    border-left: 3px solid var(--teal);
    border-radius: .45rem;
    background: var(--teal-soft);
}
.sample-card-reference strong { overflow-wrap: anywhere; }
.sample-card-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .75rem;
    margin: 1rem 0;
}
.sample-card-grid > div {
    min-width: 0;
    padding-top: .7rem;
    border-top: 1px solid #edf2f2;
}
.sample-card-grid dt,
.sample-card-grid dd { margin: 0; }
.sample-card-grid dd {
    margin-top: .3rem;
    color: #294853;
    font-size: .82rem;
    font-weight: 650;
    line-height: 1.4;
    overflow-wrap: anywhere;
}
.sample-card-wide { grid-column: 1 / -1; }
.sample-card-button { width: 100%; }
th {
    padding: .75rem .8rem;
    background: #edf5f5;
    color: #3f5962;
    font-size: .7rem;
    letter-spacing: .04em;
    text-align: left;
    text-transform: uppercase;
    white-space: nowrap;
}
td { padding: .82rem .8rem; border-top: 1px solid #edf1f1; font-size: .78rem; vertical-align: top; }
tbody tr:hover { background: #f8fbfb; }
.center { text-align: center; }
.document-cell { max-width: 15rem; color: #31545d; line-height: 1.45; }
.state {
    display: inline-block;
    padding: .34rem .55rem;
    border-radius: 999px;
    background: #eef3f4;
    color: #39545c;
    font-size: .7rem;
    font-weight: 800;
    white-space: nowrap;
}
.state-en_custodia, .state-almacenado { background: #e6f6f4; color: #007c71; }
.state-en_curso { background: #eaf1ff; color: #2e5da7; }
.state-enviado { background: #edf6e9; color: #3b7131; }
.empty-state { padding: 3.5rem; text-align: center; color: var(--muted); }
.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; padding: 1rem; border-top: 1px solid var(--line); }
.pagination a { color: var(--teal-dark); font-weight: 800; text-decoration: none; }
.pagination .disabled { pointer-events: none; opacity: .35; }

.sample-dialog {
    width: min(900px, calc(100% - 2rem));
    max-height: calc(100vh - 2rem);
    padding: 0;
    border: 0;
    border-radius: 1.2rem;
    color: var(--ink);
    box-shadow: 0 30px 100px rgba(0,0,0,.32);
}
.sample-dialog::backdrop { background: rgba(3,30,39,.62); backdrop-filter: blur(3px); }
.dialog-header { display: flex; justify-content: space-between; align-items: center; padding: 1.3rem 1.5rem; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: .25rem 0 0; }
.dialog-close { width: 2.5rem; height: 2.5rem; border: 0; border-radius: 50%; background: #edf3f3; color: var(--ink); font-size: 1.5rem; cursor: pointer; }
.dialog-content { padding: 1.5rem; overflow: auto; }
.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
.detail-field { min-height: 4.6rem; padding: .85rem; border: 1px solid var(--line); border-radius: .7rem; background: #fbfdfd; }
.detail-field span { display: block; margin-bottom: .35rem; color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; }
.detail-field strong { font-size: .88rem; line-height: 1.45; }
.photo-upload {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: .8rem 1rem;
    margin-top: 1.2rem;
    padding: 1rem;
    border: 1px solid #bfe3df;
    border-radius: .8rem;
    background: var(--teal-soft);
}
.photo-upload h3 { margin: 0 0 .3rem; font-size: 1rem; }
.photo-upload p { margin: 0; color: #45666d; font-size: .78rem; line-height: 1.45; }
.photo-upload input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}
.photo-upload-button {
    display: inline-grid;
    place-items: center;
    min-height: 2.65rem;
    padding: .65rem 1rem;
    border-radius: .62rem;
    background: var(--teal);
    color: white;
    font-size: .8rem;
    font-weight: 800;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(0,155,141,.18);
}
.photo-upload-button:hover { background: var(--teal-dark); }
.photo-upload-status { grid-column: 1 / -1; }
.photo-upload-status.photo-upload-success { color: #17613d; font-weight: 750; }
.photo-upload-status.photo-upload-error { color: var(--danger); font-weight: 750; }
.sample-edit { margin-top: 1.2rem; padding: 1rem; border: 1px solid #bfe3df; border-radius: .8rem; background: #f5fbfa; }
.sample-edit form { margin-top: 1rem; }
.edit-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
.edit-grid label { display: grid; gap: .35rem; color: #45666d; font-size: .72rem; font-weight: 800; }
.edit-grid input, .edit-grid select, .edit-grid textarea,
.document-edit-row input { width: 100%; padding: .68rem .72rem; border: 1px solid #bfd2d3; border-radius: .55rem; background: white; color: var(--ink); font: inherit; }
.edit-grid textarea { min-height: 5.5rem; resize: vertical; }
.edit-wide { grid-column: 1 / -1; }
.documents-edit { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-top: 1rem; }
.documents-edit section { padding: .8rem; border: 1px solid var(--line); border-radius: .7rem; background: white; }
.documents-edit header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; }
.documents-edit h4 { margin: 0; }
.documents-edit header button, .remove-document { border: 0; border-radius: .45rem; background: #e5f4f2; color: var(--teal-dark); font-weight: 800; cursor: pointer; }
.documents-edit header button { padding: .45rem .65rem; }
.document-edit-row { display: grid; grid-template-columns: minmax(0, 1fr) 6rem 2rem; gap: .4rem; margin-top: .45rem; }
.remove-document { font-size: 1.1rem; }
.edit-actions { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; }
.edit-status { margin: 0; color: var(--muted); font-size: .8rem; }
.edit-status.edit-success { color: #17613d; font-weight: 750; }
.edit-status.edit-error { color: var(--danger); font-weight: 750; }
.history { margin-top: 1.6rem; }
.history h3 { margin: 0 0 .8rem; }
.history ol { list-style: none; margin: 0; padding: 0; border-left: 2px solid #bee1dd; }
.history li { position: relative; margin-left: 1rem; padding: 0 0 1.2rem 1rem; }
.history li::before { content: ""; position: absolute; left: -1.38rem; top: .2rem; width: .65rem; height: .65rem; border: 3px solid white; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 1px #bee1dd; }
.history li span, .history li small { color: var(--muted); font-size: .72rem; }
.history li strong { display: block; margin: .2rem 0; font-size: .82rem; }
.history li p { margin: .15rem 0; font-size: .82rem; }
.loading-state { display: flex; justify-content: center; align-items: center; gap: .7rem; min-height: 14rem; color: var(--muted); }
.loading-state span { width: 1.2rem; height: 1.2rem; border: 3px solid #c9dfdc; border-top-color: var(--teal); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1050px) {
    .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .search-field { grid-column: 1 / -1; }
    .metrics { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
    .login-layout { grid-template-columns: 1fr; gap: 2rem; padding: 1.2rem; }
    .login-brand { padding: 2rem 1rem 0; }
    .login-brand h1 { font-size: clamp(3rem, 16vw, 5rem); }
    .login-brand p, .brand-points { display: none; }
    .topbar { align-items: flex-start; }
    .user-area > div { display: none; }
    .dashboard-heading { align-items: flex-start; flex-direction: column; }
    .metrics { display: none; }
    .filters { grid-template-columns: 1fr; }
    .search-field { grid-column: auto; }
    .table-wrap { display: none; }
    .mobile-samples {
        display: grid;
        gap: .85rem;
        padding: 0 1rem 1rem;
    }
    .detail-grid { grid-template-columns: 1fr; }
    .photo-upload { grid-template-columns: 1fr; }
    .photo-upload-button { width: 100%; }
    .edit-grid, .documents-edit { grid-template-columns: 1fr; }
    .edit-wide { grid-column: auto; }
    .edit-actions { align-items: stretch; flex-direction: column; }
}

@media (max-width: 460px) {
    .dashboard { padding: 1rem; }
    .sync-badge { white-space: normal; }
}
