/* ==============================
   StudyFlow Design System
   ============================== */

:root {
    /* Palette */
    --bg:            #faf9f7;
    --bg-raised:     #f2f0ec;
    --bg-sunken:     #e8e6e1;
    --surface:       #ffffff;
    --border:        #ddd9d1;
    --border-light:  #e8e6e1;

    --text:          #1a1a1a;
    --text-secondary:#5c5a54;
    --text-tertiary: #8a877f;

    --navy:          #1a2332;
    --navy-light:    #2a3a4d;

    --overload:      #b94241;
    --overload-bg:   #fdf0ef;
    --tight:         #b07d1e;
    --tight-bg:      #fdf8ec;
    --good:          #3d7a5a;
    --good-bg:       #eef7f1;

    --accent:        #c95d20;
    --accent-hover:  #b0501b;
    --accent-bg:     #fdf3ec;

    /* Type scale */
    --font:          'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --text-xs:       0.75rem;
    --text-sm:       0.8125rem;
    --text-base:     0.9375rem;
    --text-md:       1.0625rem;
    --text-lg:       1.3125rem;
    --text-xl:       1.625rem;

    /* Spacing */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 20px;
    --sp-6: 24px;
    --sp-8: 32px;
    --sp-10: 40px;
    --sp-12: 48px;

    /* Radius */
    --r-sm: 4px;
    --r-md: 6px;
    --r-lg: 8px;
}

/* ==============================
   Reset & Base
   ============================== */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    font-size: var(--text-base);
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
}

button {
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

a {
    color: inherit;
}

/* ==============================
   Layout
   ============================== */

.app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 220px;
    background: var(--navy);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-header {
    padding: var(--sp-6) var(--sp-5);
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.logo {
    font-size: var(--text-md);
    font-weight: 700;
    letter-spacing: -0.02em;
}

.nav-list {
    list-style: none;
    padding: var(--sp-3) var(--sp-3);
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    width: 100%;
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--r-md);
    color: rgba(255,255,255,0.6);
    font-size: var(--text-sm);
    font-weight: 500;
    transition: color 0.15s, background 0.15s;
    text-align: left;
}

.nav-item:hover {
    color: rgba(255,255,255,0.9);
    background: rgba(255,255,255,0.06);
}

.nav-item.active {
    color: #fff;
    background: rgba(255,255,255,0.1);
}

.nav-item:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.sidebar-footer {
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid rgba(255,255,255,0.08);
}

.btn-add {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    width: 100%;
    padding: var(--sp-3) var(--sp-4);
    background: var(--accent);
    color: #fff;
    border-radius: var(--r-md);
    font-size: var(--text-sm);
    font-weight: 600;
    transition: background 0.15s;
}

.btn-add:hover {
    background: var(--accent-hover);
}

.btn-add:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* Content */
.content {
    flex: 1;
    margin-left: 220px;
    padding: var(--sp-10) var(--sp-12);
    max-width: 860px;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

/* ==============================
   Section Structure
   ============================== */

.section {
    margin-bottom: var(--sp-10);
}

.section-header {
    display: flex;
    align-items: baseline;
    gap: var(--sp-3);
    margin-bottom: var(--sp-4);
}

.section-header h2 {
    font-size: var(--text-md);
    font-weight: 600;
    letter-spacing: -0.01em;
}

.section-note {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

.view-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: var(--sp-6);
}

.view-top h1 {
    font-size: var(--text-lg);
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* ==============================
   Workload Banner
   ============================== */

.workload-banner {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-5);
    padding: var(--sp-6);
    border-radius: var(--r-lg);
    margin-bottom: var(--sp-10);
    border: 1px solid var(--border);
    background: var(--surface);
}

.workload-banner.status-overload {
    background: var(--overload-bg);
    border-color: #e8c4c3;
}

.workload-banner.status-tight {
    background: var(--tight-bg);
    border-color: #e5d9b8;
}

.workload-banner.status-good {
    background: var(--good-bg);
    border-color: #bcdcc7;
}

.workload-icon {
    font-size: 1.75rem;
    line-height: 1;
    flex-shrink: 0;
}

.workload-body {
    flex: 1;
    min-width: 0;
}

.workload-title {
    font-size: var(--text-lg);
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: var(--sp-1);
}

.workload-text {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: 1.6;
}

.workload-text strong {
    font-weight: 600;
    color: var(--text);
}

.workload-text .hl-overload {
    color: var(--overload);
    font-weight: 600;
}

.workload-text .hl-tight {
    color: var(--tight);
    font-weight: 600;
}

.workload-text .hl-good {
    color: var(--good);
    font-weight: 600;
}

/* ==============================
   Focus List
   ============================== */

.focus-list {
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
}

.focus-item {
    display: grid;
    grid-template-columns: 32px 1fr auto;
    gap: var(--sp-4);
    align-items: center;
    padding: var(--sp-4) var(--sp-5);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    transition: border-color 0.15s;
}

.focus-item:hover {
    border-color: var(--text-tertiary);
}

.focus-rank {
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--text-tertiary);
    text-align: center;
}

.focus-rank.top {
    color: var(--accent);
}

.focus-body {
    min-width: 0;
}

.focus-subject {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-tertiary);
    margin-bottom: 2px;
}

.focus-name {
    font-size: var(--text-base);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.focus-meta {
    display: flex;
    gap: var(--sp-2);
    margin-top: var(--sp-2);
    flex-wrap: wrap;
}

.tag {
    font-size: var(--text-xs);
    padding: 2px var(--sp-2);
    border-radius: var(--r-sm);
    font-weight: 500;
    white-space: nowrap;
}

.tag-urgent {
    background: var(--overload-bg);
    color: var(--overload);
}

.tag-warning {
    background: var(--tight-bg);
    color: var(--tight);
}

.tag-safe {
    background: var(--good-bg);
    color: var(--good);
}

.tag-neutral {
    background: var(--bg-raised);
    color: var(--text-secondary);
}

.focus-actions {
    display: flex;
    gap: var(--sp-1);
}

.btn-icon {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-md);
    color: var(--text-tertiary);
    transition: background 0.12s, color 0.12s;
    font-size: var(--text-sm);
}

.btn-icon:hover {
    background: var(--bg-raised);
    color: var(--text);
}

.btn-icon.danger:hover {
    background: var(--overload-bg);
    color: var(--overload);
}

.btn-icon:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* ==============================
   Collision Section
   ============================== */

.collision-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-3);
}

.collision-chip {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    font-size: var(--text-sm);
}

.collision-chip .sub {
    font-weight: 600;
    color: var(--text);
}

.collision-chip .due {
    color: var(--overload);
    font-weight: 500;
    font-size: var(--text-xs);
}

/* ==============================
   Forecast Row
   ============================== */

.forecast-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-4);
}

.availability-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: var(--sp-2);
    margin-top: var(--sp-3);
}

.avail-day {
    display: flex;
    flex-direction: column;
    gap: var(--sp-1);
}

.avail-day label {
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.avail-input {
    width: 100%;
    padding: var(--sp-2) var(--sp-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--text-primary);
    font: inherit;
    font-size: var(--text-sm);
    text-align: center;
}

.forecast-cell {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--sp-5);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}

.forecast-label {
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.forecast-value {
    font-size: var(--text-xl);
    font-weight: 700;
    letter-spacing: -0.03em;
}

.forecast-input-wrap {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}

.forecast-input {
    width: 60px;
    padding: var(--sp-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: var(--text-xl);
    font-weight: 700;
    letter-spacing: -0.03em;
    background: var(--bg);
    color: var(--text);
    text-align: center;
}

.forecast-input:focus {
    outline: none;
    border-color: var(--accent);
}

.forecast-unit {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
}

.forecast-verdict {
    justify-content: center;
}

.verdict-label {
    font-size: var(--text-base);
    font-weight: 700;
    letter-spacing: -0.01em;
}

.verdict-sub {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: 1.5;
}

.verdict-label.overload { color: var(--overload); }
.verdict-label.tight { color: var(--tight); }
.verdict-label.good { color: var(--good); }

/* ==============================
   Due Soon Grid
   ============================== */

.due-soon-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--sp-4);
}

.due-soon-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--sp-5);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--sp-1);
}

.due-soon-number {
    font-size: var(--text-xl);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1;
}

.due-soon-number.overload {
    color: var(--overload);
}

.due-soon-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.due-soon-hours {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

/* ==============================
   Assignment Table
   ============================== */

.filters {
    display: flex;
    gap: var(--sp-2);
}

.filters select {
    padding: var(--sp-2) var(--sp-3);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--text);
    font-size: var(--text-sm);
}

.filters select:focus {
    outline: none;
    border-color: var(--accent);
}

.assignment-table {
    display: flex;
    flex-direction: column;
}

.assignment-row {
    display: grid;
    grid-template-columns: 1fr 100px 110px 90px 80px;
    align-items: center;
    gap: var(--sp-4);
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border-light);
    transition: background 0.12s;
}

.assignment-row:hover {
    background: var(--bg-raised);
}

.assignment-row:last-child {
    border-bottom: none;
}

.assignment-row-header {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}

.assignment-row-header:hover {
    background: none;
}

.ar-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ar-subject {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    font-weight: 400;
    display: block;
    margin-top: 1px;
}

.ar-date {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.ar-countdown {
    font-size: var(--text-xs);
    font-weight: 600;
    padding: 2px var(--sp-2);
    border-radius: var(--r-sm);
    display: inline-block;
    text-align: center;
}

.ar-countdown.overload, .ar-countdown.past {
    background: var(--overload-bg);
    color: var(--overload);
}

.ar-countdown.tight {
    background: var(--tight-bg);
    color: var(--tight);
}

.ar-countdown.good {
    background: var(--good-bg);
    color: var(--good);
}

.ar-actions {
    display: flex;
    gap: var(--sp-1);
    justify-content: flex-end;
}

/* ==============================
   Schedule
   ============================== */

.schedule-content {
    display: flex;
    flex-direction: column;
    gap: var(--sp-5);
}

.schedule-day {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    overflow: hidden;
}

.schedule-day-header {
    padding: var(--sp-3) var(--sp-5);
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border-light);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-secondary);
}

.schedule-day-header.today {
    color: var(--accent);
    background: var(--accent-bg);
    border-bottom-color: #e8cfc0;
}

.schedule-day-header.full {
    background: var(--tight-bg);
    color: var(--tight);
    border-bottom-color: #e5d9b8;
}

.schedule-warning {
    background: var(--tight-bg);
    border: 1px solid #e5d9b8;
    border-radius: var(--r-lg);
    padding: var(--sp-4) var(--sp-5);
    margin-bottom: var(--sp-4);
    font-size: var(--text-sm);
    color: var(--tight);
    line-height: 1.6;
}

.schedule-warning strong {
    display: block;
    margin-bottom: var(--sp-1);
    color: var(--text);
}

.sw-item {
    display: inline-block;
    padding: 2px var(--sp-2);
    background: rgba(176, 125, 30, 0.15);
    border-radius: var(--r-sm);
    margin: 2px 4px 2px 0;
    font-size: var(--text-xs);
    font-weight: 500;
}

.sw-total {
    display: block;
    margin-top: var(--sp-2);
    font-weight: 600;
    font-size: var(--text-sm);
}

.schedule-blocks {
    padding: var(--sp-3) var(--sp-5);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}

.schedule-block {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-3) 0;
    border-bottom: 1px solid var(--border-light);
}

.schedule-block:last-child {
    border-bottom: none;
}

.sb-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.sb-subject {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-tertiary);
}

.sb-name {
    font-size: var(--text-sm);
    font-weight: 500;
}

.sb-hours {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ==============================
   Empty State
   ============================== */

.empty-state {
    text-align: center;
    padding: var(--sp-10) var(--sp-5);
    color: var(--text-tertiary);
}

.empty-state h3 {
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--sp-1);
}

.empty-state p {
    font-size: var(--text-sm);
}

/* ==============================
   Modal
   ============================== */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(26,26,26,0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: var(--sp-5);
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--surface);
    border-radius: var(--r-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.modal-sm {
    max-width: 380px;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-5) var(--sp-6);
    border-bottom: 1px solid var(--border-light);
}

.modal-head h2 {
    font-size: var(--text-md);
    font-weight: 600;
}

.modal-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-md);
    color: var(--text-tertiary);
    font-size: 1.25rem;
}

.modal-close:hover {
    background: var(--bg-raised);
    color: var(--text);
}

/* Form */
form {
    padding: var(--sp-6);
}

.field {
    margin-bottom: var(--sp-5);
}

.field label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 500;
    margin-bottom: var(--sp-2);
    color: var(--text);
}

.field input, .field select, .field textarea {
    width: 100%;
    padding: var(--sp-3);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--bg);
    color: var(--text);
    font-size: var(--text-sm);
}

.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--surface);
}

.field input.error, .field select.error {
    border-color: var(--overload);
}

.field-error {
    display: none;
    font-size: var(--text-xs);
    color: var(--overload);
    margin-top: var(--sp-1);
}

.field-error.visible {
    display: block;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-4);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-6);
    border-top: 1px solid var(--border-light);
}

.btn-cancel {
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--r-md);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
}

.btn-cancel:hover {
    background: var(--bg-raised);
}

.btn-save {
    padding: var(--sp-2) var(--sp-5);
    border-radius: var(--r-md);
    font-size: var(--text-sm);
    font-weight: 600;
    background: var(--accent);
    color: #fff;
}

.btn-save:hover {
    background: var(--accent-hover);
}

.btn-danger {
    padding: var(--sp-2) var(--sp-5);
    border-radius: var(--r-md);
    font-size: var(--text-sm);
    font-weight: 600;
    background: var(--overload);
    color: #fff;
}

.btn-danger:hover {
    background: #9e3636;
}

.delete-text {
    padding: var(--sp-5) var(--sp-6) 0;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

/* ==============================
   Focus Visible
   ============================== */

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ==============================
   Reduced Motion
   ============================== */

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

/* ==============================
   Responsive
   ============================== */

@media (max-width: 900px) {
    .content {
        padding: var(--sp-6) var(--sp-5);
    }

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

    .availability-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .due-soon-grid {
        grid-template-columns: 1fr;
    }

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

    .assignment-row > :nth-child(2),
    .assignment-row > :nth-child(3) {
        display: none;
    }

    .assignment-row-header > :nth-child(2),
    .assignment-row-header > :nth-child(3) {
        display: none;
    }
}

@media (max-width: 640px) {
    .sidebar {
        width: 100%;
        height: auto;
        position: fixed;
        bottom: 0;
        top: auto;
        left: 0;
        right: 0;
        flex-direction: row;
        padding: 0;
    }

    .sidebar-header, .sidebar-footer {
        display: none;
    }

    .nav-list {
        display: flex;
        width: 100%;
        padding: var(--sp-2);
        gap: var(--sp-2);
    }

    .nav-item {
        flex: 1;
        justify-content: center;
        padding: var(--sp-3);
        font-size: var(--text-xs);
        flex-direction: column;
        gap: var(--sp-1);
    }

    .nav-item svg {
        width: 20px;
        height: 20px;
    }

    .content {
        margin-left: 0;
        margin-bottom: 72px;
        padding: var(--sp-5) var(--sp-4);
    }

    .focus-item {
        grid-template-columns: 1fr;
        gap: var(--sp-2);
    }

    .focus-rank {
        display: none;
    }

    .focus-actions {
        justify-content: flex-end;
    }

    .workload-banner {
        flex-direction: column;
        gap: var(--sp-3);
    }

    .section-header {
        flex-direction: column;
        gap: var(--sp-1);
    }

    .view-top {
        flex-direction: column;
        gap: var(--sp-3);
    }

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

/* ==============================
   Loading Skeleton
   ============================== */

.skeleton {
    background: var(--bg-raised);
    border-radius: var(--r-md);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ==============================
   Success Toast
   ============================== */

.toast {
    position: fixed;
    bottom: var(--sp-6);
    right: var(--sp-6);
    padding: var(--sp-3) var(--sp-5);
    background: var(--navy);
    color: #fff;
    border-radius: var(--r-md);
    font-size: var(--text-sm);
    font-weight: 500;
    z-index: 300;
    transform: translateY(20px);
    opacity: 0;
    transition: transform 0.2s, opacity 0.2s;
    pointer-events: none;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}