/* ============================================================
   AuthenCenter — Stylesheet
   Font: Prompt (Google Fonts) — โหลดผ่าน <link> ใน <head> ของทุกหน้า
   ============================================================ */

:root {
    --primary: #1d4ed8;          /* blue-700 */
    --primary-dark: #1e3a8a;     /* blue-900 */
    --primary-light: #3b82f6;    /* blue-500 */
    --gradient-from: #2563eb;    /* blue-600 */
    --gradient-to: #1e3a8a;      /* blue-900 */
    --bg: #f1f5f9;               /* slate-100 (เย็นสว่าง) */
    --card: #ffffff;
    --border: #cbd5e1;           /* slate-300 */
    --text: #0f172a;             /* slate-900 */
    --muted: #475569;            /* slate-600 */
    --success: #059669;
    --danger:  #dc2626;
    --warning: #d97706;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Prompt', 'Sarabun', 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* ─── Login Page ──────────────────────────── */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--gradient-from) 0%, var(--gradient-to) 100%);
    padding: 20px;
}

.login-card {
    background: white;
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.login-header {
    text-align: center;
    margin-bottom: 28px;
}

.login-header .logo {
    font-size: 48px;
    margin-bottom: 8px;
}

.login-header h1 {
    margin: 0;
    font-size: 28px;
    color: var(--text);
}

.login-header .org {
    color: var(--muted);
    margin: 4px 0 0;
    font-size: 14px;
}

.login-card label {
    display: block;
    margin-bottom: 16px;
}

.login-card label > span {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
}

.login-card .hint {
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    margin-top: 16px;
}

.login-card .hint code {
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
}

.footer-text {
    text-align: center;
    color: var(--muted);
    font-size: 12px;
    margin-top: 24px;
    margin-bottom: 0;
}

/* ─── Form ─────────────────────────────────── */
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], select, textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    background: white;
    color: var(--text);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

input[disabled] {
    background: var(--bg);
    color: var(--muted);
}

label {
    display: block;
    margin-bottom: 14px;
}

label > span {
    display: block;
    margin-bottom: 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: normal;
}

.checkbox-label input { width: auto; }
.checkbox-label span { margin: 0; font-size: 14px; }

button, .btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    display: inline-block;
}

button:hover, .btn-primary:hover {
    background: var(--primary-dark);
    text-decoration: none;
}

.btn-secondary {
    background: white;
    color: var(--primary);
    border: 1px solid var(--primary);
    padding: 9px 18px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    display: inline-block;
}
.btn-secondary:hover {
    background: #eff6ff;
    text-decoration: none;
}

.header-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.login-card button {
    width: 100%;
    padding: 12px;
    font-size: 16px;
}

.form-actions {
    margin-top: 16px;
    display: flex;
    gap: 12px;
    align-items: center;
}

/* ─── Flash messages ───────────────────────── */
.flash {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}
.flash-success { background: #d1fae5; color: #065f46; }
.flash-error   { background: #fee2e2; color: #991b1b; }
.flash-warning { background: #fef3c7; color: #92400e; }
.flash-info    { background: #dbeafe; color: #1e40af; }

/* ─── Topbar ───────────────────────────────── */
.topbar {
    background: white;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.topbar-admin {
    background: linear-gradient(90deg, var(--gradient-to) 0%, #172554 100%);
    color: white;
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 17px;
}

.topbar-admin .brand { color: white; }

.brand-icon { font-size: 22px; }

.topbar nav {
    display: flex;
    gap: 20px;
    align-items: center;
}

.topbar nav a {
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 6px;
}

.topbar-admin nav a { color: #cbd5e1; }
.topbar-admin nav a:hover { background: rgba(255,255,255,0.12); color: white; text-decoration: none; }
.topbar-admin nav a.active { background: var(--primary); color: white; }

.topbar nav a.logout {
    color: var(--danger);
}

/* ─── Welcome Card ──────────────────────────── */
.welcome-card {
    background: linear-gradient(135deg, var(--gradient-from) 0%, var(--gradient-to) 100%);
    color: white;
    padding: 32px;
    border-radius: 16px;
    margin-bottom: 32px;
    box-shadow: 0 8px 24px rgba(30, 58, 138, 0.25);
}

.welcome-card h1 { margin: 0 0 8px; }
.welcome-card p  { margin: 0; opacity: 0.95; }

/* ─── Badge ─────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}
.badge-student { background: #dbeafe; color: #1e40af; }
.badge-teacher { background: #d1fae5; color: #065f46; }
.badge-staff   { background: #fef3c7; color: #92400e; }
.badge-admin   { background: #fce7f3; color: #9d174d; }
.badge-inactive { background: #f1f5f9; color: #94a3b8; padding: 2px 6px; font-size: 11px; margin-left: 4px; }

/* แถวที่ user ถูกปิดใช้งาน */
.row-inactive td { opacity: 0.55; }

/* meta info แสดงใต้ title ในหน้า edit user */
.meta-info {
    display: flex;
    flex-wrap: wrap;
    gap: 18px 28px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 13px;
    color: var(--muted);
}
.meta-info strong { color: var(--text); margin-right: 4px; }

/* ─── Section title ────────────────────────── */
.section-title {
    font-size: 18px;
    margin: 24px 0 12px;
    color: var(--text);
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

/* ─── App Grid ──────────────────────────────── */
.app-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

.app-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    transition: all 0.2s;
    color: var(--text);
    text-decoration: none;
    display: block;
}

.app-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0,0,0,0.1);
    text-decoration: none;
    border-color: var(--primary);
}

.app-icon {
    font-size: 40px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 56px;
}
.app-icon img {
    max-height: 56px;
    max-width: 56px;
    object-fit: contain;
}

/* admin/apps icon thumb */
.icon-thumb {
    width: 32px;
    height: 32px;
    object-fit: contain;
    border-radius: 6px;
    background: white;
}
.icon-default { font-size: 22px; }
.icon-cell { width: 40px; text-align: center; }

/* Avatar in profile */
.avatar-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}
.avatar-display {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--bg);
    border: 3px solid var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
}
.avatar-display img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.avatar-fallback {
    font-size: 48px;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
}
.avatar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}
.avatar-actions form { margin: 0; }
.avatar-actions input[type=file] { width: 180px; font-size: 13px; }

/* Security row (2FA toggle) */
.security-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px;
    background: var(--bg);
    border-radius: 8px;
    flex-wrap: wrap;
}

/* fieldset สิทธิ์การมองเห็น app */
.access-fieldset {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 16px;
    margin: 14px 0;
}
.access-fieldset legend {
    padding: 0 8px;
    font-weight: 600;
    color: var(--text);
    font-size: 14px;
}
.access-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    margin-bottom: 10px;
}
.access-row:last-child { margin-bottom: 0; }
.access-label {
    font-size: 13px;
    color: var(--muted);
    min-width: 110px;
}
.checkbox-inline {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 14px;
    cursor: pointer;
}
.checkbox-inline input { width: auto; margin: 0; }

/* form preview ของ icon ปัจจุบัน */
.icon-preview-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    padding: 8px;
    background: var(--bg);
    border-radius: 6px;
}
.icon-preview {
    width: 48px;
    height: 48px;
    object-fit: contain;
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px;
}
.app-name { font-weight: 600; }
.app-desc { font-size: 13px; color: var(--muted); margin-top: 4px; }

.empty-state {
    background: white;
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 40px;
    text-align: center;
    color: var(--muted);
}

/* ─── Cards / Grid ─────────────────────────── */
.card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 16px;
}

.card h2 { margin-top: 0; font-size: 18px; }

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
}

.form-stack label { margin-bottom: 14px; }

.extra-fields {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}
.extra-fields h3 { margin-top: 0; font-size: 16px; }

/* ─── Stats ─────────────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin: 20px 0;
}

.stat-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
}

.stat-highlight {
    background: linear-gradient(135deg, var(--gradient-from) 0%, var(--gradient-to) 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(30, 58, 138, 0.2);
}

.stat-label {
    font-size: 13px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-highlight .stat-label { color: rgba(255,255,255,0.85); }

.stat-value {
    font-size: 32px;
    font-weight: 700;
    margin-top: 4px;
}

/* ─── Tables ────────────────────────────────── */
.data-table {
    width: 100%;
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
}

.data-table th, .data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.data-table th {
    background: var(--bg);
    font-weight: 600;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fafbfc; }

.data-table.compact th, .data-table.compact td {
    padding: 8px 12px;
    font-size: 13px;
}

.data-table code {
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.actions { white-space: nowrap; }
.actions a, .actions .link-btn { margin-right: 8px; }

.text-muted { color: var(--muted); font-size: 12px; }

.empty-row { text-align: center; color: var(--muted); padding: 30px; }

.status-active { color: var(--success); font-weight: 600; }
.status-inactive { color: var(--muted); }

.link-btn {
    background: none;
    border: none;
    color: var(--primary);
    padding: 0;
    font-size: 14px;
    cursor: pointer;
    font-family: inherit;
}
.link-btn:hover { text-decoration: underline; background: none; }
.link-danger { color: var(--danger); }
.link-muted { color: var(--muted); }

/* ─── Filter Bar ───────────────────────────── */
.filter-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 16px;
    background: white;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.filter-bar input, .filter-bar select {
    width: auto;
    flex: 0 1 250px;
}
.filter-bar button { padding: 10px 16px; }

/* ─── Pagination ───────────────────────────── */
.pagination-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;
    gap: 12px;
    flex-wrap: wrap;
}
.pagination-bar .text-muted { font-size: 13px; }

.pagination {
    display: flex;
    gap: 4px;
    justify-content: center;
}
.pagination .ellipsis {
    padding: 6px 8px;
    color: var(--muted);
    font-size: 13px;
}
.pagination a {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
}
.pagination a.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.pagination a:hover { text-decoration: none; background: var(--bg); }
.pagination a.active:hover { background: var(--primary-dark); }
