/* ==========================================================================
   Sophicly Study Calendar v2.4.0
   Weekly schedule planner grid.
   ========================================================================== */

.sccal-widget {
    --sccal-font: 'Proxima Soft', system-ui, -apple-system, sans-serif;
    --sccal-text: #f0f0f2;
    --sccal-text-muted: rgba(255,255,255,0.55);
    --sccal-bg: #1C1D1F;
    --sccal-card-bg: #2a2b2e;
    --sccal-card-border: rgba(255,255,255,0.08);
    --sccal-success: #1CD991;
    --sccal-error: #E74C3C;
    --sccal-accent: #51dacf;
    --sccal-purple: #5333ed;
    --sccal-cell-hover: rgba(83,51,237,0.08);

    font-family: var(--sccal-font); max-width: 820px; margin: 24px auto;
    color: var(--sccal-text); -webkit-font-smoothing: antialiased;
    animation: sccalFadeIn 0.4s ease both;
}
.sccal-widget *, .sccal-widget *::before, .sccal-widget *::after { box-sizing: border-box; }
@keyframes sccalFadeIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }

.sccal-title { font-size: 20px; font-weight: 600; margin-bottom: 16px; text-align: center; }

/* ── Toolbar (duration selector + stats) ──────────────────────────────── */

.sccal-toolbar {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 12px; flex-wrap: wrap; gap: 12px;
}
.sccal-duration-selector { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sccal-toolbar-label {
    font-size: 12px; font-weight: 600; color: var(--sccal-text-muted);
    text-transform: uppercase; letter-spacing: 0.05em;
}
.sccal-dur-btn {
    padding: 5px 12px; border-radius: 20px; border: 1px solid var(--sccal-card-border);
    background: transparent; color: var(--sccal-text);
    font-family: var(--sccal-font); font-size: 12px; font-weight: 600;
    cursor: pointer; transition: all 0.2s ease;
}
.sccal-dur-btn:hover { background: rgba(255,255,255,0.05); }
.sccal-dur-btn--active { color: #fff; border-color: transparent; }

.sccal-stats { display: flex; gap: 12px; align-items: center; }
.sccal-stat {
    font-size: 13px; font-weight: 600; color: var(--sccal-text-muted);
    padding: 3px 10px; border-radius: 12px;
    background: rgba(255,255,255,0.05);
}
.sccal-stat--met { color: var(--sccal-success); background: rgba(28,217,145,0.1); }
.sccal-stat--unmet { color: var(--sccal-error); background: rgba(231,76,60,0.1); }

/* ── Instruction ──────────────────────────────────────────────────────── */

.sccal-instruction {
    font-size: 13px; color: var(--sccal-text-muted); text-align: center;
    margin-bottom: 12px; font-style: italic;
}

/* ── Grid ─────────────────────────────────────────────────────────────── */

.sccal-grid {
    border: 1px solid var(--sccal-card-border); border-radius: 12px;
    overflow: hidden; background: var(--sccal-card-bg);
    margin-bottom: 16px;
}

.sccal-header {
    display: grid; grid-template-columns: 50px repeat(7, 1fr);
    border-bottom: 1px solid var(--sccal-card-border);
}
.sccal-header-cell {
    padding: 8px 4px; text-align: center;
    font-size: 12px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.05em; color: var(--sccal-text-muted);
}

.sccal-row {
    display: grid; grid-template-columns: 50px repeat(7, 1fr);
    border-bottom: 1px solid var(--sccal-card-border);
    min-height: 48px;
}
.sccal-row:last-child { border-bottom: none; }

.sccal-time-col {
    display: flex; align-items: flex-start; justify-content: center;
    padding-top: 4px; border-right: 1px solid var(--sccal-card-border);
}
.sccal-time-label {
    font-size: 10px; font-weight: 600; color: var(--sccal-text-muted);
}

/* ── Cell ─────────────────────────────────────────────────────────────── */

.sccal-cell {
    position: relative; min-height: 48px;
    border-right: 1px solid var(--sccal-card-border);
    cursor: pointer;
    transition: background 0.15s ease;
}
.sccal-cell:last-child { border-right: none; }
.sccal-cell:hover { background: var(--sccal-cell-hover); }

/* ── Events (sessions + blocks) ──────────────────────────────────────── */

.sccal-event {
    position: absolute; left: 2px; right: 2px; top: 2px;
    border-radius: 6px; padding: 3px 6px;
    display: flex; flex-direction: column; justify-content: center;
    overflow: hidden; z-index: 1;
    transition: opacity 0.2s ease, transform 0.15s ease;
}

.sccal-event--session {
    cursor: default; opacity: 0.85;
}

.sccal-event--block {
    cursor: pointer;
}
.sccal-event--block:hover {
    opacity: 0.9; transform: scale(0.98);
}

.sccal-event-label {
    font-size: 10px; font-weight: 700; color: #fff;
    line-height: 1.2; white-space: nowrap; overflow: hidden;
    text-overflow: ellipsis;
}
.sccal-event-time {
    font-size: 9px; font-weight: 500; color: rgba(255,255,255,0.7);
    white-space: nowrap;
}
.sccal-event-remove {
    position: absolute; top: 2px; right: 4px;
    font-size: 14px; font-weight: 700; color: rgba(255,255,255,0.6);
    line-height: 1; cursor: pointer;
}
.sccal-event--block:hover .sccal-event-remove { color: #fff; }

/* v2.7.0: drag-to-create preview + 15-min cell snap. */
.sccal-event--preview {
    background: rgba(83, 51, 237, 0.35);
    border: 2px dashed rgba(83, 51, 237, 0.7);
    pointer-events: none;
    z-index: 2;
}
.sccal-event--preview .sccal-event-label,
.sccal-event--preview .sccal-event-time {
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
.sccal-cell { user-select: none; }

/* v2.7.1: bottom resize handle on student blocks. */
.sccal-event-resize {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 8px;
    cursor: ns-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.sccal-event-resize::before {
    content: '';
    display: block;
    width: 30px;
    height: 3px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.7);
}
.sccal-event--block:hover .sccal-event-resize { opacity: 1; }

/* v2.7.1: name modal. */
.sccal-modal-backdrop {
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(0, 0, 0, 0.55);
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(3px);
    animation: sccalFadeIn 0.15s ease both;
}
.sccal-modal {
    background: var(--sccal-card-bg, #2a2b2e);
    color: var(--sccal-text, #f0f0f2);
    border: 1px solid var(--sccal-card-border);
    border-radius: 12px;
    padding: 20px 22px;
    width: min(380px, calc(100vw - 32px));
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    font-family: var(--sccal-font);
}
.sccal-modal-title {
    font-size: 15px; font-weight: 600; margin-bottom: 12px;
}
.sccal-modal-input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.25);
    color: var(--sccal-text);
    border: 1px solid var(--sccal-card-border);
    border-radius: 8px;
    font-family: var(--sccal-font);
    font-size: 14px;
    margin-bottom: 16px;
}
.sccal-modal-input:focus {
    outline: none;
    border-color: var(--sccal-purple, #5333ed);
    background: rgba(0, 0, 0, 0.35);
}
.sccal-modal-actions {
    display: flex; justify-content: flex-end; gap: 10px;
}
html[data-theme="light"] .sccal-modal, html.light .sccal-modal {
    background: #fff;
}
html[data-theme="light"] .sccal-modal-input, html.light .sccal-modal-input {
    background: #fff;
    color: #1a1a1e;
    border-color: rgba(0, 0, 0, 0.12);
}
html[data-theme="light"] .sccal-modal-input:focus, html.light .sccal-modal-input:focus {
    background: #fff;
    border-color: #5333ed;
}

/* ── Legend ────────────────────────────────────────────────────────────── */

.sccal-legend {
    display: flex; gap: 16px; justify-content: center;
    margin-bottom: 16px; flex-wrap: wrap;
}
.sccal-legend-item {
    display: flex; align-items: center; gap: 6px;
    font-size: 12px; font-weight: 500; color: var(--sccal-text-muted);
}
.sccal-legend-dot {
    width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}

/* ── Action Buttons ───────────────────────────────────────────────────── */

.sccal-actions {
    display: flex; align-items: center; justify-content: center;
    gap: 10px; flex-wrap: wrap;
}

.sccal-btn {
    padding: 8px 24px; border: none; border-radius: 24px;
    font-family: var(--sccal-font); font-size: 14px; font-weight: 600;
    cursor: pointer; transition: background 0.2s ease, transform 0.15s ease;
}
.sccal-btn:active { transform: scale(0.97); }
.sccal-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.sccal-btn--primary { background: var(--sccal-accent); color: #1C1D1F; }
.sccal-btn--primary:hover:not(:disabled) { background: #7DF9E9; }
.sccal-btn--secondary { background: transparent; border: 1px solid var(--sccal-card-border); color: var(--sccal-text); }
.sccal-btn--secondary:hover { background: rgba(255,255,255,0.05); }

.sccal-status { font-size: 13px; font-weight: 500; }
.sccal-status--saved { color: var(--sccal-success); }
.sccal-status--error { color: var(--sccal-error); }

/* ── Light Theme ──────────────────────────────────────────────────────── */

html[data-theme="light"] .sccal-widget, html.light .sccal-widget {
    --sccal-text: #1a1a1e;
    --sccal-text-muted: rgba(0,0,0,0.5);
    --sccal-bg: #f5f5f7;
    --sccal-card-bg: #e8e8ed;
    --sccal-card-border: rgba(0,0,0,0.08);
    --sccal-cell-hover: rgba(83,51,237,0.05);
}
html[data-theme="light"] .sccal-btn--primary, html.light .sccal-btn--primary { background: #5333ed; color: #fff; }
html[data-theme="light"] .sccal-btn--primary:hover, html.light .sccal-btn--primary:hover { background: #6b4fff; }

/* ── Focus Mode ───────────────────────────────────────────────────────── */

.sophicly-focus-mode .sccal-widget { max-width: none; margin: 24px 0; }

/* ── Responsive ───────────────────────────────────────────────────────── */

@media (max-width: 640px) {
    .sccal-widget { margin: 16px 4px; }
    .sccal-header, .sccal-row { grid-template-columns: 36px repeat(7, 1fr); }
    .sccal-header-cell { font-size: 10px; padding: 6px 2px; }
    .sccal-time-label { font-size: 9px; }
    .sccal-row { min-height: 40px; }
    .sccal-event-label { font-size: 8px; }
    .sccal-event-time { display: none; }
    .sccal-toolbar { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
    .sccal-widget *, .sccal-widget *::before, .sccal-widget *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
