@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Fraunces:ital,opsz,wght@0,9..144,300;0,9..144,600;1,9..144,300&family=Inter:wght@400;500;600;700&display=swap');

:root {
    --black: #0e0e0e;
    --white: #f5f3ee;
    --ink: #1a1a1a;
    --muted: #6b6560;
    --border: #d8d4ce;
    --border-strong: #a09a93;
    --accent: #c8432a;
    --accent-light: #f7ebe8;
    --surface: #faf8f5;
    --surface-2: #f0ece5;
    --success: #2a7a4b;
    --success-bg: #eaf4ee;
    --warn: #9c6c1a;
    --warn-bg: #fdf3e0;
    --danger: #c8432a;
    --danger-bg: #f7ebe8;
    --font-display: 'Fraunces', Georgia, serif;
    --font-sans: 'Inter', sans-serif;
    --font-mono: 'DM Mono', monospace;
    --radius: 2px;
    --radius-md: 4px;
    --radius-lg: 6px;
    --transition: 150ms ease;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-sans);
    background: var(--surface);
    color: var(--ink);
    min-height: 100vh;
    line-height: 1.6;
}

/* ── Typography ── */
h1,
h2,
h3 {
    font-family: var(--font-display);
    font-weight: 300;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

h1 {
    font-size: 2rem;
}

h2 {
    font-size: 1.4rem;
}

h3 {
    font-size: 1.1rem;
}

p {
    color: var(--muted);
    font-size: 0.9rem;
}

label {
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.mono {
    font-family: var(--font-mono);
}

/* ── Layout ── */
.app-shell {
    display: grid;
    grid-template-columns: 220px 1fr;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
}

/* ── Topbar ── */
.topbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    height: 56px;
    border-bottom: 1px solid var(--border);
    background: var(--white);
}

.topbar-brand {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.topbar-brand .wordmark {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.15rem;
    letter-spacing: -0.03em;
    color: var(--ink);
}

.topbar-brand .tag {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--muted);
    border: 1px solid var(--border);
    padding: 1px 6px;
    border-radius: var(--radius);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.82rem;
    color: var(--muted);
}

.avatar {
    width: 30px;
    height: 30px;
    background: var(--ink);
    color: var(--white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 500;
}

/* ── Sidebar ── */
.sidebar {
    background: var(--white);
    border-right: 1px solid var(--border);
    padding: 1.5rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-section {
    padding: 0.75rem 1.25rem 0.25rem;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--border-strong);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0.55rem 1.25rem;
    font-size: 0.85rem;
    color: var(--muted);
    cursor: pointer;
    border-left: 2px solid transparent;
    transition: all var(--transition);
    text-decoration: none;
}

.nav-item i {
    font-size: 16px;
    opacity: 0.7;
}

.nav-item:hover {
    color: var(--ink);
    background: var(--surface-2);
}

.nav-item.active {
    color: var(--ink);
    font-weight: 600;
    border-left-color: var(--accent);
    background: var(--accent-light);
}

.nav-item.active i {
    opacity: 1;
    color: var(--accent);
}

.main-content {
    padding: 2.5rem 2.5rem 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* ── Footer ── */
.main-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    text-align: center;
    font-family: var(--font-sans);
    font-size: 0.82rem;
    color: var(--muted);
}

.page {
    display: none;
}

.page.active {
    display: block;
}

/* ── Page header ── */
.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 2rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.page-header .eyebrow {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    color: var(--accent);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

.page-header h1 {
    line-height: 1;
}

/* ── Cards ── */
.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

.card-sm {
    padding: 1rem 1.25rem;
}

/* ── Grid ── */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

/* ── Stat cards ── */
.stat-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}

.stat-card .stat-label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.4rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.stat-card .stat-label i {
    font-size: 14px;
}

.stat-card .stat-value {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 600;
    color: var(--ink);
    line-height: 1;
}

.stat-card .stat-sub {
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 0.35rem;
}

.stat-card.accent-left {
    border-left: 3px solid var(--accent);
}

.stat-card.accent-success {
    border-left: 3px solid var(--success);
}

.stat-card.accent-warn {
    border-left: 3px solid var(--warn);
}

/* ── Forms ── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    display: block;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    transition: border-color var(--transition), background var(--transition);
    outline: none;
    appearance: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--ink);
    background: var(--white);
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6560' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 2rem;
    cursor: pointer;
}

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

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 0.5rem 1.1rem;
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.btn i {
    font-size: 15px;
}

.btn-primary {
    background: var(--ink);
    color: var(--white);
    border-color: var(--ink);
}

.btn-primary:hover {
    background: #333;
}

.btn-outline {
    background: transparent;
    color: var(--ink);
    border-color: var(--border-strong);
}

.btn-outline:hover {
    border-color: var(--ink);
    background: var(--surface-2);
}

.btn-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: #e8b5ac;
}

.btn-danger:hover {
    background: #f0cdc7;
}

.btn-success {
    background: var(--success-bg);
    color: var(--success);
    border-color: #b5ddc5;
}

.btn-success:hover {
    background: #d5ece0;
}

.btn-sm {
    padding: 0.3rem 0.7rem;
    font-size: 0.75rem;
}

.btn-full {
    width: 100%;
    justify-content: center;
}

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border-radius: var(--radius);
    border: 1px solid;
    width: 100px;
    justify-content: center;
}

.badge-urgente {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: #e8b5ac;
}

.badge-normal {
    background: var(--surface-2);
    color: var(--muted);
    border-color: var(--border);
}

.badge-pendiente {
    background: var(--warn-bg);
    color: var(--warn);
    border-color: #e8d5a8;
}

.badge-proceso {
    background: #e8f0fb;
    color: #1a4fa0;
    border-color: #b5cef0;
}

.badge-entregado {
    background: var(--success-bg);
    color: var(--success);
    border-color: #b5ddc5;
}

.badge-admin {
    background: #f1e8ff;
    color: #6a1b9a;
    border-color: #d1bced;
}

.badge-operario {
    background: #e8f4f8;
    color: #0277bd;
    border-color: #b3e5fc;
}

/* ── Table ── */
.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    table-layout: auto;
}

thead th {
    text-align: left;
    padding: 0.6rem 1rem;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    color: var(--ink);
    white-space: nowrap;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover td {
    background: var(--surface);
}

.td-mono {
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

.td-muted {
    color: var(--muted);
    font-size: 0.82rem;
}

.actions {
    display: flex;
    gap: 6px;
}

/* ── Dividers ── */
.divider {
    height: 1px;
    background: var(--border);
    margin: 1.5rem 0;
}

.divider-v {
    width: 1px;
    background: var(--border);
}

/* ── Result estimacion ── */
.estimate-result {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.estimate-header {
    background: var(--ink);
    color: var(--white);
    padding: 0.9rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.estimate-header .label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    opacity: 0.6;
}

.estimate-header .dias-big {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 600;
}

.estimate-body {
    background: var(--white);
    padding: 1.25rem;
}

.date-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
    text-align: center;
}

.date-block .date-label {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 4px;
}

.date-block .date-val {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--ink);
}

.date-arrow {
    color: var(--border-strong);
    font-size: 20px;
}

.formula-tag {
    margin-top: 1rem;
    padding: 0.6rem 0.9rem;
    background: var(--surface-2);
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--muted);
    border-left: 2px solid var(--border-strong);
}

.formula-tag strong {
    color: var(--ink);
}

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

.login-box {
    width: 380px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem 2rem;
}

.login-logo {
    font-family: var(--font-display);
    font-size: 1.6rem;
    font-weight: 600;
    letter-spacing: -0.04em;
    margin-bottom: 0.25rem;
}

.login-logo span {
    color: var(--accent);
}

.login-sub {
    font-size: 0.82rem;
    color: var(--muted);
    margin-bottom: 2rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* ── Alerts ── */
.alert {
    padding: 0.7rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid;
}

.alert i {
    font-size: 15px;
    flex-shrink: 0;
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: #e8b5ac;
}

.alert-success {
    background: var(--success-bg);
    color: var(--success);
    border-color: #b5ddc5;
}

.alert-warn {
    background: var(--warn-bg);
    color: var(--warn);
    border-color: #e8d5a8;
}

/* ── Modal ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(14, 14, 14, 0.45);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

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

.modal {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 520px;
    max-width: 94vw;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 1rem;
    font-family: var(--font-sans);
    font-weight: 600;
}

.modal-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--muted);
}

.empty-state i {
    font-size: 36px;
    opacity: 0.25;
    margin-bottom: 0.75rem;
    display: block;
}

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

/* ── Misc ── */
.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-sm {
    gap: 0.5rem;
}

.gap-md {
    gap: 1rem;
}

.gap-lg {
    gap: 1.5rem;
}

.mt-sm {
    margin-top: 0.5rem;
}

.mt-md {
    margin-top: 1rem;
}

.mt-lg {
    margin-top: 1.5rem;
}

.mb-md {
    margin-bottom: 1rem;
}

.text-right {
    text-align: right;
}

.hidden {
    display: none !important;
}

.text-accent {
    color: var(--accent);
}

.text-success {
    color: var(--success);
}

.text-muted {
    color: var(--muted);
}

.fw-600 {
    font-weight: 600;
}

.mono-sm {
    font-family: var(--font-mono);
    font-size: 0.78rem;
}

/* ── Animations ── */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-in {
    animation: fadeIn 250ms ease forwards;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

/* ── Toast Notification ── */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid #b5ddc5;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: slideLeftFade 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards, fadeOutRight 0.4s ease 2.6s forwards;
    opacity: 0;
}

@keyframes slideLeftFade {
    0% {
        transform: translateX(50px);
        opacity: 0;
    }

    100% {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeOutRight {
    0% {
        transform: translateX(0);
        opacity: 1;
    }

    100% {
        transform: translateX(50px);
        opacity: 0;
    }
}

.text-success {
    color: var(--success);
}

/* ── Responsive Mobile ── */
.hidden-desktop {
    display: none !important;
}

.btn-icon {
    background: transparent;
    border: none;
    font-size: 1.25rem;
    color: var(--ink);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
}

@media (max-width: 768px) {
    .hidden-desktop {
        display: inline-flex !important;
    }

    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        padding-bottom: 0;
    }

    .sidebar {
        position: fixed;
        top: 56px;
        left: -100%;
        width: 250px;
        height: calc(100vh - 56px);
        flex-direction: column;
        padding: 1.5rem 0;
        border-right: 1px solid var(--border);
        border-top: none;
        z-index: 1000;
        justify-content: flex-start;
        background: var(--white);
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.05);
        transition: left 0.3s ease;
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-overlay {
        position: fixed;
        top: 56px;
        left: 0;
        width: 100vw;
        height: calc(100vh - 56px);
        background: rgba(0, 0, 0, 0.4);
        z-index: 999;
        display: block;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.open {
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar-overlay.hidden {
        display: none !important;
    }

    .sidebar-section {
        display: block;
    }

    .nav-item {
        flex-direction: row;
        justify-content: flex-start;
        padding: 0.55rem 1.25rem;
        gap: 10px;
        font-size: 0.85rem;
        border-left: 2px solid transparent;
        border-bottom: none;
        flex: none;
        text-align: left;
    }

    .nav-item.active {
        border-left-color: var(--accent);
        border-bottom: none;
        background: var(--accent-light);
        color: var(--accent);
    }

    .nav-item i {
        font-size: 16px;
    }

    .main-content {
        padding: 1.5rem 1rem 1rem;
    }

    .grid-2,
    .grid-4 {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .topbar {
        padding: 0 1rem;
    }

    #topbar-nombre,
    #topbar-rol {
        display: none;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .page-header button {
        width: 100%;
        justify-content: center;
    }

    .estimate-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .date-row {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }

    .date-arrow {
        transform: rotate(90deg);
        margin: 0.5rem 0 0.5rem 1rem;
    }

    .modal {
        width: 95% !important;
        padding: 1.25rem;
        max-height: 90vh;
        overflow-y: auto;
    }

    .table-wrap {
        border-radius: 0;
        border-left: none;
        border-right: none;
        margin: 0;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 800px;
        /* Activa el scroll horizontal */
    }
}