:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    min-height: 100%;
}

/* Layout: header y footer fijos, solo el contenido hace scroll */
.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.app-header,
.topbar.app-header {
    flex-shrink: 0;
    margin-bottom: 0;
    z-index: 20;
}

.app-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-top: 1.5rem;
    padding-bottom: 1rem;
}

.app-content > .container {
    padding-bottom: 0.5rem;
}

.app-footer {
    flex-shrink: 0;
    background: var(--panel);
    border-top: 1px solid var(--border);
    padding: 0.85rem 0;
    padding-bottom: calc(0.85rem + env(safe-area-inset-bottom));
    font-size: 0.78rem;
    color: var(--muted);
    z-index: 20;
}

.app-footer__inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
}

.app-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.app-footer a:hover {
    text-decoration: underline;
}

.container {
    width: min(1200px, 92%);
    margin: 0 auto;
}

.topbar {
    background: linear-gradient(135deg, #1e3a8a, #2563eb);
    color: #fff;
    padding: 1.5rem 0 2rem;
    margin-bottom: 1.5rem;
}

.topbar-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    min-width: 0;
}

.topbar-logo,
.login-logo {
    width: 42px;
    height: 42px;
    object-fit: contain;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.95);
    padding: 4px;
    flex-shrink: 0;
}

.login-brand {
    display: flex;
    justify-content: center;
    margin-bottom: 0.75rem;
}

.login-logo {
    width: 56px;
    height: 56px;
}

.eyebrow {
    margin: 0;
    opacity: 0.85;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.topbar h1 {
    margin: 0.25rem 0 0;
    font-size: 1.8rem;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.25rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
}

.upload-panel h2,
.panel h2 {
    margin-top: 0;
    font-size: 1.15rem;
}

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

.upload-form {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    margin-top: 1rem;
}

.dropzone {
    flex: 1 1 320px;
    border: 2px dashed #93c5fd;
    background: #eff6ff;
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    color: #1d4ed8;
}

.dropzone input {
    display: none;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 10px;
    padding: 0.75rem 1.1rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
}

.topbar .btn-secondary {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.35);
}

.topbar .btn-secondary:hover,
.btn-secondary:hover {
    filter: brightness(0.97);
}

.upload-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.75rem;
    align-items: center;
}

.inline-form {
    margin: 0;
}

.save-hint {
    color: #047857;
}

.file-hint {
    margin: 0.75rem 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.alert {
    padding: 0.9rem 1rem;
    border-radius: 10px;
    margin-bottom: 1rem;
}

.alert-success {
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-warning {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}

.meta-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.meta-bar > div {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
}

.meta-label {
    display: block;
    color: var(--muted);
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.kpi-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1rem;
    box-shadow: var(--shadow);
}

.kpi-card.kpi-warning {
    border-color: #fdba74;
    background: #fff7ed;
}

.kpi-label {
    display: block;
    color: var(--muted);
    font-size: 0.85rem;
}

.kpi-value {
    display: block;
    font-size: 1.7rem;
    margin-top: 0.2rem;
}

.kpi-card small {
    color: var(--muted);
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: end;
}

.filters label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 220px;
    font-size: 0.9rem;
}

.filters select,
.filters input {
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}

.chart-panel canvas {
    width: 100% !important;
    max-height: 280px;
}

.chart-panel {
    min-height: 300px;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-wrap.is-scrollable {
    position: relative;
}

.table-scroll-hint {
    display: none;
    margin: 0 0 0.5rem;
    font-size: 0.8rem;
    color: var(--muted);
    text-align: right;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.data-table th,
.data-table td {
    padding: 0.7rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

.data-table th {
    background: #f8fafc;
    position: sticky;
    top: 0;
}

.data-table tbody tr:hover {
    background: #f8fafc;
}

.row-warning {
    background: #fffbeb;
}

.row-danger {
    background: #fef2f2;
}

.punch-badge {
    display: inline-block;
    background: #dbeafe;
    color: #1e40af;
    border-radius: 999px;
    padding: 0.2rem 0.55rem;
    margin: 0.1rem 0.2rem 0.1rem 0;
    font-size: 0.82rem;
}

.badge-muted {
    color: var(--muted);
    font-size: 0.85rem;
}

.badge-absent {
    display: inline-block;
    background: #fee2e2;
    color: #991b1b;
    border-radius: 999px;
    padding: 0.2rem 0.65rem;
    font-size: 0.82rem;
    font-weight: 600;
}

.corrected-panel {
    border-color: #86efac;
    background: linear-gradient(180deg, #f0fdf4 0%, #ffffff 120px);
}

.rules-box {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: #f8fafc;
    border-radius: 10px;
    font-size: 0.9rem;
}

.cell-highlight {
    color: #047857;
}

.cell-ot {
    color: #b45309;
    font-weight: 600;
}

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

.panel-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
}

.panel-header h2 {
    margin-bottom: 0.35rem;
}

.inactive-note {
    margin: 0 0 1rem;
    padding: 0.65rem 1rem;
    background: #f3f4f6;
    border-radius: 8px;
    color: var(--muted);
    font-size: 0.9rem;
}

.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
}

code {
    background: #f3f4f6;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
}

.login-page {
    background: linear-gradient(135deg, #1e3a8a, #2563eb);
}

.app-layout--auth {
    background: linear-gradient(135deg, #1e3a8a, #2563eb);
}

.app-layout--auth .app-footer {
    background: rgba(15, 23, 42, 0.35);
    border-top-color: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.85);
}

.app-layout--auth .app-footer a {
    color: #fff;
}

.app-content--centered {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.login-card {
    width: min(420px, 100%);
    background: #fff;
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.2);
}

.login-card h1 {
    margin: 0.25rem 0 0.5rem;
}

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

.login-form label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
}

.login-form input {
    padding: 0.75rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
}

.btn-block {
    width: 100%;
}

.user-badge {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
    margin-right: 0.5rem;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.reports-panel code {
    font-size: 0.82rem;
    word-break: break-all;
}

.reports-table .btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.82rem;
}

.badge-active {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background: #d1fae5;
    color: #065f46;
    font-size: 0.82rem;
    font-weight: 600;
}

.row-active-report {
    background: #eff6ff;
}

.empty-hint {
    color: var(--muted);
    margin: 0;
}

.tabbed-panel h2 {
    margin-bottom: 0.35rem;
}

.tabbed-hint {
    margin: 0 0 1rem;
    font-size: 0.9rem;
}

.employee-tabs {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.tab-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #fff;
    color: var(--text);
    font: inherit;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.tab-btn:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.tab-btn.active {
    background: #dbeafe;
    border-color: #93c5fd;
    color: #1d4ed8;
    font-weight: 600;
}

.tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.35rem;
    height: 1.35rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.08);
    font-size: 0.75rem;
    font-weight: 700;
}

.tab-btn.active .tab-count {
    background: rgba(29, 78, 216, 0.15);
    color: #1d4ed8;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.tab-empty {
    margin: 0;
    padding: 1.25rem;
    text-align: center;
    color: var(--muted);
    background: #f8fafc;
    border: 1px dashed var(--border);
    border-radius: 10px;
}

.data-table-compact th,
.data-table-compact td {
    white-space: normal;
}

.data-table-compact td:last-child {
    min-width: 180px;
}

/* ── Responsive: laptop, tablet, móvil ── */

/* Laptop (≤1199px) */
@media (max-width: 1199px) {
    .container {
        width: min(1200px, 94%);
    }

    .charts-grid {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    }
}

/* Tablet (≤991px) */
@media (max-width: 991px) {
    .topbar {
        padding: 1.25rem 0 1.5rem;
    }

    .topbar h1 {
        font-size: 1.55rem;
    }

    .panel {
        padding: 1.1rem;
    }

    .kpi-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .kpi-value {
        font-size: 1.45rem;
    }

    .meta-bar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filters label {
        flex: 1 1 calc(50% - 0.5rem);
        min-width: 0;
    }

    .charts-grid {
        grid-template-columns: 1fr 1fr;
    }

    .chart-panel:last-child {
        grid-column: 1 / -1;
    }

    .rules-box {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* Móvil grande (≤767px) */
@media (max-width: 767px) {
    .container {
        width: min(1200px, 96%);
    }

    .app-footer__inner {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .topbar-inner {
        flex-direction: column;
        align-items: stretch;
    }

    .topbar-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .topbar-actions .btn {
        flex: 1 1 auto;
        min-height: 44px;
    }

    .user-badge {
        width: 100%;
        margin: 0 0 0.25rem;
    }

    .upload-form {
        flex-direction: column;
        align-items: stretch;
    }

    .dropzone {
        flex-basis: auto;
    }

    .upload-form .btn-primary,
    .upload-actions .btn,
    .upload-actions .inline-form {
        width: 100%;
    }

    .upload-actions .inline-form .btn {
        width: 100%;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .meta-bar {
        grid-template-columns: 1fr;
    }

    .filters {
        flex-direction: column;
        align-items: stretch;
    }

    .filters label {
        width: 100%;
        min-width: 0;
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .chart-panel:last-child {
        grid-column: auto;
    }

    .chart-panel canvas {
        max-height: 240px;
    }

    .tab-nav {
        flex-wrap: nowrap;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scrollbar-width: thin;
        padding-bottom: 0.5rem;
        margin: 0 -0.25rem;
        padding-left: 0.25rem;
        padding-right: 0.25rem;
    }

    .tab-btn {
        flex-shrink: 0;
        min-height: 44px;
    }

    .table-scroll-hint {
        display: block;
    }

    .data-table {
        font-size: 0.86rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.6rem 0.65rem;
    }

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

/* Móvil pequeño (≤479px) */
@media (max-width: 479px) {
    .topbar h1 {
        font-size: 1.3rem;
    }

    .eyebrow {
        font-size: 0.78rem;
    }

    .panel {
        padding: 1rem;
        border-radius: 12px;
    }

    .kpi-grid {
        grid-template-columns: 1fr;
    }

    .kpi-value {
        font-size: 1.35rem;
    }

    .btn {
        min-height: 44px;
    }

    .login-card {
        padding: 1.5rem;
    }
}

/* Tablas → tarjetas en móvil */
@media (max-width: 640px) {
    .responsive-table thead {
        display: none;
    }

    .responsive-table tbody tr {
        display: block;
        margin-bottom: 0.85rem;
        border: 1px solid var(--border);
        border-radius: 12px;
        overflow: hidden;
        background: #fff;
        box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
    }

    .responsive-table tbody tr:hover {
        background: #fff;
    }

    .responsive-table tbody td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 0.65rem 0.85rem;
        border-bottom: 1px solid #f1f5f9;
        white-space: normal;
        text-align: right;
    }

    .responsive-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--muted);
        font-size: 0.78rem;
        text-align: left;
        flex: 0 0 42%;
        max-width: 42%;
    }

    .responsive-table tbody td:last-child {
        border-bottom: none;
    }

    .responsive-table tbody td[data-label="Action"],
    .responsive-table tbody td[data-label="Punches"],
    .responsive-table tbody td[data-label="Notes"] {
        flex-direction: column;
        align-items: stretch;
        text-align: left;
    }

    .responsive-table tbody td[data-label="Action"]::before,
    .responsive-table tbody td[data-label="Punches"]::before,
    .responsive-table tbody td[data-label="Notes"]::before {
        max-width: 100%;
        flex: none;
        margin-bottom: 0.35rem;
    }

    .responsive-table .inline-form,
    .responsive-table .btn {
        width: 100%;
    }

    .responsive-table code {
        word-break: break-all;
        font-size: 0.78rem;
    }

    .data-table-compact td:last-child {
        min-width: 0;
    }
}
