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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    min-height: 100vh;
    color: #e0e0e0;
    line-height: 1.5;
}

/* ── Header ─────────────────────────────────────────────── */
.editor-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.main-title {
    font-size: 2rem;
    font-weight: bold;
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4, #feca57);
    background-size: 400% 400%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientShift 3s ease-in-out infinite;
}

.header-controls {
    display: flex;
    gap: 0.75rem;
}

.nav-btn, .save-btn, .add-btn, .cancel-btn, .delete-btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 10px;
    font-weight: bold;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.nav-btn {
    background: linear-gradient(45deg, #45b7d1, #96ceb4);
    color: white;
}

.save-btn {
    background: linear-gradient(45deg, #4ecdc4, #45b7d1);
    color: white;
}

.add-btn {
    background: linear-gradient(45deg, #4ecdc4, #45b7d1);
    color: white;
}

.cancel-btn {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.25);
}

.delete-btn {
    background: linear-gradient(45deg, #ff6b6b, #ff5252);
    color: white;
}

.nav-btn:hover, .save-btn:hover, .add-btn:hover, .cancel-btn:hover, .delete-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* ── Category tabs ──────────────────────────────────────── */
.category-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.cat-tab {
    padding: 0.45rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.cat-tab:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.cat-tab.active {
    background: linear-gradient(45deg, #4ecdc4, #45b7d1);
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(78, 205, 196, 0.3);
}

/* ── Toolbar ────────────────────────────────────────────── */
.toolbar {
    margin-bottom: 1rem;
}

.search-input {
    width: 100%;
    max-width: 400px;
    padding: 0.6rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 0.9rem;
}

/* Force dark background on native dropdown options */
select,
.add-row-grid select,
.cell-input[type="select"],
select.cell-input {
    background-color: #1a1a2e;
    color: #e0e0e0;
}

select option {
    background-color: #1a1a2e;
    color: #e0e0e0;
    padding: 0.4rem;
}

select option:checked {
    background-color: #0f3460;
    color: #fff;
}

.search-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.search-input:focus {
    outline: none;
    border-color: #4ecdc4;
    box-shadow: 0 0 10px rgba(78, 205, 196, 0.25);
}

/* ── Spreadsheet table ──────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.25);
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

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

thead {
    position: sticky;
    top: 0;
    z-index: 5;
}

th {
    background: rgba(255, 255, 255, 0.08);
    padding: 0.7rem 0.8rem;
    text-align: left;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.7);
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
    white-space: nowrap;
    user-select: none;
}

th[data-sort] {
    cursor: pointer;
    position: relative;
    padding-right: 1.5rem;
}

th[data-sort]:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

th[data-sort]::after {
    content: '⇅';
    position: absolute;
    right: 0.5rem;
    opacity: 0.3;
    font-size: 0.7rem;
}

th.sort-asc::after {
    content: '▲';
    opacity: 0.9;
    color: #4ecdc4;
}

th.sort-desc::after {
    content: '▼';
    opacity: 0.9;
    color: #4ecdc4;
}

td {
    padding: 0.55rem 0.8rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: background 0.15s ease;
}

/* Editable cell hover */
td[data-field] {
    cursor: text;
}

td[data-field]:hover {
    background: rgba(78, 205, 196, 0.08);
    outline: 1px solid rgba(78, 205, 196, 0.2);
    outline-offset: -1px;
}

/* Editing state */
td.editing {
    background: rgba(78, 205, 196, 0.12);
    padding: 0.25rem 0.35rem;
    outline: 2px solid #4ecdc4;
    outline-offset: -2px;
}

.cell-input {
    width: 100%;
    padding: 0.35rem 0.5rem;
    border: none;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
}

textarea.cell-input {
    resize: vertical;
    min-height: 50px;
}

select.cell-input {
    cursor: pointer;
    background-color: #1a1a2e;
    color: #e0e0e0;
}

select.cell-input option {
    background-color: #1a1a2e;
    color: #e0e0e0;
}

/* Row hover */
tbody tr:hover {
    background: rgba(255, 255, 255, 0.04);
}

/* Row striping */
tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

tbody tr:nth-child(even):hover {
    background: rgba(255, 255, 255, 0.06);
}

/* Status cells */
.status-cell {
    font-weight: 700;
    font-size: 0.75rem;
    text-align: center;
    border-radius: 0;
}

.status-overdue {
    color: #ff6b6b;
}

.status-soon {
    color: #feca57;
}

.status-month {
    color: #4ecdc4;
}

.status-ok {
    color: rgba(255, 255, 255, 0.5);
}

/* Actions */
.actions-cell {
    text-align: center;
    width: 50px;
}

.row-delete-btn {
    background: none;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    opacity: 0.4;
    transition: opacity 0.2s ease;
    padding: 0.2rem;
}

.row-delete-btn:hover {
    opacity: 1;
}

.empty-msg {
    text-align: center;
    padding: 2rem;
    color: rgba(255, 255, 255, 0.4);
    font-style: italic;
}

/* ── Add-row section ────────────────────────────────────── */
.add-row-section {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 2rem;
}

.add-row-section h3 {
    margin-bottom: 0.75rem;
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.8);
}

.add-row-grid {
    display: grid;
    grid-template-columns: 1.5fr 2fr 1fr 1fr 0.8fr 0.8fr auto;
    gap: 0.5rem;
    align-items: center;
}

.add-row-grid input,
.add-row-grid select {
    padding: 0.55rem 0.7rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 0.85rem;
}

.add-row-grid input::placeholder {
    color: rgba(255, 255, 255, 0.35);
}

.add-row-grid input:focus,
.add-row-grid select:focus {
    outline: none;
    border-color: #4ecdc4;
    box-shadow: 0 0 8px rgba(78, 205, 196, 0.2);
}

/* ── Modal ──────────────────────────────────────────────── */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 16px;
    padding: 1.5rem;
    width: 90%;
    max-width: 450px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.modal-header h3 {
    font-size: 1.2rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.8rem;
    color: #ffffff;
    cursor: pointer;
    transition: color 0.2s ease;
    line-height: 1;
}

.close-btn:hover {
    color: #ff6b6b;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.event-preview {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 0.8rem;
    margin: 0.75rem 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.85rem;
    line-height: 1.6;
}

/* ── Status toast ───────────────────────────────────────── */
.status-message {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    padding: 0.7rem 1.2rem;
    border-radius: 10px;
    font-weight: bold;
    font-size: 0.85rem;
    z-index: 1001;
    animation: slideInRight 0.3s ease-out;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.status-message.success {
    background: linear-gradient(45deg, #4ecdc4, #45b7d1);
    color: white;
}

.status-message.error {
    background: linear-gradient(45deg, #ff6b6b, #ff5252);
    color: white;
}

/* ── Animations ─────────────────────────────────────────── */
@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(60px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 1024px) {
    .add-row-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 768px) {
    .editor-header {
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
    }

    .main-title {
        font-size: 1.5rem;
    }

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

    .category-tabs {
        gap: 0.3rem;
    }

    .cat-tab {
        font-size: 0.7rem;
        padding: 0.35rem 0.7rem;
    }

    td {
        font-size: 0.8rem;
        padding: 0.45rem 0.5rem;
    }

    th {
        font-size: 0.7rem;
        padding: 0.5rem;
    }
}
