:root {
    --ink: #1a1a1a;
    --paper: #f8f6f1;
    --surface: #ffffff;
    --accent: #c41e3a;
    --muted: #8a8680;
    --divider: #d4d0c8;
    --divider-light: #e8e6e1;
    --annual: #1e40af;
    --half-year: #047857;
    --quarterly: #c2410c;
    --trading: #6b7280;
}

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

body {
    font-family: 'Montserrat', sans-serif;
    background: var(--paper);
    color: var(--ink);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 48px 64px;
}

/* Header - Editorial masthead */
header {
    border-bottom: 3px solid var(--ink);
    padding-bottom: 24px;
    margin-bottom: 48px;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: end;
}

.masthead {
    font-family: 'Prata', serif;
    font-size: 3rem;
    font-weight: 400;
    letter-spacing: -0.01em;
    line-height: 1;
}

.edition {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--muted);
    margin-bottom: 8px;
    font-weight: 500;
}

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

.current-date {
    font-family: 'Prata', serif;
    font-size: 1.25rem;
}

.last-updated-header {
    font-size: 0.7rem;
    color: var(--muted);
    margin-top: 4px;
}

/* Stats Row */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: var(--ink);
    margin-bottom: 48px;
}

.stat {
    background: var(--paper);
    padding: 24px 20px;
    text-align: center;
}

.stat-number {
    font-family: 'Prata', serif;
    font-size: 2.75rem;
    line-height: 1;
    color: var(--ink);
}

.stat-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--muted);
    margin-top: 8px;
    font-weight: 600;
}

/* Controls */
.controls {
    display: flex;
    gap: 24px;
    margin-bottom: 32px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-group label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

select {
    padding: 10px 32px 10px 14px;
    border: 1px solid var(--ink);
    background: var(--surface);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.8rem;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%231a1a1a' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

select:hover {
    background-color: var(--paper);
}

.time-buttons {
    display: flex;
    border: 1px solid var(--ink);
}

.time-btn {
    padding: 10px 20px;
    border: none;
    border-right: 1px solid var(--ink);
    background: var(--surface);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: all 0.15s ease;
}

.time-btn:last-child {
    border-right: none;
}

.time-btn:hover {
    background: var(--paper);
}

.time-btn.active {
    background: var(--ink);
    color: var(--surface);
}

/* Section styling */
.section-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--accent);
    margin-bottom: 12px;
    font-weight: 700;
}

/* Timeline Section */
.timeline-section {
    margin-bottom: 48px;
}

.timeline-box {
    border: 1px solid var(--ink);
    background: var(--surface);
    overflow: hidden;
}

.timeline-container {
    padding: 20px 24px;
    min-height: 300px;
}

#timeline {
    min-height: 280px;
    flex: 1;
}

/* Timeline with sidebar layout */
.timeline-with-sidebar {
    display: flex;
    gap: 0;
}

.timeline-main {
    flex: 1;
    min-width: 0;
}

/* Date Sidebar */
.date-sidebar {
    width: 220px;
    border-left: 1px solid var(--divider);
    background: var(--paper);
    display: flex;
    flex-direction: column;
}

.date-sidebar-header {
    padding: 16px 18px;
    border-bottom: 1px solid var(--divider);
}

.date-sidebar-date {
    font-family: 'Prata', serif;
    font-size: 1rem;
    margin-bottom: 4px;
}

.date-sidebar-count {
    font-size: 0.7rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.date-sidebar-events {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

.date-sidebar-event {
    padding: 10px 18px;
    border-bottom: 1px solid var(--divider-light);
}

.date-sidebar-event:last-child {
    border-bottom: none;
}

.date-sidebar-company {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 3px;
}

.date-sidebar-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.date-sidebar-type {
    font-size: 0.7rem;
    color: var(--muted);
    margin-left: 16px;
}

.date-sidebar-empty {
    padding: 24px 18px;
    color: var(--muted);
    font-size: 0.85rem;
    text-align: center;
}

.date-sidebar-hint {
    padding: 16px 18px;
    font-size: 0.7rem;
    color: var(--muted);
    text-align: center;
    border-top: 1px solid var(--divider-light);
}

/* Legend */
.legend {
    display: flex;
    gap: 32px;
    padding: 14px 24px;
    border-top: 1px solid var(--divider);
    background: var(--paper);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.75rem;
    color: var(--muted);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* Table Section */
.table-section {
    border: 1px solid var(--ink);
    background: var(--surface);
}

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

.table-title {
    font-family: 'Prata', serif;
    font-size: 1.25rem;
}

.table-meta {
    font-size: 0.7rem;
    color: var(--muted);
    margin-left: 16px;
    font-weight: 400;
}

.table-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.action-btn {
    padding: 10px 20px;
    border: 1px solid var(--ink);
    background: var(--surface);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: all 0.15s ease;
}

.action-btn:hover:not(:disabled) {
    background: var(--paper);
}

.action-btn.primary {
    background: var(--ink);
    color: var(--surface);
}

.action-btn.primary:hover:not(:disabled) {
    background: #333;
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.action-progress {
    font-size: 0.7rem;
    color: var(--muted);
    margin-left: 8px;
}

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

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 14px 20px;
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--muted);
    font-weight: 700;
    border-bottom: 1px solid var(--divider);
    background: #faf9f6;
}

th.sortable {
    cursor: pointer;
    user-select: none;
}

th.sortable:hover {
    color: var(--ink);
    background: var(--divider-light);
}

th .sort-icon {
    margin-left: 6px;
    opacity: 0.3;
}

th.sorted-asc .sort-icon,
th.sorted-desc .sort-icon {
    opacity: 1;
}

td {
    padding: 16px 20px;
    border-bottom: 1px solid var(--divider-light);
    font-size: 0.85rem;
}

tr:hover {
    background: #fdfcfa;
}

.company-cell {
    display: flex;
    align-items: center;
    gap: 8px;
}

.company-name {
    font-weight: 600;
}

.no-calendar-icon {
    color: #d97706;
    font-size: 0.8rem;
    cursor: help;
}

.ticker {
    color: var(--muted);
    font-size: 0.7rem;
    margin-left: 8px;
    font-weight: 500;
}

.index-tag {
    display: inline-block;
    padding: 3px 8px;
    background: var(--ink);
    color: var(--surface);
    font-size: 0.55rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    margin-left: 10px;
}

/* URL Cell */
.url-cell {
    min-width: 180px;
    max-width: 280px;
}

.url-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
}

.url-status {
    width: 8px !important;
    height: 8px !important;
    min-width: 8px;
    max-width: 8px;
    min-height: 8px;
    max-height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
}

.url-status.ok { background: var(--half-year); }
.url-status.error { background: var(--accent); }
.url-status.unknown { background: var(--divider); }
.url-status.testing {
    background: #fbbf24;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.url-input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--divider);
    background: var(--surface);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.7rem;
}

.url-input:focus {
    outline: none;
    border-color: var(--ink);
}

.url-input.saving {
    background: var(--paper);
    color: var(--muted);
}

.url-open-link {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.8rem;
    opacity: 0.6;
    transition: opacity 0.15s;
}

.url-open-link:hover {
    opacity: 1;
    color: var(--ink);
}

.url-open-link.hidden {
    display: none;
}

.url-fetch-btn {
    padding: 4px 8px;
    border: 1px solid var(--divider);
    background: var(--surface);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    cursor: pointer;
    color: var(--muted);
    transition: all 0.15s;
}

.url-fetch-btn:hover:not(:disabled) {
    border-color: var(--ink);
    color: var(--ink);
}

.url-fetch-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.url-fetch-btn.fetching {
    color: var(--quarterly);
}

.url-fetch-btn.hidden {
    display: none;
}

.last-fetched {
    font-size: 0.6rem;
    color: var(--muted);
    margin-top: 4px;
}

/* Date cells */
.date-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.date-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.date-indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.date-indicator.annual { background: var(--annual); }
.date-indicator.half_year { background: var(--half-year); }
.date-indicator.quarterly { background: var(--quarterly); }
.date-indicator.trading_update { background: var(--trading); }

.date-value {
    font-weight: 500;
}

.period-label {
    font-size: 0.65rem;
    color: var(--muted);
    margin-left: 16px;
}

.empty-cell {
    color: var(--divider);
}

/* Tooltip */
.tooltip {
    position: absolute;
    background: var(--ink);
    color: var(--surface);
    padding: 14px 18px;
    font-size: 0.8rem;
    pointer-events: none;
    z-index: 1000;
    max-width: 280px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.tooltip-title {
    font-weight: 600;
    margin-bottom: 4px;
}

.tooltip-date {
    color: #a0a0a0;
    margin-bottom: 8px;
    font-size: 0.75rem;
}

.tooltip-details {
    font-size: 0.7rem;
}

.tooltip-detail {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--divider);
    border-top-color: var(--ink);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

.spinner.light {
    border-color: rgba(255,255,255,0.3);
    border-top-color: white;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Loading/Error states */
.loading, .error-message {
    text-align: center;
    padding: 48px;
    color: var(--muted);
    font-size: 0.85rem;
}

.error-message {
    color: var(--accent);
}

/* Responsive */
@media (max-width: 1024px) {
    .container {
        padding: 32px;
    }

    .masthead {
        font-size: 2.25rem;
    }

    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .container {
        padding: 20px;
    }

    header {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .date-display {
        text-align: left;
    }

    .stats-row {
        grid-template-columns: 1fr;
    }

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

    .legend {
        flex-wrap: wrap;
        gap: 16px;
    }

    .table-header {
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
    }
}
