/* =====================================================================
   STOU Smart Hub – global stylesheet (v2.0)
   Used by:  /index.php   /upload.php
   Per-course pages (32209, 32210) keep their own styles.
   ===================================================================== */

:root {
    --primary:        #2563eb;
    --primary-dark:   #1d4ed8;
    --primary-soft:   #eff6ff;
    --accent:         #8b5cf6;
    --success:        #16a34a;
    --warn:           #d97706;
    --danger:         #dc2626;

    --bg:             #f8fafc;
    --bg-elev:        #ffffff;
    --bg-soft:        #f1f5f9;
    --border:         #e2e8f0;
    --border-strong:  #cbd5e1;

    --text:           #0f172a;
    --text-soft:      #475569;
    --text-light:     #94a3b8;

    --shadow-sm:      0 1px 2px rgba(15, 23, 42, .06);
    --shadow:         0 4px 12px rgba(15, 23, 42, .08);
    --shadow-lg:      0 10px 30px rgba(15, 23, 42, .12);

    --radius:         12px;
    --radius-lg:      18px;
    --radius-pill:    999px;

    --container:      1180px;
    --header-h:       64px;
}

/* ---------- Dark theme ---------- */
[data-theme="dark"] {
    --primary-soft:   #1e293b;
    --bg:             #0b1120;
    --bg-elev:        #111a2e;
    --bg-soft:        #0f172a;
    --border:         #1e293b;
    --border-strong:  #334155;
    --text:           #f1f5f9;
    --text-soft:      #cbd5e1;
    --text-light:     #64748b;
    --shadow-sm:      0 1px 2px rgba(0, 0, 0, .3);
    --shadow:         0 4px 12px rgba(0, 0, 0, .4);
    --shadow-lg:      0 10px 30px rgba(0, 0, 0, .5);
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    font-family: 'Kanit', 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition: background-color .3s ease, color .3s ease;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ---------- Top nav ---------- */
.hub-nav {
    position: sticky;
    top: 0;
    z-index: 50;
    background: color-mix(in srgb, var(--bg-elev) 90%, transparent);
    backdrop-filter: saturate(140%) blur(12px);
    -webkit-backdrop-filter: saturate(140%) blur(12px);
    border-bottom: 1px solid var(--border);
    height: var(--header-h);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 max(1rem, calc((100vw - var(--container)) / 2));
}
.hub-brand {
    display: inline-flex; align-items: center; gap: 10px;
    font-size: 1.15rem; font-weight: 500;
    color: var(--text);
}
.brand-mark { font-size: 1.6rem; line-height: 1; }
.brand-text strong { color: var(--primary); }
.hub-actions { display: inline-flex; align-items: center; gap: 10px; }

.icon-btn {
    width: 40px; height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-soft);
    transition: .2s;
}
.icon-btn:hover { background: var(--primary-soft); color: var(--primary); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 0.6rem 1.1rem;
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: 0.95rem; font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: transform .15s, box-shadow .2s, background .2s, border-color .2s;
    white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-lg { padding: 0.85rem 1.5rem; font-size: 1.05rem; border-radius: 12px; }
.btn-sm { padding: 0.45rem 0.85rem; font-size: 0.85rem; }

.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 30%, transparent); }
.btn-primary:hover { background: var(--primary-dark); }

.btn-outline { background: var(--bg-elev); color: var(--text); border-color: var(--border-strong); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.btn-ghost { background: transparent; color: var(--text-soft); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-soft); color: var(--text); }

/* ---------- Layout containers ---------- */
.hub-main {
    max-width: var(--container);
    margin: 0 auto;
    padding: 2.5rem 1rem 4rem;
}

/* ---------- Hero ---------- */
.hero {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 2.5rem;
    align-items: center;
    background:
        radial-gradient(1200px 400px at -10% -20%, color-mix(in srgb, var(--primary) 18%, transparent), transparent 60%),
        radial-gradient(800px 400px at 110% 110%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 60%),
        var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 3rem;
    box-shadow: var(--shadow);
    margin-bottom: 3rem;
}
.eyebrow {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: .85rem; font-weight: 500;
    padding: 5px 14px;
    border-radius: var(--radius-pill);
    margin-bottom: 1rem;
}
.hero h1 {
    font-size: clamp(2rem, 4vw, 2.8rem);
    line-height: 1.2;
    margin: 0 0 1rem;
    font-weight: 600;
}
.grad {
    background: linear-gradient(90deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.hero-text p {
    color: var(--text-soft);
    font-size: 1.1rem;
    margin: 0 0 1.75rem;
    max-width: 480px;
}
.hero-cta { display: flex; flex-wrap: wrap; gap: 12px; }
.hero-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}
.stat {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1rem;
    text-align: center;
    box-shadow: var(--shadow-sm);
}
.stat-num {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.1;
}
.stat-label { font-size: .85rem; color: var(--text-soft); margin-top: 4px; }

/* ---------- Section heads ---------- */
.section-head {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.section-head h2 {
    margin: 0 0 4px;
    font-size: 1.5rem;
    font-weight: 600;
}
.section-head h2 i { color: var(--primary); margin-right: 6px; }
.section-sub { color: var(--text-soft); margin: 0; font-size: 0.95rem; }

/* ---------- Search ---------- */
.search-wrap {
    position: relative;
    flex: 1; max-width: 380px; min-width: 240px;
}
.search-icon {
    position: absolute; left: 14px; top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    pointer-events: none;
}
.search-input {
    width: 100%;
    padding: 12px 50px 12px 40px;
    border: 1px solid var(--border-strong);
    background: var(--bg-elev);
    color: var(--text);
    border-radius: var(--radius-pill);
    font-family: inherit; font-size: .95rem;
    transition: .2s;
}
.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 15%, transparent);
}
.kbd {
    position: absolute; right: 12px; top: 50%;
    transform: translateY(-50%);
    background: var(--bg-soft);
    border: 1px solid var(--border-strong);
    color: var(--text-soft);
    border-radius: 6px;
    padding: 2px 8px;
    font-size: .75rem;
    font-family: ui-monospace, monospace;
}

/* ---------- Course grid ---------- */
.course-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
}
.course-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex; flex-direction: column;
    box-shadow: var(--shadow-sm);
    transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease;
    position: relative;
    overflow: hidden;
}
.course-card::before {
    content: "";
    position: absolute; left: 0; top: 0; bottom: 0;
    width: 4px;
    background: linear-gradient(180deg, var(--primary), var(--accent));
    opacity: 0;
    transition: opacity .25s ease;
}
.course-card:hover {
    transform: translateY(-3px);
    border-color: var(--primary);
    box-shadow: var(--shadow);
}
.course-card:hover::before { opacity: 1; }

.card-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 0.6rem;
}
.course-code {
    font-family: ui-monospace, monospace;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-soft);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: .9rem;
}
.badge {
    font-size: .75rem;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-weight: 500;
    display: inline-flex; align-items: center; gap: 4px;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-warn    { background: #fef3c7; color: #92400e; }
.badge-muted   { background: var(--bg-soft); color: var(--text-light); }
[data-theme="dark"] .badge-success { background: #052e1a; color: #4ade80; }
[data-theme="dark"] .badge-warn    { background: #422006; color: #fbbf24; }

.course-name {
    font-size: 1.1rem;
    margin: 0 0 0.5rem;
    color: var(--text);
    font-weight: 600;
    line-height: 1.4;
}
.course-desc {
    color: var(--text-soft);
    font-size: 0.9rem;
    margin: 0 0 1rem;
    flex-grow: 1;
    /* Clamp to 3 lines */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.card-foot {
    display: flex; align-items: center; justify-content: space-between;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}
.card-meta { font-size: .8rem; color: var(--text-light); }

/* ---------- Progress (per-course on hub card) ---------- */
.progress-wrap { margin-bottom: 0.9rem; }
.progress-meta {
    display: flex; justify-content: space-between;
    font-size: .8rem; color: var(--text-soft);
    margin-bottom: 4px;
}
.progress-bar {
    height: 6px;
    background: var(--bg-soft);
    border-radius: var(--radius-pill);
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: var(--radius-pill);
    transition: width .4s ease;
}

/* ---------- Empty state ---------- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    background: var(--bg-elev);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
}
.empty-state i { font-size: 3rem; color: var(--text-light); margin-bottom: 1rem; }
.empty-state h3 { margin: 0 0 .5rem; }
.empty-state p { color: var(--text-soft); margin: 0 0 1rem; }
.empty-state.mini { padding: 1.5rem; margin-top: 1rem; }
.empty-state.mini i { font-size: 1.5rem; margin: 0 8px 0 0; vertical-align: middle; }

/* ---------- Recent ---------- */
.recent-section { margin-top: 3rem; }
.recent-section h2 { font-size: 1.25rem; margin: 0 0 1rem; }
.recent-section h2 i { color: var(--primary); margin-right: 6px; }
.recent-list { display: flex; flex-wrap: wrap; gap: 10px; }
.recent-chip {
    display: inline-flex; align-items: center; gap: 8px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 8px 16px;
    font-size: .9rem;
    color: var(--text);
    transition: .2s;
}
.recent-chip:hover { border-color: var(--primary); color: var(--primary); }
.recent-chip code {
    font-family: ui-monospace, monospace;
    color: var(--primary);
    background: var(--primary-soft);
    padding: 1px 6px; border-radius: 4px; font-size: .8rem;
}

/* ---------- Footer ---------- */
.hub-footer {
    text-align: center;
    color: var(--text-light);
    font-size: .85rem;
    padding: 2rem 1rem 3rem;
    border-top: 1px solid var(--border);
    margin-top: 3rem;
}
.dot { margin: 0 6px; }

/* ===================================================================
   Upload page (upload.php) – grid of file slots
   =================================================================== */
.navbar {
    height: var(--header-h);
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 max(1rem, calc((100vw - var(--container)) / 2));
}
.navbar .brand {
    color: var(--text);
    font-weight: 500;
    display: inline-flex; align-items: center; gap: 8px;
}
.container {
    max-width: var(--container);
    margin: 0 auto;
    padding: 2rem 1rem;
}
.upload-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}
.file-slot {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow-sm);
    transition: .2s;
}
.file-slot.done { border-color: var(--success); background: color-mix(in srgb, var(--success) 8%, var(--bg-elev)); }
.slot-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.slot-title { font-weight: 600; color: var(--text); }
.slot-status { font-size: .8rem; color: var(--text-light); }
.upload-btn-label {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%;
    padding: 0.6rem;
    background: var(--primary);
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    font-size: .9rem;
    transition: .2s;
}
.upload-btn-label:hover { background: var(--primary-dark); }
.upload-btn-label.disabled {
    background: var(--bg-soft);
    color: var(--text-light);
    pointer-events: none;
    border: 1px dashed var(--border-strong);
}
.mini-progress {
    height: 4px;
    background: var(--bg-soft);
    border-radius: var(--radius-pill);
    margin-top: 8px;
    overflow: hidden;
    display: none;
}
.mini-progress-bar {
    height: 100%; width: 0;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    transition: width .2s;
}

/* ---------- Responsive ---------- */
@media (max-width: 880px) {
    .hero {
        grid-template-columns: 1fr;
        padding: 2rem;
    }
    .hero-stats { grid-template-columns: repeat(3, 1fr); }
    .section-head { flex-direction: column; align-items: stretch; }
    .search-wrap { max-width: 100%; }
}
@media (max-width: 540px) {
    .hub-main { padding: 1.5rem 1rem 3rem; }
    .hero { padding: 1.5rem; }
    .hero h1 { font-size: 1.75rem; }
    .hero-cta .btn-lg { width: 100%; justify-content: center; }
    .brand-text { display: none; }
    .hub-actions .btn span { display: none; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}
