:root {
    --primary: #4F46E5;
    --bg-outside: #E2E8F0;
    --surface: #FFFFFF;
    --surface-hover: #F8FAFC;
    --border: #F1F5F9;
    --border-strong: #E2E8F0;
    --text-main: #0F172A;
    --text-muted: #64748B;
    --accent-red: #EF4444;
    --accent-green: #10B981;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --radius-lg: 16px;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Pretendard', sans-serif; }

body { background: var(--bg-outside); display: flex; justify-content: center; align-items: center; height: 100vh; }

#app { width: 100%; max-width: 480px; height: 100vh; background: var(--surface); display: flex; flex-direction: column; position: relative; overflow: hidden; }

@media (min-width: 485px) {
    #app { height: 90vh; max-height: 850px; border-radius: 24px; box-shadow: 0 20px 40px rgba(0,0,0,0.1); }
}

.header { background: var(--surface); padding: 24px 20px 0; position: relative; z-index: 20; box-shadow: 0 4px 12px rgba(0,0,0,0.02); }
.date-display { color: var(--primary); font-size: 0.85rem; font-weight: 700; margin-bottom: 8px; letter-spacing: -0.02em; }
.title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; position: relative; }
.admin-only-flex { display: flex; align-items: center; gap: 8px; }
h1 { font-size: 1.5rem; font-weight: 800; color: var(--text-main); }
.edit-icon { opacity: 0.4; font-size: 1.1rem; cursor: pointer; transition: opacity 0.2s; }
.edit-icon:hover { opacity: 1; }

.menu-btn { background: var(--surface-hover); border: none; width: 38px; height: 38px; border-radius: 50%; font-size: 1.4rem; cursor: pointer; color: var(--text-muted); transition: background 0.2s, transform 0.2s; display: flex; align-items: center; justify-content: center; }
.menu-btn:hover { background: #E2E8F0; }
.menu-btn:active { transform: scale(0.95); }

.dropdown-menu { position: absolute; top: 50px; right: 0; background: white; border-radius: var(--radius-lg); box-shadow: 0 10px 30px rgba(0,0,0,0.1); width: 260px; padding: 8px 0; border: 1px solid var(--border-strong); transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1); transform-origin: top right; z-index: 99; }
.dropdown-menu.hidden { opacity: 0; transform: scale(0.95); pointer-events: none; }
.menu-item { display: block; width: 100%; text-align: left; padding: 12px 16px; background: none; border: none; font-size: 0.95rem; font-weight: 600; color: var(--text-main); cursor: pointer; border-radius: 8px; transition: background 0.2s; display: flex; align-items: center; }
.menu-item:hover { background-color: var(--surface-hover); color: var(--primary); }
.material-symbols-rounded { font-size: 1.25rem; vertical-align: middle; margin-right: 8px; font-variation-settings: 'FILL' 1, 'wght' 600, 'GRAD' 0, 'opsz' 24; }
#menuBtn .material-symbols-rounded { margin-right: 0; font-size: 1.75rem; color: var(--text-main); font-variation-settings: 'FILL' 0; }
.text-primary { color: var(--primary); }
.text-red { color: var(--accent-red); }
.text-green { color: var(--accent-green); }
.text-muted { color: var(--text-muted); }
.divider { height: 1px; background: var(--border-strong); margin: 6px 0; }

.tabs { display: flex; background: var(--surface-hover); padding: 4px; border-radius: 12px; margin-bottom: -1px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 1 0 auto; min-width: 100px; padding: 12px; border: none; background: transparent; font-weight: 700; color: var(--text-muted); border-radius: 10px; cursor: pointer; transition: all 0.2s; }
.tab.active { background: white; color: var(--primary); box-shadow: var(--shadow-sm); }

/* Readonly Mode Toggles */
body.read-mode .admin-only { display: none !important; }
body.read-mode .admin-only-btn { display: none !important; }
body.read-mode .schedule-card { cursor: default; }
body.read-mode .schedule-card:hover { transform: none; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); z-index: 5;}

/* Delete Mode Active */
body.delete-mode .schedule-card {
    animation: shake 0.5s infinite alternate;
}
@keyframes shake {
    0% { transform: rotate(-1.5deg); }
    100% { transform: rotate(1.5deg); }
}

/* Timetable Grid */
.timetable-container { flex: 1; overflow-y: auto; overflow-x: hidden; position: relative; padding-bottom: 60px; background: white; }
.timetable-container::-webkit-scrollbar { width: 4px; }
.timetable-container::-webkit-scrollbar-thumb { background-color: #CBD5E1; border-radius: 4px; }
.timetable-grid { display: grid; grid-template-columns: 50px repeat(5, 1fr); width: 100%;}
.day-header { padding: 12px 0; font-size: 0.9rem; font-weight: 700; border-right: 1px solid var(--border); border-bottom: 2px solid var(--border-strong); background: var(--surface); color: var(--text-muted); position: sticky; top: 0; z-index: 10; }
.time-col-header { border-right: 1px solid var(--border); border-bottom: 2px solid var(--border-strong); background: var(--surface); position: sticky; top: 0; z-index: 11; }
.time-row-label { text-align: center; font-size: 0.75rem; font-weight: 500; color: var(--text-muted); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); display: flex; flex-direction: column; justify-content: center; padding: 8px 2px; min-height: 80px; }
.grid-cell { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); position: relative; min-height: 80px; }
.grid-cell:nth-child(6n) { border-right: none; }

/* Current Time Indicator */
.current-time-line { position: absolute; height: 2px; background-color: var(--accent-red); z-index: 15; pointer-events: none; transition: top 1s cubic-bezier(0.4, 0, 0.2, 1); box-shadow: 0 0 4px rgba(239, 68, 68, 0.4); }
.time-pulsing-dot { position: absolute; left: -4px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background-color: var(--accent-red); }
.time-pulsing-dot::after { content: ''; position: absolute; left: 0; top: 0; right: 0; bottom: 0; border-radius: 50%; background-color: var(--accent-red); animation: pulse 1.5s infinite; }
@keyframes pulse { 0% { transform: scale(1); opacity: 0.7; } 100% { transform: scale(2.5); opacity: 0; } }

/* Schedule Cards */
.schedule-card { position: absolute; left: 2px; right: 2px; border-radius: 6px; padding: 4px 6px; font-size: 0.75rem; font-weight: 700; color: #fff; cursor: pointer; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); overflow: hidden; transition: transform 0.2s, box-shadow 0.2s; backdrop-filter: blur(4px); z-index: 5; display: flex; flex-direction: column; }
.schedule-card .title { margin-bottom: 2px; font-size: 0.8rem; line-height: 1.25; word-break: break-all; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.schedule-card .time { font-size: 0.55rem; font-weight: 500; opacity: 0.8; margin-bottom: 2px; letter-spacing: -0.01em; }
.schedule-card .memo { font-size: 0.65rem; font-weight: 500; opacity: 0.9; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.schedule-card:hover { transform: translateY(-2px); box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); z-index: 8; }
.text-center { text-align: center; }

/* Modals */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(4px); display: flex; justify-content: center; align-items: center; z-index: 100; opacity: 1; transition: opacity 0.2s ease; }
.modal-overlay.hidden { opacity: 0; pointer-events: none; }
.modal { background: white; width: 90%; max-width: 400px; border-radius: var(--radius-lg); padding: 24px; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1); transform: translateY(0); transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
.modal-overlay.hidden .modal { transform: translateY(20px); }
.modal-title { font-size: 1.25rem; font-weight: 800; margin-bottom: 20px; color: var(--text-main); }
.form-group { margin-bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 0.85rem; font-weight: 700; color: var(--text-muted); }
.form-group input[type="text"] { padding: 12px 14px; border: 1px solid var(--border-strong); border-radius: 8px; font-size: 0.95rem; outline: none; transition: border-color 0.2s; background: var(--surface-hover); color: var(--text-main); font-weight: 500; }
.form-group input[type="text"]:focus { border-color: var(--primary); background: white; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 120px; margin-bottom: 0;}

/* V2 Checkboxes & Selects */
.checkbox-group { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.checkbox-group label { display: flex; align-items: center; gap: 4px; font-size: 0.9rem; font-weight: 600; cursor: pointer; padding: 4px 8px; background: var(--surface-hover); border-radius: 6px;}
.checkbox-group input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer;}
.time-selects { display: flex; align-items: center; gap: 6px; }
.time-selects select { flex: 1; padding: 10px; border: 1px solid var(--border-strong); border-radius: 8px; font-size: 0.95rem; font-weight: 600; background: var(--surface-hover); outline:none; }
.time-selects select:focus { border-color: var(--primary); background: white; }
.time-separator { font-weight: 800; color: var(--text-muted); }
.color-palette { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.color-swatch { width: 34px; height: 34px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; transition: transform 0.1s; }
.color-swatch.active { border-color: var(--text-main); transform: scale(1.1); box-shadow: 0 0 0 2px white inset; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.btn { padding: 12px 20px; border-radius: 8px; font-weight: 700; font-size: 0.95rem; cursor: pointer; border: none; transition: transform 0.1s; }
.btn:active { transform: scale(0.96); }
.btn-outline { background: transparent; border: 1px solid var(--border-strong); color: var(--text-muted); }
.btn-outline:hover { background: var(--surface-hover); }
.btn-primary { background: var(--primary); color: white; box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3); }
.btn-primary:hover { filter: brightness(110%); }
.btn-danger { background: var(--accent-red); color: white; box-shadow: 0 4px 10px rgba(239, 68, 68, 0.3); }
.btn-danger:hover { filter: brightness(110%); }

/* Toast */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1E293B; color: white; padding: 12px 24px; border-radius: 30px; font-weight: 600; font-size: 0.9rem; z-index: 999; box-shadow: 0 10px 15px rgba(0,0,0,0.1); opacity: 1; transition: opacity 0.3s; pointer-events: none;}
.toast.hidden { opacity: 0; }
