:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --blue: #2563eb;
    --blue-dark: #1d4ed8;
    --green: #16a34a;
    --green-dark: #15803d;
    --red: #dc2626;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.05);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

/* ── Header ── */
header {
    background: linear-gradient(135deg, #1e3a8a 0%, #4f46e5 100%);
    color: white;
    text-align: center;
    padding: 48px 24px 32px;
}

header h1 {
    font-size: clamp(2rem, 5vw, 2.75rem);
    font-weight: 700;
    letter-spacing: -0.5px;
}

.subtitle {
    margin-top: 10px;
    font-size: 1.05rem;
    opacity: 0.8;
}

/* ── Main ── */
main {
    max-width: 780px;
    margin: 0 auto;
    padding: 36px 20px 60px;
}

/* ── Upload area ── */
.upload-area {
    background: var(--surface);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 52px 32px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    position: relative;
}

.upload-area:hover,
.upload-area.drag-over {
    border-color: var(--blue);
    background: #eff6ff;
}

.upload-area.drag-over { border-style: solid; }

.upload-icon {
    width: 48px;
    height: 48px;
    color: var(--text-muted);
    margin-bottom: 16px;
    transition: color 0.2s;
}

.upload-area:hover .upload-icon,
.upload-area.drag-over .upload-icon { color: var(--blue); }

.upload-text { font-size: 1rem; color: var(--text); margin-bottom: 6px; }
.upload-hint { font-size: 0.875rem; color: var(--text-muted); }

#upload-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.97); }
.btn-success { background: var(--green); color: white; }
.btn-success:hover { background: var(--green-dark); }

/* ── Status ── */
.status {
    margin-top: 20px;
    padding: 14px 18px;
    border-radius: var(--radius);
    font-size: 0.925rem;
    display: flex;
    align-items: center;
    gap: 12px;
}

.status.loading {
    background: #eff6ff;
    color: var(--blue);
    border: 1px solid #bfdbfe;
}

.status.error {
    background: #fef2f2;
    color: var(--red);
    border: 1px solid #fecaca;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid #bfdbfe;
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

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

.hidden { display: none !important; }

/* ── Preview section ── */
#preview-section { margin-top: 36px; }

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.preview-header h2 { font-size: 1.25rem; font-weight: 600; }

.event-count {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 8px;
}

/* ── Course legend ── */
.cal-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text);
    background: var(--surface);
    padding: 4px 10px 4px 8px;
    border-radius: 20px;
    box-shadow: var(--shadow);
}

.legend-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ── Calendar ── */
.cal-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.calendar {
    background: var(--surface);
    min-width: 480px;
    border-radius: var(--radius);
    overflow: hidden;
}

.cal-header {
    display: grid;
    grid-template-columns: 52px repeat(5, 1fr);
    border-bottom: 2px solid var(--border);
    background: #f8fafc;
}

.cal-header-gutter { border-right: 1px solid var(--border); }

.cal-day-label {
    padding: 10px 0;
    text-align: center;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.cal-body {
    display: grid;
    grid-template-columns: 52px repeat(5, 1fr);
    position: relative;
}

.cal-time-col {
    position: relative;
    border-right: 1px solid var(--border);
}

.cal-time-label {
    position: absolute;
    right: 6px;
    transform: translateY(-50%);
    font-size: 0.62rem;
    color: var(--text-muted);
    white-space: nowrap;
    line-height: 1;
    user-select: none;
}

.cal-day-col {
    position: relative;
    border-left: 1px solid var(--border);
}

.cal-hour-line {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px solid var(--border);
    pointer-events: none;
}

.cal-half-line {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px dashed #eef2f7;
    pointer-events: none;
}

/* ── Calendar events ── */
.cal-event {
    position: absolute;
    left: 3px;
    right: 3px;
    border-radius: 5px;
    padding: 3px 5px;
    overflow: hidden;
    cursor: default;
    transition: filter 0.15s;
    border-left-width: 3px;
    border-left-style: solid;
}

.cal-event:hover { filter: brightness(0.94); }

.cal-event-course {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cal-event-type {
    display: block;
    font-size: 0.62rem;
    opacity: 0.75;
    line-height: 1.2;
}

.cal-event-time {
    display: block;
    font-size: 0.6rem;
    opacity: 0.6;
    margin-top: 1px;
}

/* ── Exams / one-time events ── */
.onetime-section { margin-top: 4px; }

.onetime-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 12px;
}

.onetime-list { display: flex; flex-direction: column; gap: 8px; }

.onetime-item {
    background: var(--surface);
    border-radius: 8px;
    padding: 12px 16px;
    box-shadow: var(--shadow);
    border-left-width: 3px;
    border-left-style: solid;
}

.onetime-name {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 3px;
}

.onetime-details { font-size: 0.8rem; color: var(--text-muted); }

/* ── Responsive ── */
@media (max-width: 540px) {
    header { padding: 36px 16px 24px; }
    main { padding: 24px 14px 48px; }
    .upload-area { padding: 40px 20px; }
    .preview-header { flex-direction: column; align-items: flex-start; gap: 12px; }
}
