:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --border: #dce2ea;
    --border-strong: #c2cbd6;
    --text: #1e293b;
    --text-muted: #64748b;
    --primary: #1d4ed8;
    --primary-hover: #1e40af;
    --excel: #15803d;
    --excel-hover: #166534;
    --danger: #dc2626;
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 10px 25px rgba(15, 23, 42, 0.14);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 13.5px;
    line-height: 1.4;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.hidden {
    display: none !important;
}

/* Topbar */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.brand-logo {
    height: 30px;
    width: auto;
    object-fit: contain;
}

.brand-divider {
    width: 1px;
    height: 22px;
    background: var(--border);
}

.app-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
    white-space: nowrap;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Container */
.container {
    max-width: 1520px;
    margin: 0 auto;
    padding: 16px 20px 28px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 13px;
    border-radius: 6px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    white-space: nowrap;
}

.btn:hover {
    background: #f8fafc;
}

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

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

.btn-excel {
    background: #f0fdf4;
    border-color: #86efac;
    color: var(--excel);
}

.btn-excel:hover {
    background: #dcfce7;
    border-color: #4ade80;
    color: var(--excel-hover);
}

.btn-icon-only {
    padding: 5px 7px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon-only:hover {
    background: #e2e8f0;
    color: var(--text);
}

.btn-icon-only.danger:hover {
    background: #fee2e2;
    color: var(--danger);
}

.btn-icon-only.save {
    background: #dcfce7;
    color: #166534;
    border-color: #86efac;
}

.btn-icon-only.save:hover {
    background: #bbf7d0;
}

/* Inputs */
.input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text);
    background: #ffffff;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.14);
}

.input-sm {
    padding: 5px 9px;
    font-size: 12.5px;
}

/* Quick Entry Card */
.entry-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px 14px;
    box-shadow: var(--shadow-sm);
}

.entry-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.entry-title {
    font-weight: 700;
    font-size: 13.5px;
    color: #0f172a;
}

.entry-hint {
    font-size: 12px;
    color: var(--text-muted);
}

.entry-grid {
    display: grid;
    grid-template-columns: 1.5fr 1.1fr 1.8fr 132px 132px 130px 1.4fr auto;
    gap: 8px;
    align-items: end;
}

.field-col label {
    display: block;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}

@media (max-width: 1200px) {
    .entry-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
    .col-submit {
        grid-column: span 1;
    }
}

@media (max-width: 700px) {
    .entry-grid {
        grid-template-columns: 1fr;
    }
    .topbar {
        flex-wrap: wrap;
    }
}

/* Searchable Combobox */
.combo-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.combo-input {
    padding-right: 42px;
}

.combo-clear,
.combo-toggle {
    position: absolute;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 13px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
}

.combo-clear {
    right: 22px;
    font-size: 15px;
}

.combo-toggle {
    right: 6px;
}

.combo-clear:hover,
.combo-toggle:hover {
    color: var(--text);
}

.combo-dropdown {
    position: fixed;
    z-index: 90;
    background: #ffffff;
    border: 1px solid var(--border-strong);
    border-radius: 7px;
    box-shadow: var(--shadow-md);
    max-height: 260px;
    overflow-y: auto;
    padding: 4px;
}

.combo-option {
    display: block;
    padding: 7px 10px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.combo-option:hover,
.combo-option.active {
    background: #eff6ff;
    color: #1e40af;
}

.combo-option.selected {
    font-weight: 600;
}

.combo-option mark {
    background: #fef08a;
    color: inherit;
    padding: 0;
    border-radius: 2px;
    font-weight: 700;
}

.combo-empty {
    padding: 8px 10px;
    font-size: 12.5px;
    color: var(--text-muted);
}

.combo-add-inline {
    margin-top: 2px;
    border-top: 1px solid var(--border);
    padding: 7px 10px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
    border-radius: 5px;
}

.combo-add-inline:hover {
    background: #eff6ff;
}

/* Toolbar */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    justify-content: space-between;
}

.toolbar-search {
    position: relative;
    flex: 1 1 280px;
    max-width: 420px;
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    padding-left: 32px;
}

.filter-pills {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.pill-btn {
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    border-radius: 999px;
    padding: 5px 11px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s;
}

.pill-btn:hover {
    background: #f8fafc;
}

.pill-btn.active {
    background: #0f172a;
    border-color: #0f172a;
    color: #ffffff;
}

.pill-btn.pill-alert.active {
    background: #b91c1c;
    border-color: #b91c1c;
}

.pill-count {
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 999px;
    background: rgba(100, 116, 139, 0.14);
}

.pill-btn.active .pill-count {
    background: rgba(255, 255, 255, 0.22);
}

.toolbar-resp {
    min-width: 195px;
}

/* Table Card */
.table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.table-scroll {
    overflow-x: auto;
}

.sheet-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

.sheet-table thead th {
    background: #f8fafc;
    border-bottom: 2px solid var(--border);
    border-right: 1px solid #edf1f6;
    padding: 9px 10px;
    text-align: left;
    font-size: 12px;
    font-weight: 700;
    color: #334155;
    white-space: nowrap;
    user-select: none;
}

.sheet-table thead th.sortable {
    cursor: pointer;
}

.sheet-table thead th.sortable:hover {
    background: #eef2f7;
}

.sort-ind {
    font-size: 10px;
    color: var(--primary);
    margin-left: 3px;
}

.sheet-table tbody td {
    border-bottom: 1px solid #e9eef4;
    border-right: 1px solid #f1f5f9;
    padding: 7px 10px;
    vertical-align: middle;
}

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

/* Row Urgency / State Highlights */
.sheet-table tbody tr.row-overdue {
    background-color: #fee2e2;
}

.sheet-table tbody tr.row-overdue:hover {
    background-color: #fecaca;
}

.sheet-table tbody tr.row-overdue td:first-child {
    box-shadow: inset 4px 0 0 #dc2626;
}

.sheet-table tbody tr.row-overdue .td-date:nth-child(5) .date-main {
    color: #991b1b;
    font-weight: 700;
}

.sheet-table tbody tr.row-soon {
    background-color: #fef9c3;
}

.sheet-table tbody tr.row-soon:hover {
    background-color: #fef08a;
}

.sheet-table tbody tr.row-soon td:first-child {
    box-shadow: inset 4px 0 0 #eab308;
}

.sheet-table tbody tr.row-soon .td-date:nth-child(5) .date-main {
    color: #854d0e;
    font-weight: 700;
}

.sheet-table tbody tr.row-done {
    background-color: #f0fdf4;
}

.sheet-table tbody tr.row-done:hover {
    background-color: #dcfce7;
}

.sheet-table tbody tr.row-done td:first-child {
    box-shadow: inset 4px 0 0 #16a34a;
}

.sheet-table tbody tr.row-editing {
    background-color: #eff6ff !important;
}

.th-date,
.td-date {
    width: 126px;
    white-space: nowrap;
}

.th-estado,
.td-estado {
    width: 138px;
}

.th-actions,
.td-actions {
    width: 86px;
    text-align: center;
    white-space: nowrap;
}

.cell-razon {
    font-weight: 600;
    color: #0f172a;
    min-width: 170px;
}

.cell-resp {
    min-width: 130px;
}

.cell-detalle {
    min-width: 220px;
}

.cell-obs {
    min-width: 180px;
    color: #475569;
}

/* Date urgency badge */
.date-main {
    display: block;
    font-variant-numeric: tabular-nums;
}

.due-tag {
    display: inline-block;
    margin-top: 2px;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 4px;
}

.due-tag.overdue {
    background: #fee2e2;
    color: #b91c1c;
}

.due-tag.soon {
    background: #fef3c7;
    color: #b45309;
}

/* Inline Status Pill Select */
.status-select {
    width: 100%;
    padding: 5px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    border: 1px solid transparent;
    outline: none;
    transition: filter 0.15s;
}

.status-select:hover {
    filter: brightness(0.96);
}

.status-Pendiente {
    background: #f1f5f9;
    color: #334155;
    border-color: #cbd5e1;
}

.status-En-proceso {
    background: #dbeafe;
    color: #1e40af;
    border-color: #93c5fd;
}

.status-Completado {
    background: #dcfce7;
    color: #166534;
    border-color: #86efac;
}

.status-Vencido {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fca5a5;
}

.status-Anulado {
    background: #e2e8f0;
    color: #475569;
    border-color: #cbd5e1;
}

.empty-cell {
    text-align: center;
    padding: 36px 16px !important;
    color: var(--text-muted);
}

.table-footer {
    padding: 9px 14px;
    background: #f8fafc;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 12px;
    color: var(--text-muted);
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-panel {
    background: var(--surface);
    border-radius: 10px;
    width: 100%;
    max-width: 560px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

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

.modal-header h2 {
    margin: 0;
    font-size: 15.5px;
    font-weight: 700;
}

.btn-close {
    border: none;
    background: transparent;
    font-size: 22px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 6px;
}

.btn-close:hover {
    color: var(--text);
}

.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
    padding: 0 14px;
    gap: 6px;
}

.tab-btn {
    border: none;
    background: transparent;
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-count {
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 999px;
    background: #e2e8f0;
    color: #334155;
}

.modal-body {
    padding: 14px 18px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: hidden;
}

.catalog-add-row {
    display: flex;
    gap: 8px;
}

.catalog-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    max-height: 46vh;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.catalog-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 7px 10px;
    border-bottom: 1px solid #f1f5f9;
}

.catalog-item:last-child {
    border-bottom: none;
}

.catalog-item:hover {
    background: #f8fafc;
}

.catalog-item-name {
    flex: 1;
    min-width: 0;
    word-break: break-word;
}

.catalog-item-actions {
    display: flex;
    gap: 4px;
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: 18px;
    right: 18px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: #0f172a;
    color: #ffffff;
    padding: 9px 14px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-md);
}

.toast.error {
    background: #b91c1c;
}

.toast.success {
    background: #15803d;
}
