:root {
    /* Color Palette - Premium Dark */
    --bg-main: #0f172a;
    --bg-sidebar: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --accent: #38bdf8;
    --accent-hover: #0ea5e9;
    --border: #334155;
    --card-bg: rgba(30, 41, 59, 0.7);
    --card-border: rgba(255, 255, 255, 0.1);

    /* Spacing & Radius */
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* Fonts */
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-main);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

/* Login & DB Screen Layouts */
.hidden-initially {
    display: none !important;
}

.hidden {
    display: none !important;
}

.login-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.login-card {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    padding: 2.5rem;
    border-radius: 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-card h2 {
    margin-bottom: 1.5rem;
    color: white;
}

.input-group {
    margin-bottom: 1rem;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: #94a3b8;
}

.input-group input,
.input-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.75rem;
    color: white;
    font-family: inherit;
}

.btn-full {
    width: 100%;
    margin-top: 1rem;
}

.db-status-bar {
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: #94a3b8;
}

.db-badge {
    background: rgba(56, 189, 248, 0.1);
    color: #38bdf8;
    padding: 0.2rem 0.5rem;
    border-radius: 0.4rem;
    font-weight: 500;
    word-break: break-all;
    white-space: normal;
    text-align: left;
}

/* App Layout */
.app-container {
    display: flex;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 320px;
    min-width: 320px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 10;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.collapsed {
    margin-left: -320px;
}

.sidebar-toggle {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

.sidebar-toggle:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

/* Floating variant for welcome screen */
.sidebar-toggle.floating {
    position: absolute;
    top: 24px;
    left: 24px;
    z-index: 50;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.25rem;
    color: white;
}

.brand-logo {
    max-width: 100%;
    height: auto;
    max-height: 50px;
    /* Adjust based on image aspect ratio */
    object-fit: contain;
}

.subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
    letter-spacing: 0.05em;
}

.search-container {
    padding: 16px;
}

.search-input-wrapper {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-muted);
}

input[type="text"] {
    width: 100%;
    background-color: #0f172a;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    padding: 10px 10px 10px 36px;
    color: white;
    font-family: var(--font-body);
    font-size: 0.875rem;
    transition: all 0.2s;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.results-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px;
}

.result-item {
    padding: 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 4px;
}

.result-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.result-item.active {
    background-color: var(--accent);
    color: white;
}

.result-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}

.result-item .fmi {
    font-weight: 600;
}

.anot-badge {
    font-size: 0.65rem;
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    padding: 2px 6px;
    border-radius: var(--radius-full);
    font-weight: 500;
}

.result-item.active .anot-badge {
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
}

.result-item .location {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.result-item.active .location {
    color: rgba(255, 255, 255, 0.8);
}

.sidebar-footer {
    padding: 12px;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

/* Empty State Sidebar */
.empty-state-sidebar {
    height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-muted);
    gap: 12px;
    padding: 20px;
}

/* Main Content */
.main-content {
    flex: 1;
    position: relative;
    background: radial-gradient(circle at top right, #1e293b 0%, #0f172a 40%);
    overflow: hidden;
}

/* Welcome Screen / Drag Drop */
.welcome-screen {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

.upload-zone {
    background: var(--card-bg);
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 64px;
    text-align: center;
    max-width: 500px;
    width: 90%;
    backdrop-filter: blur(10px);
    transition: all 0.3s;
}

.upload-zone.drag-active {
    border-color: var(--accent);
    background: rgba(56, 189, 248, 0.1);
}

.icon-circle {
    width: 80px;
    height: 80px;
    background: rgba(56, 189, 248, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    color: var(--accent);
}

.upload-zone h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.upload-zone p {
    color: var(--text-muted);
    margin-bottom: 32px;
}

.btn-primary {
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
}

/* Detail View */
.detail-view {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.detail-view.hidden {
    display: none;
}

.detail-header {
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 14px 40px;
    z-index: 10;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.fmi-title-group {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.fmi-title-group h1 {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
}

.badge {
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge.active {
    background-color: rgba(34, 197, 94, 0.2);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.badge.closed {
    background-color: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.label-muted {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.sub-info {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.location-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.location-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.separator {
    opacity: 0.3;
}

.loc-label {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

/* Content Area */
.scroll-content {
    flex: 1;
    overflow-y: auto;
    padding: 40px;
}

.content-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.grid-2-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

/* Glass Card */
.glass-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.02);
}

.card-header h3 {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-main);
}

.text-accent {
    color: var(--accent);
}

.card-body {
    padding: 24px;
}

.header-with-actions {
    justify-content: space-between;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-mini {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
    padding: 4px 12px;
    color: white;
    font-size: 0.8rem;
    width: 120px;
    font-family: var(--font-body);
    transition: all 0.2s;
}

.search-mini:focus {
    outline: none;
    border-color: var(--accent);
    background: rgba(0, 0, 0, 0.3);
    width: 160px;
}

/* Info List */
.info-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
    padding-bottom: 8px;
}

.info-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.info-row .label {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.info-row .value {
    font-weight: 500;
    text-align: right;
    max-width: 70%;
}

/* Owner Cards */
.owner-card {
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.owner-icon-box {
    width: 32px;
    height: 32px;
    background: rgba(56, 189, 248, 0.2);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
}

.owner-details {
    flex: 1;
}

.owner-name {
    font-weight: 600;
    display: block;
    margin-bottom: 4px;
}

.owner-doc {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: inline-block;
    padding: 2px 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

/* Linderos Box */
.linderos-box {
    font-family: var(--font-body);
    font-size: 0.9rem;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.8);
    transition: all 0.3s ease;
}

.linderos-box.collapsed {
    max-height: 100px;
    overflow: hidden;
    position: relative;
    mask-image: linear-gradient(to bottom, black 50%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 50%, transparent 100%);
}

.btn-text {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.85rem;
    margin-top: 12px;
    font-weight: 500;
}

.btn-text:hover {
    text-decoration: underline;
}

/* Chips / Tags */
.tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag {
    font-size: 0.8rem;
    padding: 6px 12px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
}

.tag.matriz {
    background: rgba(56, 189, 248, 0.1);
    border-color: rgba(56, 189, 248, 0.3);
    color: var(--accent);
}

.tag.linked {
    border: 1px solid #4ade80;
    /* Green border */
    color: #4ade80;
    cursor: pointer;
    background: rgba(74, 222, 128, 0.1);
    transition: all 0.2s;
}

.tag.linked:hover {
    background: rgba(74, 222, 128, 0.2);
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.2);
}

/* Timeline */
.timeline-wrapper {
    max-height: 500px;
    overflow-y: auto;
    padding-right: 12px;
}

.timeline {
    position: relative;
    padding-left: 20px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 4px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: rgba(255, 255, 255, 0.1);
}

.timeline-item {
    position: relative;
    margin-bottom: 24px;
    padding-left: 20px;
}

.timeline-dot {
    position: absolute;
    left: -20px;
    top: 5px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--bg-sidebar);
    border: 2px solid var(--text-muted);
}

.timeline-item.important .timeline-dot {
    border-color: var(--accent);
    background: var(--accent);
}

/* Timeline Header & Body */
.timeline-header-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.anotacion-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.02em;
}

.timeline-date-badge {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    padding: 2px 8px;
    border-radius: 4px;
}

.timeline-specs {
    margin-bottom: 12px;
}

.spec-item {
    font-weight: 600;
    color: var(--text-main);
    font-size: 0.95rem;
    margin-bottom: 4px;
    display: block;
}

.timeline-body-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.detail-row {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.timeline-actors {
    background: rgba(0, 0, 0, 0.2);
    padding: 12px;
    border-radius: var(--radius-md);
    margin-top: 8px;
}

.actors-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 4px;
}

.actor-row {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 2px;
    padding-left: 8px;
    border-left: 2px solid var(--accent);
}

/* Scrollbar Styles */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Timeline Dashboard (Nuevo) */
.timeline-interactive-card .card-body {
    padding: 0;
}

.timeline-dashboard {
    display: flex;
    min-height: 600px;
    height: 75vh;
    border-top: 1px solid var(--border);
    transition: all 0.3s ease;
}

/* Fullscreen Modifiers */
.timeline-interactive-card.is-fullscreen,
.expanded-height.is-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    margin: 0;
    border-radius: 0;
    display: flex;
    flex-direction: column;
}

.timeline-interactive-card.is-fullscreen .card-header,
.expanded-height.is-fullscreen .card-header {
    padding: 8px 24px;
}

.timeline-interactive-card.is-fullscreen .card-header h3,
.expanded-height.is-fullscreen .card-header h3 {
    font-size: 0.95rem;
}

.timeline-interactive-card.is-fullscreen .timeline-fullscreen-btn,
.expanded-height.is-fullscreen .timeline-fullscreen-btn {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.timeline-interactive-card.is-fullscreen .timeline-dashboard {
    height: 100%;
    flex: 1;
}

.timeline-interactive-card.is-fullscreen .timeline-detail-panel {
    max-height: 35vh;
}

.expanded-height.is-fullscreen .timeline-wrapper {
    height: 100%;
    flex: 1;
    max-height: none;
    /* Override the default max-height */
}

.timeline-fullscreen-btn {
    margin-left: auto;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.timeline-fullscreen-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.timeline-summary {
    width: 300px;
    min-width: 300px;
    border-right: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.15);
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.timeline-summary-category {
    margin-bottom: 16px;
}

.timeline-summary-category h4 {
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
}

.summary-item-container {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.2s ease;
}

.summary-item-container:last-child {
    border-bottom: none;
}

.summary-item {
    display: flex;
    align-items: center;
    font-size: 0.75rem;
    gap: 10px;
    padding: 6px 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 4px;
}

.summary-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.toggle-all-conceptos-btn {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 8px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
}

.toggle-all-conceptos-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border-color: rgba(255, 255, 255, 0.2);
}

.toggle-all-conceptos-btn i {
    width: 16px;
    height: 16px;
}

.summary-item-concepto {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0 8px 8px 34px;
    line-height: 1.4;
    transition: all 0.3s ease;
}

.summary-item-concepto.collapsed {
    display: none;
}

.summary-item-concepto p {
    margin: 0;
    padding: 6px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    border-left: 2px solid var(--accent);
}

.summary-item-icon {
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.summary-item-icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
    stroke-width: 0.5px;
    transform: scale(1.1);
}

.summary-item-text {
    flex: 1;
    color: var(--text-main);
}

.summary-item-count {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
}

.timeline-right-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* previene desbordamiento flex */
}

.timeline-chart-container {
    flex: 6;
    /* Toma la mayor parte del espacio */
    border-bottom: 1px solid var(--border);
    position: relative;
    padding: 10px;
}

.timeline-detail-panel {
    flex: 4;
    /* Toma parte inferior */
    background: rgba(15, 23, 42, 0.5);
    padding: 20px;
    overflow-y: auto;
}

.timeline-detail-empty {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9rem;
}

.chart-detail-card {
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-md);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 20px;
}

.chart-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 12px;
}

.chart-detail-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
}

.chart-detail-date {
    font-family: var(--font-mono);
    color: var(--text-muted);
    font-size: 0.85rem;
}

.chart-detail-spec {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 12px;
}

.chart-detail-body {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.chart-detail-actors {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: var(--radius-md);
    border-left: 2px solid var(--accent);
}