/* ---------- CSS VARIABLES & THEMES ---------- */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --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 -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-pill: 999px;

    /* One spacing scale. Every new element picks from these rather than
       inventing 10px, 15px or 18px, which is how ten different paddings ended
       up in the same card. */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
}

[data-theme="dark"] {
    --primary: #818cf8;
    --primary-dark: #6366f1;
    --secondary: #a78bfa;
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
    --bg-primary: #1f2937;
    --bg-secondary: #111827;
    --bg-tertiary: #374151;
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --border: #374151;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
    transition: background-color 0.3s ease, color 0.3s ease;
    line-height: 1.6;
}

/* ---------- HEADER ---------- */
.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-3);
    /* Wrap rather than overlap. At 430px the brand and five buttons cannot
       share a line, and the old fixed row let them collide. */
    flex-wrap: wrap;
    margin-bottom: var(--space-5);
    padding: var(--space-4) 0;
}

h1 {
    font-size: 2rem;
    line-height: 1.2;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ---------- ICON BUTTONS ----------
   44px because that is the minimum comfortable touch target, and this app is
   used on phones far more than desktops. The icon inside is 20px; the rest is
   deliberate breathing room, not padding that happened. */
.icon-btn {
    /* No border and no filled circle. The emoji already carry colour and a
       distinct silhouette; framing each one in a grey ring gave the eye five
       identical rectangles to land on before it reached the icons. */
    background: transparent;
    border: none;
    width: 44px;              /* still a full touch target, just an invisible one */
    height: 44px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.15s ease, opacity 0.15s ease;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: 1.3rem;
    line-height: 1;
    flex: none;
}

.icon-btn:hover {
    /* The hover surface is what tells you it is a button, and it only appears
       when you are pointing at it. */
    background: var(--bg-tertiary);
    /* No transform. The old scale(1.1) made the whole header twitch on hover,
       and on touch devices it fires on tap and looks like a glitch. */
    transform: none;
}

/* Kept for the few controls that are still SVG rather than emoji. */
.icon-btn svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
    display: block;
}

/* The Sign in button sits in the same row but is a label, not an icon. */
.icon-btn--text {
    width: auto;
    padding: 0 16px;
    font-size: 0.875rem;
    font-weight: 600;
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    white-space: nowrap;
}

.icon-btn--text:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: #fff;
}

/* Notifications off: dimmed AND struck through, so the state is not carried by
   opacity alone. A 50%-opacity icon is easy to miss and impossible to
   distinguish from "disabled" at a glance. */
.icon-btn.is-off {
    opacity: 0.55;
}

.icon-btn.is-off svg {
    stroke-dasharray: none;
}

/* ---------- TABS ---------- */
.tabs {
    display: flex;
    gap: 12px;
    margin-bottom: 30px;
    padding: 8px;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
}

.tab-button {
    padding: 12px 24px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    flex: 1;
    min-width: 120px;
    white-space: nowrap;
}

.tab-/* ---------- SECONDARY BUTTONS ----------
   Three identical filled buttons in a row means none of them is the obvious
   one. The first action in a group stays filled; the rest are quiet. */
button.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border);
    box-shadow: none;
}

button.btn-secondary:hover {
    background: var(--bg-tertiary);
    border-color: var(--text-secondary);
}

/* Destructive, and styled as such rather than as a grey slab with black text
   that ignored the theme entirely. */
button.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--border);
    box-shadow: none;
}

button.btn-danger:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

/* ---------- DUE CHIP ----------
   The due text used to be grey parentheses inside a longer sentence. As a chip
   it can be scanned down a column. Colour is never the only signal — the words
   ("Past due", "Due today") carry the meaning on their own. */
.due-chip {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 9px;
    border-radius: var(--radius-pill);
    white-space: nowrap;
    /* Tinted with the chip's own colour. color-mix takes a var(), which string
       concatenation ("var(--danger)" + "1f") does not — that produced an
       invalid declaration that the browser dropped without complaint, so the
       chips rendered as bare coloured text. */
    background: color-mix(in srgb, currentColor 15%, transparent);
    color: var(--text-secondary);
}

/* Small icon button that sits inline with text, e.g. the class colour picker. */
.icon-btn--inline {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    margin-left: var(--space-3);
    background: var(--bg-tertiary);
    font-size: 0.95rem;
    flex: none;
}

.icon-btn--inline svg {
    width: 15px;
    height: 15px;
}

@media (max-width: 480px) {
    h1 { font-size: 1.6rem; }
    .header-container { padding: var(--space-3) 0; margin-bottom: var(--space-4); }
}

button:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.tab-button.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    box-shadow: var(--shadow-md);
}

/* ---------- ADD CLASS ---------- */
.add-class {
    margin-bottom: 24px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.add-class input {
    flex: 1;
    min-width: 200px;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.add-class input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.add-class button {
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.add-class /* ---------- SECONDARY BUTTONS ----------
   Three identical filled buttons in a row means none of them is the obvious
   one. The first action in a group stays filled; the rest are quiet. */
button.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border);
    box-shadow: none;
}

button.btn-secondary:hover {
    background: var(--bg-tertiary);
    border-color: var(--text-secondary);
}

/* Destructive, and styled as such rather than as a grey slab with black text
   that ignored the theme entirely. */
button.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--border);
    box-shadow: none;
}

button.btn-danger:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

/* ---------- DUE CHIP ----------
   The due text used to be grey parentheses inside a longer sentence. As a chip
   it can be scanned down a column. Colour is never the only signal — the words
   ("Past due", "Due today") carry the meaning on their own. */
.due-chip {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 9px;
    border-radius: var(--radius-pill);
    white-space: nowrap;
    /* Tinted with the chip's own colour. color-mix takes a var(), which string
       concatenation ("var(--danger)" + "1f") does not — that produced an
       invalid declaration that the browser dropped without complaint, so the
       chips rendered as bare coloured text. */
    background: color-mix(in srgb, currentColor 15%, transparent);
    color: var(--text-secondary);
}

/* Small icon button that sits inline with text, e.g. the class colour picker. */
.icon-btn--inline {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    margin-left: var(--space-3);
    background: var(--bg-tertiary);
    font-size: 0.95rem;
    flex: none;
}

.icon-btn--inline svg {
    width: 15px;
    height: 15px;
}

@media (max-width: 480px) {
    h1 { font-size: 1.6rem; }
    .header-container { padding: var(--space-3) 0; margin-bottom: var(--space-4); }
}

button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* ---------- CLASS CARD ---------- */
.class-card {
    background: var(--bg-primary);
    padding: 20px;
    margin-bottom: 20px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    transition: all 0.3s ease;
    border: 1px solid var(--border);
}

.class-card:hover {
    box-shadow: var(--shadow-lg);
}

.class-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-md);
    transition: background 0.2s ease;
}

.class-header:hover {
    background: var(--bg-secondary);
}

.class-header h2 {
    margin: 0;
    flex: 1;
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-primary);
}

.class-header .assignment-count {
    padding: 6px 14px;
    background: var(--bg-tertiary);
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ---------- ASSIGNMENTS & TESTS ---------- */
.assignment, .test {
    padding: 16px;
    margin-bottom: 12px;
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    border-left: 4px solid var(--success);
    transition: all 0.2s ease;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.assignment:hover, .test:hover {
    transform: translateX(4px);
    box-shadow: var(--shadow-md);
}

.test {
    border-left-color: var(--warning);
}

.assignment.completed, .test.completed {
    opacity: 0.7;
    border-left-color: var(--text-secondary);
}

.completed-label {
    margin-top: 8px;
    padding: 4px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--success);
    background: rgba(16, 185, 129, 0.1);
    border-radius: var(--radius-sm);
    display: inline-block;
}

/* ---------- INPUT FIELDS ---------- */
input[type="text"],
input[type="date"],
input[type="time"],
input[type="number"] {
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all 0.2s ease;
    font-family: inherit;
}

input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: var(--shadow-md);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    cursor: pointer;
    border: none;
    box-shadow: var(--shadow-sm);
}

/* ---------- BUTTONS ---------- */
button {
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

/* ---------- SECONDARY BUTTONS ----------
   Three identical filled buttons in a row means none of them is the obvious
   one. The first action in a group stays filled; the rest are quiet. */
button.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border);
    box-shadow: none;
}

button.btn-secondary:hover {
    background: var(--bg-tertiary);
    border-color: var(--text-secondary);
}

/* Destructive, and styled as such rather than as a grey slab with black text
   that ignored the theme entirely. */
button.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--border);
    box-shadow: none;
}

button.btn-danger:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

/* ---------- DUE CHIP ----------
   The due text used to be grey parentheses inside a longer sentence. As a chip
   it can be scanned down a column. Colour is never the only signal — the words
   ("Past due", "Due today") carry the meaning on their own. */
.due-chip {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 9px;
    border-radius: var(--radius-pill);
    white-space: nowrap;
    /* Tinted with the chip's own colour. color-mix takes a var(), which string
       concatenation ("var(--danger)" + "1f") does not — that produced an
       invalid declaration that the browser dropped without complaint, so the
       chips rendered as bare coloured text. */
    background: color-mix(in srgb, currentColor 15%, transparent);
    color: var(--text-secondary);
}

/* Small icon button that sits inline with text, e.g. the class colour picker. */
.icon-btn--inline {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    margin-left: var(--space-3);
    background: var(--bg-tertiary);
    font-size: 0.95rem;
    flex: none;
}

.icon-btn--inline svg {
    width: 15px;
    height: 15px;
}

@media (max-width: 480px) {
    h1 { font-size: 1.6rem; }
    .header-container { padding: var(--space-3) 0; margin-bottom: var(--space-4); }
}

button:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

button:active {
    transform: translateY(0);
}

/* ---------- FILTER TABS ---------- */
.filter-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 24px;
    padding: 6px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    flex-wrap: wrap;
}

.filter-tab {
    padding: 10px 20px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    flex: 1;
}

.filter-tab:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.filter-tab.active {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

/* ---------- CALENDAR ---------- */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.calendar-legend {
    margin-top: 20px;
    padding: 16px;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.calendar-day-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 12px;
    text-align: center;
    font-weight: 600;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
}

.calendar-day {
    background: var(--bg-primary);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    min-height: 120px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    transition: all 0.2s ease;
}

.calendar-day:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.calendar-day.empty {
    background: var(--bg-tertiary);
    opacity: 0.4;
}

.calendar-day.today {
    border: 3px solid var(--primary);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.05) 0%, rgba(139, 92, 246, 0.05) 100%);
    box-shadow: var(--shadow-md);
}

.day-number {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.day-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.calendar-item {
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.calendar-item:hover {
    transform: translateX(2px);
    box-shadow: var(--shadow-sm);
}

.calendar-item.assignment {
    background: var(--success);
    color: white;
}

.calendar-item.test {
    background: var(--warning);
    color: white;
}

.calendar-item.completed {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    text-decoration: line-through;
}

/* Four tabs do not fit on one line on a phone. Rather than let them wrap
   unevenly, put them in a deliberate 2x2. */
@media (max-width: 560px) {
    .tabs {
        gap: 8px;
        padding: 6px;
    }

    .tab-button {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
        padding: 11px 8px;
        font-size: 0.88rem;
    }
}

/* ---------- MOBILE RESPONSIVE ---------- */
@media (max-width: 768px) {
    body {
        padding: 12px;
    }

    h1 {
        font-size: 1.5rem;
    }

    .header-container {
        margin-bottom: 16px;
    }

    .tabs {
        padding: 6px;
        gap: 8px;
    }

    .tab-button {
        padding: 10px 16px;
        font-size: 0.85rem;
        min-width: 100px;
    }

    .class-card {
        padding: 16px;
    }

    .class-header h2 {
        font-size: 1.1rem;
    }

    .calendar-grid {
        gap: 8px;
    }

    .calendar-day {
        min-height: 100px;
        padding: 8px;
    }

    .day-number {
        font-size: 1rem;
    }

    .calendar-item {
        font-size: 0.7rem;
        padding: 4px 6px;
    }
}

@media (max-width: 480px) {
    .add-class {
        flex-direction: column;
    }

    .add-class input,
    .add-class button {
        width: 100%;
    }

    .calendar-day-header {
        font-size: 0.75rem;
        padding: 8px;
    }

    .calendar-day {
        min-height: 80px;
    }
}

/* ---------- ANIMATIONS ---------- */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.class-card {
    animation: fadeIn 0.4s ease;
}