/* Global Reset & Base Variables */
:root {
    --primary: hsl(245, 75%, 65%);
    --primary-hover: hsl(245, 75%, 58%);
    --primary-light: hsla(245, 75%, 65%, 0.15);
    
    --bg-dark: hsl(222, 47%, 11%);
    --text-main: hsl(210, 40%, 98%);
    --text-muted: hsl(215, 20%, 65%);
    
    /* Emojis Colors */
    --color-happy: hsl(142, 70%, 50%);
    --color-meh: hsl(45, 100%, 50%);
    --color-frown: hsl(0, 85%, 60%);
    
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    --font-main: 'Prompt', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-thai: 'Sarabun', sans-serif;
}

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

body {
    font-family: var(--font-main);
    background-color: hsl(224, 71%, 4%);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* Background Gradients */
.bg-gradient {
    position: fixed;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    filter: blur(140px);
    z-index: -1;
    pointer-events: none;
    opacity: 0.45;
}

.bg-gradient-1 {
    background: radial-gradient(circle, var(--primary) 0%, transparent 70%);
    top: -200px;
    left: -200px;
}

.bg-gradient-2 {
    background: radial-gradient(circle, hsl(315, 80%, 60%) 0%, transparent 70%);
    bottom: -200px;
    right: -200px;
}

/* Header Styles */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2.5rem;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    background: linear-gradient(135deg, var(--primary) 0%, hsl(270, 80%, 65%) 100%);
    color: white;
    width: 45px;
    height: 45px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 16px rgba(99, 102, 241, 0.3);
}

.logo-icon i {
    width: 24px;
    height: 24px;
}

.logo-text h1 {
    font-size: 1.35rem;
    font-weight: 700;
    background: linear-gradient(135deg, #fff 30%, var(--text-muted) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-text span {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* View Toggle Buttons */
.view-toggle {
    display: flex;
    gap: 0.5rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.35rem;
    border-radius: 30px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.toggle-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    padding: 0.6rem 1.4rem;
    border-radius: 20px;
    font-family: var(--font-main);
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition-fast);
}

.toggle-btn i {
    width: 18px;
    height: 18px;
}

.toggle-btn:hover {
    color: white;
}

.toggle-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

/* Main Container Layout */
.app-container {
    max-width: 1280px;
    margin: 2.5rem auto;
    padding: 0 1.5rem;
}

/* Glassmorphism Card Style */
.card {
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.card-header {
    margin-bottom: 1.8rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding-bottom: 1.2rem;
}

.card-header h2, .card-header h3 {
    font-size: 1.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.card-header h2 i, .card-header h3 i {
    color: var(--primary);
}

.subtitle {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
}

/* View Sections visibility */
.view-section {
    display: none;
    animation: fadeIn var(--transition-smooth) forwards;
}

.view-section.active {
    display: block;
}

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

/* Form Styling */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.form-group label {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.form-group label i {
    width: 16px;
    height: 16px;
    color: var(--primary);
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="url"],
input[type="password"],
select,
textarea {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 0.85rem 1rem;
    color: white;
    font-family: var(--font-thai);
    font-size: 1rem;
    outline: none;
    transition: var(--transition-fast);
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

select option {
    background-color: var(--bg-dark);
    color: white;
}

/* Period Cards Container */
.periods-container {
    margin-top: 2rem;
}

.periods-container h3 {
    font-size: 1.2rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 0.75rem;
}

.periods-container h3 i {
    color: var(--primary);
}

.periods-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 1.5rem;
}

/* Period Card Styling */
.period-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 1.25rem;
    transition: var(--transition-smooth);
    position: relative;
    overflow: hidden;
}

.period-card:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.1);
    transform: translateY(-4px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.period-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.period-number {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
    font-size: 0.9rem;
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    border: 1px solid hsla(245, 75%, 65%, 0.3);
}

/* Emoji Selector (Understanding levels) */
.emoji-selector {
    display: flex;
    justify-content: space-around;
    gap: 0.5rem;
    margin: 1rem 0;
}

.emoji-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 0.6rem 0.4rem;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.emoji-btn span.emoji {
    font-size: 1.6rem;
    transition: transform var(--transition-fast);
}

.emoji-btn span.label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.emoji-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
}

.emoji-btn:hover span.emoji {
    transform: scale(1.2);
}

/* Active Emoji buttons matching level colors */
.emoji-btn.active[data-level="3"] {
    background: hsla(142, 70%, 50%, 0.15);
    border-color: var(--color-happy);
}
.emoji-btn.active[data-level="3"] span.label {
    color: var(--color-happy);
}

.emoji-btn.active[data-level="2"] {
    background: hsla(45, 100%, 50%, 0.15);
    border-color: var(--color-meh);
}
.emoji-btn.active[data-level="2"] span.label {
    color: var(--color-meh);
}

.emoji-btn.active[data-level="1"] {
    background: hsla(0, 85%, 60%, 0.15);
    border-color: var(--color-frown);
}
.emoji-btn.active[data-level="1"] span.label {
    color: var(--color-frown);
}

/* Form buttons and inputs styling inside cards */
.period-card .form-group {
    margin-bottom: 0.75rem;
}

.period-card textarea {
    resize: none;
    font-size: 0.9rem;
    height: 70px;
    padding: 0.5rem 0.75rem;
}

.form-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 2rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 1.5rem;
}

/* Buttons */
.btn {
    border: none;
    border-radius: 12px;
    padding: 0.75rem 1.5rem;
    font-family: var(--font-main);
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: var(--transition-fast);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
}

.btn-success {
    background: hsl(142, 70%, 45%);
    color: white;
}

.btn-success:hover {
    background: hsl(142, 70%, 40%);
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.35);
}

.btn-danger {
    background: hsla(0, 85%, 60%, 0.15);
    color: var(--color-frown);
    border: 1px solid hsla(0, 85%, 60%, 0.25);
}

.btn-danger:hover {
    background: hsla(0, 85%, 60%, 0.25);
}

.btn-large {
    padding: 1rem 2.5rem;
    font-size: 1.1rem;
    border-radius: 14px;
}

.btn-full {
    width: 100%;
}

/* TEACHER DASHBOARD PORTAL */
.auth-card {
    max-width: 480px;
    margin: 4rem auto;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
}

.lock-icon {
    width: 50px;
    height: 50px;
    color: var(--primary);
    background: var(--primary-light);
    border-radius: 50%;
    padding: 0.8rem;
    margin-bottom: 0.5rem;
}

.auth-input-group {
    display: flex;
    gap: 0.5rem;
    width: 100%;
    margin-top: 1rem;
}

.auth-input-group input {
    flex: 1;
}

.error-msg {
    color: var(--color-frown);
    font-size: 0.9rem;
    font-weight: 500;
}

/* Quick Stats Section */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 1.5rem;
    border-radius: 20px;
}

.stat-icon {
    width: 45px;
    height: 45px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.bg-blue { background: hsl(217, 91%, 60%); }
.bg-green { background: var(--color-happy); }
.bg-yellow { background: var(--color-meh); }
.bg-red { background: var(--color-frown); }

.stat-info h3 {
    font-size: 1.45rem;
    font-weight: 700;
}

.stat-info p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Tabs */
.dashboard-tabs {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 0.5rem;
}

.tab-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    padding: 0.75rem 1.25rem;
    font-family: var(--font-main);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
    transition: var(--transition-fast);
}

.tab-btn.active {
    color: white;
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -0.5rem;
    left: 0;
    width: 100%;
    height: 3px;
    background: var(--primary);
    border-radius: 3px;
}

.tab-panel {
    display: none;
    animation: fadeIn var(--transition-smooth) forwards;
}

.tab-panel.active {
    display: block;
}

/* Toolbar & Summary Table */
.table-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1.2rem;
    margin-bottom: 1.5rem;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toolbar-actions {
    display: flex;
    gap: 0.75rem;
}

.summary-table-container {
    overflow-x: auto;
}

.summary-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-family: var(--font-thai);
}

.summary-table th {
    padding: 1rem;
    font-family: var(--font-main);
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 2px solid rgba(255, 255, 255, 0.08);
}

.summary-table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: white;
}

.summary-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* Status badges & grid boxes */
.status-badge {
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    display: inline-block;
}

.status-badge.submitted {
    background: hsla(142, 70%, 50%, 0.15);
    color: var(--color-happy);
}

.status-badge.pending {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
}

.table-period-status {
    display: flex;
    flex-direction: column;
    font-size: 0.8rem;
    gap: 0.2rem;
}

.table-period-status .subj {
    font-weight: 500;
    color: white;
    max-width: 90px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
}

.indicator.good { background: var(--color-happy); }
.indicator.mid { background: var(--color-meh); }
.indicator.poor { background: var(--color-frown); }

/* Student Management Tab Grid */
.student-management-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 2rem;
}

.add-student-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.student-list-container {
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.management-student-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.management-student-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
    padding: 0.75rem 1rem;
    border-radius: 12px;
    transition: var(--transition-fast);
}

.management-student-list li:hover {
    background: rgba(255, 255, 255, 0.04);
}

.student-info-meta {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.student-info-meta .num {
    font-size: 0.8rem;
    color: var(--primary);
    font-weight: 600;
}

.student-info-meta .name {
    font-weight: 500;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    backdrop-filter: blur(8px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    width: 100%;
    max-width: 680px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 2rem;
    box-shadow: 0 25px 50px rgba(0,0,0,0.5);
    animation: zoomIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes zoomIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
}

.close-modal {
    font-size: 1.8rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition-fast);
}

.close-modal:hover {
    color: white;
}

.modal-meta-info {
    display: flex;
    gap: 2rem;
    background: rgba(255, 255, 255, 0.02);
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.modal-periods-detail {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.modal-period-row {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 14px;
    padding: 1.25rem;
}

.modal-period-title {
    display: flex;
    justify-content: space-between;
    font-weight: 600;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 0.5rem;
}

.modal-period-row p {
    font-family: var(--font-thai);
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

.modal-period-row p strong {
    font-family: var(--font-main);
    color: var(--text-muted);
    font-size: 0.85rem;
    display: inline-block;
    width: 120px;
}

/* Cloud Settings elements */
.max-width-600 {
    max-width: 600px;
    margin: 0 auto;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.mode-badge {
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid hsla(245, 75%, 65%, 0.3);
    padding: 0.6rem 1rem;
    border-radius: 10px;
    font-weight: 600;
    display: inline-block;
    text-align: center;
}

.mode-badge.online {
    background: hsla(142, 70%, 50%, 0.1);
    color: var(--color-happy);
    border-color: hsla(142, 70%, 50%, 0.3);
}

.help-text {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Toasts notifications */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid var(--primary);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    z-index: 10000;
    display: none;
    animation: slideUp 0.3s ease;
}

.toast.active {
    display: block;
}

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

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Responsive adjustment */
@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
    
    .table-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .toolbar-actions {
        justify-content: space-between;
    }
}
