:root {
    --bg-deep: #0a0a1a;
    --bg-navy: #0f0f2a;
    --bg-card: rgba(255, 255, 255, 0.035);
    --bg-glass: rgba(255, 255, 255, 0.05);
    --bg-glass-hover: rgba(255, 255, 255, 0.08);
    --sidebar-bg: rgba(255, 255, 255, 0.03);
    --sidebar-hover: rgba(108, 99, 255, 0.12);
    --sidebar-active: rgba(108, 99, 255, 0.2);
    --border-glass: rgba(108, 99, 255, 0.15);
    --border-strong: rgba(108, 99, 255, 0.25);
    --text: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.6);
    --text-dim: rgba(255, 255, 255, 0.35);
    --accent-purple: #7C5CFC;
    --accent-pink: #FF6584;
    --accent-gradient: linear-gradient(135deg, #7C5CFC, #FF6584);
    --accent-gradient-hover: linear-gradient(135deg, #8C6CFF, #FF7594);
    --danger: #ff4757;
    --danger-bg: rgba(255, 71, 87, 0.12);
    --success: #2ed573;
    --success-bg: rgba(46, 213, 115, 0.12);
    --warning: #ffa502;
    --warning-bg: rgba(255, 165, 2, 0.12);
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 40px rgba(108, 99, 255, 0.08);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-2xl: 24px;
    --sidebar-width: 240px;
    --font: "Noto Sans Thai", "Inter", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; }
html, body {
    margin: 0;
    min-height: 100%;
    font-family: var(--font);
    color: var(--text);
    background:
        linear-gradient(160deg, rgba(10,10,26,0.82), rgba(15,15,42,0.88)),
        url('/static/img/bg-iro.jpg') center / cover no-repeat fixed;
    line-height: 1.5;
}

body {
    position: relative;
    overflow-x: hidden;
}

/* Ambient glow */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 600px 400px at 10% 20%, rgba(124, 92, 252, 0.12), transparent 60%),
        radial-gradient(ellipse 500px 500px at 90% 80%, rgba(255, 101, 132, 0.08), transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* ── Layout ── */

.app-layout {
    display: flex;
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

/* ── Sidebar ── */

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-glass);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 12px 20px;
    border-bottom: 1px solid var(--border-glass);
    margin-bottom: 12px;
}

.sidebar-logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.sidebar-brand-text {
    font-size: 0.7rem;
    color: var(--text-muted);
    line-height: 1.3;
}
.sidebar-brand-text strong {
    color: var(--text);
    font-size: 0.85rem;
    display: block;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.88rem;
    transition: all 0.2s;
    border: none;
    background: none;
    cursor: pointer;
    width: 100%;
    font-family: inherit;
}

.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: var(--text);
}

.sidebar-link.active {
    background: var(--sidebar-active);
    color: var(--text);
    border: 1px solid var(--border-strong);
}

.sidebar-link .icon {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-footer {
    padding-top: 12px;
    border-top: 1px solid var(--border-glass);
}

/* ── Main Content ── */

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ── Top Header ── */

.top-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    border-bottom: 1px solid var(--border-glass);
    background: rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.top-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.top-header-left h1 {
    font-size: 1.3rem;
    font-weight: 600;
}

.top-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: var(--radius-xl);
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    color: var(--text);
    font-size: 0.82rem;
    text-decoration: none;
    transition: all 0.2s;
    font-family: inherit;
    cursor: pointer;
}

.header-pill:hover {
    background: var(--bg-glass-hover);
    border-color: var(--border-strong);
}

.header-pill.logout {
    border-color: rgba(255, 71, 87, 0.25);
    color: var(--danger);
}

.header-pill.logout:hover {
    background: var(--danger-bg);
}

.header-pill .icon {
    font-size: 0.95rem;
}

/* ── Page Content ── */

.page-content {
    padding: 28px 32px;
    flex: 1;
}

/* ── Glass Card ── */

.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-card), var(--shadow-glow);
    transition: all 0.25s;
}

.glass-card:hover {
    border-color: rgba(108, 99, 255, 0.22);
}

/* ── Buttons ── */

.primary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--accent-gradient);
    border: none;
    color: #fff;
    padding: 10px 24px;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.25s;
    border: none;
    line-height: 1.4;
}

.primary-button:hover {
    background: var(--accent-gradient-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(124, 92, 252, 0.3);
}

.secondary-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    color: var(--text);
    padding: 8px 18px;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}

.secondary-button:hover {
    background: var(--bg-glass-hover);
    border-color: var(--border-strong);
}

.ghost-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.ghost-button:hover {
    background: var(--bg-glass);
    color: var(--text);
}

.danger-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--danger-bg);
    border: 1px solid rgba(255, 71, 87, 0.25);
    color: var(--danger);
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.danger-button:hover {
    background: rgba(255, 71, 87, 0.2);
    border-color: rgba(255, 71, 87, 0.4);
}

/* ── Forms ── */

.stack-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.stack-form label {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: -8px;
}

.stack-form input[type="text"],
.stack-form input[type="email"],
.stack-form input[type="date"],
.stack-form input[type="password"],
.stack-form textarea {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    transition: all 0.2s;
    outline: none;
    width: 100%;
}

.stack-form input:focus,
.stack-form textarea:focus {
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 3px rgba(124, 92, 252, 0.15);
    background: rgba(255, 255, 255, 0.06);
}

.stack-form textarea {
    resize: vertical;
    min-height: 80px;
}

.stack-form input::placeholder,
.stack-form textarea::placeholder {
    color: var(--text-dim);
}

/* ── Flash Messages ── */

.flash-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.flash {
    padding: 12px 18px;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    line-height: 1.5;
}

.flash.success {
    background: var(--success-bg);
    border: 1px solid rgba(46, 213, 115, 0.2);
    color: var(--success);
}

.flash.error {
    background: var(--danger-bg);
    border: 1px solid rgba(255, 71, 87, 0.2);
    color: var(--danger);
}

.flash.info {
    background: rgba(54, 164, 255, 0.12);
    border: 1px solid rgba(54, 164, 255, 0.2);
    color: #36a4ff;
}

/* ── Section Kicker ── */

.section-kicker {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--accent-pink);
    margin-bottom: 4px;
    font-weight: 600;
}

/* ── Login Page ── */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    position: relative;
}

.login-container {
    display: flex;
    max-width: 900px;
    width: 100%;
    border-radius: var(--radius-2xl);
    overflow: hidden;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    box-shadow: var(--shadow-card), var(--shadow-glow);
}

.login-left {
    flex: 1;
    padding: 48px 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 20px;
    background: linear-gradient(160deg, rgba(124, 92, 252, 0.06), rgba(255, 101, 132, 0.04));
}

.login-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.login-logo-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.login-left h1 {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.3;
}

.login-left .subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.login-left .features {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

.login-left .feature-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.login-left .feature-item .icon {
    font-size: 1rem;
    width: 24px;
    text-align: center;
}

.login-right {
    flex: 1;
    padding: 48px 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-left: 1px solid var(--border-glass);
}

.login-right h2 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.login-right .login-desc {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 24px;
}

/* ── Dashboard (User) ── */

.dashboard-page {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.welcome-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 28px;
    gap: 20px;
}

.welcome-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.welcome-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.welcome-text h2 {
    font-size: 1.05rem;
    font-weight: 600;
}

.welcome-text p {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.welcome-illustration {
    font-size: 3rem;
    opacity: 0.4;
    flex-shrink: 0;
}

.cert-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.cert-card {
    padding: 20px 24px;
}

.cert-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 8px;
}

.cert-card-header .cert-icon {
    font-size: 1.8rem;
    flex-shrink: 0;
}

.cert-card-header h3 {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
}

.cert-date-badge {
    padding: 4px 12px;
    border-radius: var(--radius-xl);
    background: rgba(124, 92, 252, 0.15);
    border: 1px solid rgba(124, 92, 252, 0.2);
    font-size: 0.8rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.cert-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 16px;
    line-height: 1.6;
}

.cert-files {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cert-file-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-md);
    gap: 12px;
}

.cert-file-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pdf-icon {
    width: 36px;
    height: 42px;
    background: rgba(255, 101, 132, 0.15);
    border: 1px solid rgba(255, 101, 132, 0.25);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.55rem;
    font-weight: 700;
    color: var(--accent-pink);
    letter-spacing: 1px;
    flex-shrink: 0;
    position: relative;
}

.pdf-icon .ribbon {
    position: absolute;
    top: 0;
    right: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 12px 12px 0;
    border-color: transparent var(--accent-pink) transparent transparent;
    border-radius: 0 4px 0 0;
}

.cert-file-info strong {
    font-size: 0.88rem;
}

.cert-file-info span {
    display: block;
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: 1px;
}

.download-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--accent-gradient);
    border: none;
    color: #fff;
    padding: 8px 18px;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.25s;
    white-space: nowrap;
    flex-shrink: 0;
}

.download-btn:hover {
    box-shadow: 0 4px 16px rgba(124, 92, 252, 0.3);
    transform: translateY(-1px);
}

/* ── Admin Grid ── */

.admin-grid {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 24px;
    align-items: start;
}

.admin-card {
    padding: 24px;
}

.admin-card h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
}

/* ── Program List (Admin) ── */

.program-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.program-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

.program-list-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--border-glass);
}

.program-list-content {
    flex: 1;
    min-width: 0;
}

.program-list-content a {
    text-decoration: none;
    color: inherit;
}

.program-list-content strong {
    font-size: 0.9rem;
    display: block;
    margin-bottom: 2px;
}

.program-list-content .muted {
    font-size: 0.78rem;
    color: var(--text-dim);
}

.program-list-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.program-list-meta span {
    font-size: 0.75rem;
    color: var(--text-dim);
    white-space: nowrap;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.04);
}

/* ── Detail Grid ── */

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
}

.detail-grid .full-width {
    grid-column: 1 / -1;
}

.detail-card {
    padding: 24px;
}

.detail-card h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.detail-card .muted {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.detail-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
    flex-wrap: wrap;
}

/* ── Upload Zone ── */

.upload-zone {
    padding: 28px 20px;
    border: 2px dashed var(--border-glass);
    border-radius: var(--radius-lg);
    text-align: center;
    cursor: pointer;
    transition: all 0.25s;
    background: rgba(255, 255, 255, 0.02);
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent-purple);
    background: rgba(124, 92, 252, 0.06);
}

.upload-zone input[type="file"] {
    display: none;
}

.upload-zone p {
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.upload-zone small {
    font-size: 0.75rem;
    color: var(--text-dim);
}

/* ── Table Styling ── */

.table-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.table-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-md);
    gap: 12px;
}

.table-row strong {
    font-size: 0.85rem;
}

.table-row .muted {
    font-size: 0.75rem;
    color: var(--text-dim);
}

.table-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
}

/* ── Inline Edit ── */

details summary {
    cursor: pointer;
    list-style: none;
}
details summary::-webkit-details-marker {
    display: none;
}
details summary h2 {
    display: inline;
}
details summary .edit-hint {
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-left: 8px;
    font-weight: normal;
}

/* ── Empty State ── */

.empty-state {
    padding: 48px 24px;
    text-align: center;
}

.empty-state .icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.empty-state h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 6px;
}

/* ── Status Badge ── */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: var(--radius-xl);
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-purple {
    background: rgba(124, 92, 252, 0.15);
    color: var(--accent-purple);
}

.badge-pink {
    background: rgba(255, 101, 132, 0.15);
    color: var(--accent-pink);
}

/* ── Animations ── */

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

.fade-up {
    animation: fadeUp 0.4s ease-out;
}

.slide-up {
    animation: fadeUp 0.5s ease-out;
}

/* ── Scrollbar ── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-glass); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ── Responsive ── */

@media (max-width: 900px) {
    .login-container {
        flex-direction: column;
        max-width: 480px;
    }
    .login-right {
        border-left: none;
        border-top: 1px solid var(--border-glass);
    }
    .login-left, .login-right {
        padding: 32px 28px;
    }
    .admin-grid {
        grid-template-columns: 1fr;
    }
    .detail-grid {
        grid-template-columns: 1fr;
    }
    .sidebar {
        display: none;
    }
    .top-header {
        padding: 12px 16px;
    }
    .page-content {
        padding: 16px;
    }
}

@media (max-width: 640px) {
    .cert-file-row {
        flex-direction: column;
        align-items: stretch;
    }
    .download-btn {
        justify-content: center;
    }
    .welcome-card {
        flex-direction: column;
        text-align: center;
    }
    .welcome-left {
        flex-direction: column;
    }
    .top-header-right .header-pill span:not(.icon) {
        display: none;
    }
    .login-left .features {
        display: none;
    }
}

/* ── Print ── */

@media print {
    .sidebar, .top-header { display: none; }
    .page-content { padding: 0; }
}
.footer-bar {
    text-align: center;
    padding: 16px 32px 24px;
    font-size: 0.75rem;
    color: var(--text-dim);
    border-top: 1px solid var(--border-glass);
}

.login-flash-wrap {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    width: 90%;
    max-width: 480px;
}
