/* ============================================================
   Edu-Causal Compass — Apple Design Language Adaptation
   Based on DESIGN.md (Apple HIG analysis)
   ============================================================ */

:root {
    /* Brand & Action */
    --color-primary: #0066cc;
    --color-primary-focus: #0071e3;
    --color-primary-on-dark: #2997ff;

    /* Surface */
    --color-canvas: #ffffff;
    --color-canvas-parchment: #f5f5f7;
    --color-surface-pearl: #fafafc;
    --color-surface-tile-1: #1d1d1f;
    --color-surface-tile-2: #2a2a2c;
    --color-surface-black: #000000;

    /* Text */
    --color-ink: #1d1d1f;
    --color-ink-muted-80: #424245;
    --color-ink-muted-48: #6e6e73;
    --color-body-muted: #cccccc;
    --color-on-dark: #ffffff;

    /* Hairlines */
    --color-divider-soft: #f0f0f0;
    --color-hairline: #d2d2d7;

    /* Data semantic colors — Apple-quietened (low chroma, deep tones) */
    --color-data-critical: #c43e3e;
    --color-data-critical-soft: #fdf4f4;
    --color-data-warning: #9e6b00;
    --color-data-warning-soft: #fbf6e8;
    --color-data-success: #1a7a4c;
    --color-data-success-soft: #f0f8f3;

    /* Typography */
    --font-display: 'SF Pro Display', 'Pretendard Variable', 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, 'Apple SD Gothic Neo', sans-serif;
    --font-text: 'SF Pro Text', 'Pretendard Variable', 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, 'Apple SD Gothic Neo', sans-serif;

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 11px;
    --radius-lg: 18px;
    --radius-pill: 9999px;

    /* Product shadow — the only drop-shadow in the system */
    --product-shadow: 0 3px 5px 0 rgba(0, 0, 0, 0.22), 0 5px 30px 0 rgba(0, 0, 0, 0.12);
}

* {
    -webkit-tap-highlight-color: transparent;
}

html, body {
    font-family: var(--font-text);
    color: var(--color-ink);
    background-color: var(--color-canvas-parchment);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'ss06' on;
    overflow-x: hidden;
}

/* ============================================================
   Typography
   ============================================================ */

.apple-headline {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: -0.022em;
    color: var(--color-ink);
}

.apple-tagline {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 21px;
    line-height: 1.19;
    letter-spacing: 0.011em;
    color: var(--color-ink);
}

.apple-body {
    font-family: var(--font-text);
    font-size: 17px;
    line-height: 1.47;
    letter-spacing: -0.022em;
    color: var(--color-ink);
}

.apple-caption {
    font-family: var(--font-text);
    font-size: 14px;
    line-height: 1.43;
    letter-spacing: -0.016em;
}

.apple-fine-print {
    font-family: var(--font-text);
    font-size: 12px;
    line-height: 1.33;
    letter-spacing: -0.01em;
    color: var(--color-ink-muted-48);
}

.apple-eyebrow {
    font-family: var(--font-text);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.0;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-ink-muted-48);
}

/* ============================================================
   Surfaces & Cards
   ============================================================ */

.apple-card {
    background: var(--color-canvas);
    border: 1px solid var(--color-hairline);
    border-radius: var(--radius-lg);
    transition: border-color 0.2s ease;
}

.apple-card:hover {
    border-color: rgba(0, 0, 0, 0.16);
}

.apple-tile-dark {
    background: var(--color-surface-tile-1);
    color: var(--color-on-dark);
    border-radius: var(--radius-lg);
}

.apple-tile-dark .apple-headline,
.apple-tile-dark .apple-body,
.apple-tile-dark .apple-tagline {
    color: var(--color-on-dark);
}

.apple-tile-dark a,
.apple-tile-dark .apple-link {
    color: var(--color-primary-on-dark);
}

/* ============================================================
   Buttons
   ============================================================ */

.apple-btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--color-primary);
    color: #ffffff;
    font-family: var(--font-text);
    font-size: 15px;
    font-weight: 400;
    letter-spacing: -0.014em;
    border-radius: var(--radius-pill);
    padding: 11px 22px;
    border: none;
    cursor: pointer;
    transition: background-color 0.18s ease, transform 0.12s ease;
}

.apple-btn-primary:hover {
    background: var(--color-primary-focus);
}

.apple-btn-primary:active {
    transform: scale(0.96);
}

.apple-btn-primary:focus-visible {
    outline: 2px solid var(--color-primary-focus);
    outline-offset: 2px;
}

.apple-btn-primary:disabled {
    background: #e8e8ed;
    color: var(--color-ink-muted-48);
    cursor: not-allowed;
}

.apple-btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: transparent;
    color: var(--color-primary);
    font-family: var(--font-text);
    font-size: 14px;
    font-weight: 400;
    letter-spacing: -0.016em;
    border-radius: var(--radius-pill);
    padding: 8px 16px;
    border: 1px solid var(--color-primary);
    cursor: pointer;
    transition: background-color 0.18s ease, transform 0.12s ease;
}

.apple-btn-secondary:hover {
    background: rgba(0, 102, 204, 0.06);
}

.apple-btn-secondary:active {
    transform: scale(0.96);
}

.apple-link {
    color: var(--color-primary);
    font-weight: 400;
    text-decoration: none;
    transition: opacity 0.18s ease;
}

.apple-link:hover {
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* ============================================================
   Global Nav (sticky header)
   ============================================================ */

.apple-nav {
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--color-divider-soft);
}

.apple-nav-brand {
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.022em;
    color: var(--color-ink);
}

/* ============================================================
   Inputs
   ============================================================ */

.apple-input,
.apple-select {
    font-family: var(--font-text);
    font-size: 14px;
    color: var(--color-ink);
    background: var(--color-canvas);
    border: 1px solid var(--color-hairline);
    border-radius: var(--radius-pill);
    padding: 10px 16px;
    transition: border-color 0.18s ease;
}

.apple-input:focus,
.apple-select:focus {
    outline: none;
    border-color: var(--color-primary-focus);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.12);
}

.apple-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%236e6e73' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><path d='M4 6l4 4 4-4'/></svg>");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 16px;
    padding-right: 36px;
    cursor: pointer;
}

/* ============================================================
   Data status pills (4-segment classification)
   ============================================================ */

.apple-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-text);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: -0.006em;
    padding: 2px 0;
    background: transparent;
    white-space: nowrap;
    line-height: 1.4;
}

.apple-pill-critical { color: var(--color-data-critical); }
.apple-pill-warning  { color: var(--color-data-warning); }
.apple-pill-success  { color: var(--color-data-success); }
.apple-pill-neutral  { color: var(--color-ink-muted-48); }
.apple-pill-info     { color: var(--color-primary); }

/* Status dot (for student list rows) */
.apple-status-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.apple-status-dot.critical { background: var(--color-data-critical); }
.apple-status-dot.warning { background: var(--color-data-warning); }
.apple-status-dot.success { background: var(--color-data-success); }
.apple-status-dot.neutral { background: var(--color-ink-muted-48); }

/* ============================================================
   Sidebar student list row
   ============================================================ */

#studentList > div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color 0.15s ease;
    border: 1px solid transparent;
}

#studentList > div:hover {
    background-color: var(--color-canvas-parchment);
}

#studentList > div.is-selected {
    background-color: rgba(0, 102, 204, 0.08);
    border-color: rgba(0, 102, 204, 0.2);
}

#studentList > div .row-id {
    font-family: var(--font-text);
    font-size: 13px;
    font-weight: 500;
    color: var(--color-ink);
    letter-spacing: -0.01em;
}

/* ============================================================
   Pagination
   ============================================================ */

#paginationContainer button {
    font-family: var(--font-text);
    font-weight: 500;
    font-size: 12px;
    letter-spacing: -0.01em;
    color: var(--color-ink);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    min-width: 26px;
    height: 28px;
    padding: 0 6px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
    white-space: nowrap;
}

#paginationContainer button:hover:not(:disabled) {
    background: var(--color-canvas);
    border-color: var(--color-hairline);
}

#paginationContainer button.is-active {
    background: var(--color-ink);
    color: #ffffff;
    border-color: var(--color-ink);
    cursor: default;
}

#paginationContainer button:disabled {
    color: var(--color-body-muted);
    cursor: not-allowed;
}

#paginationContainer .dots {
    color: var(--color-ink-muted-48);
    min-width: 14px;
    text-align: center;
    line-height: 28px;
}

/* ============================================================
   Tab navigation (main & segment)
   ============================================================ */

.apple-tab {
    font-family: var(--font-text);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: -0.016em;
    color: var(--color-ink-muted-48);
    padding: 12px 0;
    margin-right: 28px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: color 0.18s ease, border-color 0.18s ease;
}

.apple-tab:hover {
    color: var(--color-ink);
}

.apple-tab.is-active {
    color: var(--color-ink);
    border-bottom-color: var(--color-ink);
}

.apple-segment-tab {
    font-family: var(--font-text);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: -0.014em;
    color: var(--color-ink-muted-80);
    background: var(--color-canvas);
    border: 1px solid var(--color-hairline);
    border-radius: var(--radius-pill);
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.18s ease;
}

.apple-segment-tab:hover {
    border-color: var(--color-ink);
    color: var(--color-ink);
}

.apple-segment-tab.is-active {
    background: var(--color-ink);
    border-color: var(--color-ink);
    color: #ffffff;
}

/* ============================================================
   LLM Report — typographic cards (Apple style)
   ============================================================ */

.llm-section {
    background: var(--color-canvas);
    border: 1px solid var(--color-hairline);
    border-radius: var(--radius-lg);
    padding: 24px 26px;
    margin-bottom: 16px;
    animation: fadeInUp 0.45s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.llm-section h4 {
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.022em;
    color: var(--color-ink);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.llm-section .llm-body {
    font-family: var(--font-text);
    font-size: 15px;
    line-height: 1.55;
    letter-spacing: -0.014em;
    color: var(--color-ink-muted-80);
}

.llm-section .llm-body strong {
    color: var(--color-ink);
    font-weight: 600;
}

.llm-section .llm-body li {
    margin-left: 18px;
    list-style: disc;
    margin-top: 6px;
}

.llm-section.is-message {
    background: var(--color-canvas-parchment);
}

.llm-section.is-sms .llm-body {
    font-family: var(--font-text);
    font-size: 14px;
    background: var(--color-canvas-parchment);
    padding: 16px 18px;
    border-radius: var(--radius-md);
    color: var(--color-ink);
    line-height: 1.6;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================================
   Scrollbar
   ============================================================ */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.18);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.32);
}

/* ============================================================
   Loading state — quiet pulse
   ============================================================ */

@keyframes apple-pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

.apple-loading-dot {
    animation: apple-pulse 1.4s ease-in-out infinite;
}

/* ============================================================
   Info trigger (in global nav)
   ============================================================ */

.apple-info-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    color: var(--color-ink-muted-80);
    background: var(--color-canvas-parchment);
    border: 1px solid var(--color-hairline);
    cursor: pointer;
    transition: color 0.18s ease, background-color 0.18s ease, border-color 0.18s ease;
    flex-shrink: 0;
}

.apple-info-trigger:hover {
    color: var(--color-ink);
    background: var(--color-canvas);
    border-color: var(--color-ink);
}

.apple-info-trigger:active {
    transform: scale(0.92);
}

/* ============================================================
   Modal — Apple Health/Stocks explainer sheet
   ============================================================ */

.apple-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: backdropFadeIn 0.22s ease-out;
}

.apple-modal-backdrop.hidden {
    display: none;
}

.apple-modal {
    position: relative;
    background: var(--color-canvas);
    border-radius: 22px;
    width: 100%;
    max-width: 560px;
    max-height: calc(100vh - 48px);
    overflow: hidden;
    animation: modalRise 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

.apple-modal-content {
    padding: 36px 36px 32px;
    overflow-y: auto;
    max-height: calc(100vh - 48px);
}

.apple-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--color-divider-soft);
    color: var(--color-ink-muted-80);
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.18s ease, color 0.18s ease;
    z-index: 1;
}

.apple-modal-close:hover {
    background: #e5e5ea;
    color: var(--color-ink);
}

.apple-modal-close:active {
    transform: scale(0.92);
}

@keyframes backdropFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalRise {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Detail expander inside modal */
.apple-detail-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: transparent;
    border: none;
    color: var(--color-primary);
    font-family: var(--font-text);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: -0.014em;
    padding: 4px 0;
    cursor: pointer;
    transition: opacity 0.18s ease;
}

.apple-detail-toggle:hover {
    opacity: 0.7;
}

.apple-detail-toggle i {
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.apple-detail-toggle.is-expanded i {
    transform: rotate(180deg);
}

.apple-detail-section {
    border-top: 1px solid var(--color-divider-soft);
    padding-top: 24px;
    animation: detailExpand 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* ============================================================
   Data source chip (header)
   ============================================================ */

.apple-data-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--color-canvas);
    border: 1px solid var(--color-hairline);
    border-radius: var(--radius-pill);
    padding: 6px 14px;
    font-family: var(--font-text);
    font-size: 12px;
    font-weight: 500;
    color: var(--color-ink);
    letter-spacing: -0.014em;
    cursor: pointer;
    transition: border-color 0.18s ease, background-color 0.18s ease;
}

.apple-data-chip:hover {
    border-color: var(--color-ink);
}

.apple-data-chip:active {
    transform: scale(0.97);
}

/* ============================================================
   Data source mode cards (radio-style)
   ============================================================ */

.apple-source-card {
    background: var(--color-canvas);
    border: 1px solid var(--color-hairline);
    border-radius: 14px;
    padding: 16px 18px;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.18s ease, background-color 0.18s ease;
}

.apple-source-card:hover {
    border-color: var(--color-ink);
}

.apple-source-card .apple-source-check {
    color: var(--color-hairline);
    transition: color 0.18s ease;
}

.apple-source-card.is-active {
    border-color: var(--color-primary);
    background: rgba(0, 102, 204, 0.04);
}

.apple-source-card.is-active .apple-source-check {
    color: var(--color-primary);
}

.apple-source-card:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================================
   CSV dropzone
   ============================================================ */

.apple-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 28px 20px;
    border: 1.5px dashed var(--color-hairline);
    border-radius: 14px;
    background: var(--color-surface-pearl);
    cursor: pointer;
    text-align: center;
    transition: border-color 0.18s ease, background-color 0.18s ease;
}

.apple-dropzone:hover,
.apple-dropzone.is-dragover {
    border-color: var(--color-primary);
    background: rgba(0, 102, 204, 0.04);
}

/* CSV feedback bands */
.apple-feedback {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-hairline);
    font-family: var(--font-text);
    font-size: 13px;
    line-height: 1.5;
    letter-spacing: -0.014em;
}

.apple-feedback.is-error {
    border-color: rgba(196, 62, 62, 0.3);
    color: var(--color-data-critical);
    background: rgba(196, 62, 62, 0.04);
}

.apple-feedback.is-success {
    border-color: rgba(26, 122, 76, 0.3);
    color: var(--color-data-success);
    background: rgba(26, 122, 76, 0.04);
}
