/* ============================================================
   style.css — ระบบบริหารค่ายอบรมเยาวชน
   Design: Dark sidebar + clean white content area
   ============================================================ */

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

:root {
    --sidebar-w: 260px;
    --topbar-h: 56px;

    /* Palette */
    --bg-sidebar:   #0f172a;
    --bg-sidebar-2: #1e293b;
    --accent:       #3b82f6;
    --accent-glow:  rgba(59,130,246,0.18);
    --gold:         #f59e0b;
    --success:      #10b981;
    --danger:       #ef4444;
    --warning:      #f59e0b;

    --bg-page:      #f0f4f8;
    --bg-card:      #ffffff;
    --text-dark:    #0f172a;
    --text-mid:     #475569;
    --text-light:   #94a3b8;
    --border:       #e2e8f0;

    --radius:       12px;
    --radius-sm:    8px;
    --shadow:       0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
    --shadow-lg:    0 8px 30px rgba(0,0,0,.12);

    --font: 'Sarabun', sans-serif;
}

body {
    font-family: var(--font);
    background: var(--bg-page);
    color: var(--text-dark);
    font-size: 15px;
    line-height: 1.6;
}

/* ============================================================
   App Shell Layout
   ============================================================ */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    flex-shrink: 0;
    transition: transform .3s ease;
    z-index: 200;
}

.sidebar-header {
    padding: 24px 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    font-size: 1.8rem;
    line-height: 1;
}

.brand-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.brand-name {
    font-size: .95rem;
    font-weight: 700;
    color: #e2e8f0;
    letter-spacing: .01em;
}

.brand-sub {
    font-size: .75rem;
    color: #64748b;
}

.sidebar-nav {
    padding: 12px 0;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 13px 20px;
    background: none;
    border: none;
    cursor: pointer;
    color: #94a3b8;
    font-family: var(--font);
    font-size: .92rem;
    font-weight: 500;
    text-align: left;
    border-left: 3px solid transparent;
    transition: background .18s, color .18s, border-color .18s;
    position: relative;
}

.nav-item:hover {
    background: rgba(255,255,255,.05);
    color: #e2e8f0;
}

.nav-item.active {
    background: var(--accent-glow);
    color: #60a5fa;
    border-left-color: var(--accent);
    font-weight: 700;
}

.nav-icon { font-size: 1.05rem; flex-shrink: 0; width: 22px; text-align: center; }
.nav-label { flex: 1; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,.07);
    font-size: .72rem;
    color: #475569;
    text-align: center;
}

/* ============================================================
   Main Content
   ============================================================ */
.main-content {
    flex: 1;
    padding: 32px 28px;
    overflow-y: auto;
    min-width: 0;
}

/* ============================================================
   Tab Panes
   ============================================================ */
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ============================================================
   Page Header
   ============================================================ */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 24px;
}

.page-title {
    font-size: 1.45rem;
    font-weight: 800;
    color: var(--text-dark);
    line-height: 1.2;
}

.page-sub {
    font-size: .88rem;
    color: var(--text-mid);
    margin-top: 4px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-dark);
}

.card-title.text-success { color: var(--success); }

.card-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--border);
}

.count-badge {
    background: var(--accent);
    color: #fff;
    font-size: .78rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 99px;
}

.add-form-card {
    padding: 24px;
}

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

/* ============================================================
   Group Score Cards
   ============================================================ */
.group-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 18px;
}

.group-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 22px;
    border-left: 5px solid var(--gold);
    transition: transform .15s, box-shadow .15s;
}

.group-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.group-card-name {
    font-size: .95rem;
    font-weight: 700;
    color: var(--text-mid);
    margin-bottom: 4px;
}

.group-card-score {
    font-size: 2.4rem;
    font-weight: 800;
    color: var(--gold);
    line-height: 1;
    margin-bottom: 4px;
}

.group-card-label {
    font-size: .78rem;
    color: var(--text-light);
    margin-bottom: 16px;
}

.score-buttons {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.score-btn {
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    border: 1.5px solid;
    background: none;
    font-family: var(--font);
    font-weight: 700;
    font-size: .82rem;
    cursor: pointer;
    transition: all .15s;
    line-height: 1;
}

.score-btn.plus {
    border-color: var(--success);
    color: var(--success);
}

.score-btn.plus:hover {
    background: var(--success);
    color: #fff;
}

.score-btn.minus {
    border-color: var(--danger);
    color: var(--danger);
}

.score-btn.minus:hover {
    background: var(--danger);
    color: #fff;
}

/* ============================================================
   Tables
   ============================================================ */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-wrap.scrollable {
    max-height: 480px;
    overflow-y: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}

.data-table thead th {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px 16px;
    font-weight: 600;
    font-size: .83rem;
    white-space: nowrap;
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 1;
}

.data-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background .12s;
}

.data-table tbody tr:hover { background: #f8fafc; }

.data-table td {
    padding: 11px 16px;
    vertical-align: middle;
    color: var(--text-dark);
}

.th-name  { min-width: 160px; }
.th-status { min-width: 240px; }
.th-action { min-width: 160px; text-align: center; }
.th-action-sm { min-width: 80px; text-align: center; }

/* Name bold */
.data-table td.td-name { font-weight: 600; }

/* Group badge */
.badge-group {
    display: inline-block;
    background: #f1f5f9;
    color: #475569;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px 8px;
    font-size: .78rem;
    font-weight: 600;
    white-space: nowrap;
}

/* Score in table */
.score-value {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--accent);
}

/* Score buttons in table */
.score-btn-group {
    display: flex;
    gap: 5px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ============================================================
   Attendance Radio Group
   ============================================================ */
.att-group {
    display: flex;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1.5px solid var(--border);
    width: fit-content;
}

.att-radio { position: absolute; opacity: 0; width: 0; height: 0; }

.att-label {
    padding: 5px 12px;
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-mid);
    background: #fff;
    transition: all .15s;
    white-space: nowrap;
    user-select: none;
    border-right: 1.5px solid var(--border);
}

.att-label:last-child { border-right: none; }
.att-label:hover { background: #f8fafc; }

.att-radio:checked + .att-label.att-present { background: #d1fae5; color: #065f46; }
.att-radio:checked + .att-label.att-absent  { background: #fee2e2; color: #991b1b; }
.att-radio:checked + .att-label.att-leave   { background: #fef9c3; color: #713f12; }

/* ============================================================
   Student Manager Layout
   ============================================================ */
.student-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 20px;
    align-items: start;
}

/* ============================================================
   Forms & Inputs
   ============================================================ */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 9px 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: .9rem;
    color: var(--text-dark);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
    outline: none;
    appearance: none;
}

.form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

.date-input { width: 180px; }
.form-select-custom { cursor: pointer; }

/* ============================================================
   Buttons
   ============================================================ */
.btn-primary, .btn-success, .btn-secondary, .btn-dark, .btn-outline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: .88rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: all .15s;
    text-decoration: none;
}

.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover  { background: #2563eb; }

.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover  { background: #059669; }

.btn-secondary { background: #e2e8f0; color: #475569; }
.btn-secondary:hover { background: #cbd5e1; }

.btn-dark { background: #1e293b; color: #e2e8f0; }
.btn-dark:hover { background: #0f172a; }

.btn-edit {
    padding: 5px 12px;
    border: 1.5px solid var(--accent);
    border-radius: var(--radius-sm);
    background: none;
    color: var(--accent);
    font-family: var(--font);
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
}

.btn-edit:hover { background: var(--accent); color: #fff; }

.w-full { width: 100%; justify-content: center; }
.mb-0 { margin-bottom: 0; }
.flex-1 { flex: 1; }
.mt-4 { margin-top: 16px; }

/* ============================================================
   Print Toolbar
   ============================================================ */
.print-toolbar { padding: 20px 22px; }

.print-filter-row {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    flex-wrap: wrap;
}

.print-btn { align-self: flex-end; }

/* ============================================================
   Mobile Top Bar (hidden on desktop)
   ============================================================ */
.mobile-topbar {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    background: var(--bg-sidebar);
    z-index: 300;
    align-items: center;
    padding: 0 16px;
    gap: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
}

.mobile-title {
    font-size: .95rem;
    font-weight: 700;
    color: #e2e8f0;
}

.hamburger-btn {
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
}

.hamburger-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background: #e2e8f0;
    border-radius: 2px;
    transition: all .2s;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 150;
}

/* ============================================================
   Modal (Custom, no Bootstrap dependency for layout)
   ============================================================ */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.55);
    z-index: 500;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-backdrop.show { display: flex; }

.modal-box {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 460px;
    overflow: hidden;
    animation: modalIn .2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(12px) scale(.97); }
    to   { opacity: 1; transform: none; }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    background: var(--accent);
    color: #fff;
}

.modal-title { font-size: 1rem; font-weight: 700; }

.modal-close {
    background: rgba(255,255,255,.2);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: .85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}

.modal-close:hover { background: rgba(255,255,255,.35); }

.modal-body {
    padding: 22px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 22px;
    background: #f8fafc;
    border-top: 1px solid var(--border);
}

/* ============================================================
   Print Styles
   ============================================================ */
.print-title { display: none; }

@media print {
    body { background: #fff; color: #000; font-size: 13px; }
    .no-print, .sidebar, .mobile-topbar, .modal-backdrop,
    .btn-primary, .btn-success, .btn-secondary, .btn-dark, .btn-edit,
    .score-buttons, .score-btn-group, .att-group, .print-toolbar { display: none !important; }

    .app-shell { display: block; }
    .main-content { padding: 0; }

    .tab-pane { display: none; }
    #print-tab { display: block !important; }

    .print-title { display: block; text-align: center; margin-bottom: 20px; }
    .page-header { display: none; }

    .card { box-shadow: none; border-radius: 0; }
    .data-table { width: 100%; border-collapse: collapse; }
    .data-table thead th { background: #000; color: #fff; padding: 8px; font-size: 12px; }
    .data-table td { border: 1px solid #555; padding: 7px 8px; color: #000; font-size: 12px; }
    .data-table tbody tr:hover { background: none; }
}

/* ============================================================
   Responsive — Tablet (≤992px)
   ============================================================ */
@media (max-width: 992px) {
    .student-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        left: 0; top: 0;
        height: 100%;
        transform: translateX(-100%);
        z-index: 200;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .sidebar-overlay.show { display: block; }

    .mobile-topbar { display: flex; }

    .main-content {
        padding: 80px 16px 24px;
    }
}

/* ============================================================
   Responsive — Mobile (≤576px)
   ============================================================ */
@media (max-width: 576px) {
    .page-title { font-size: 1.15rem; }
    .group-grid { grid-template-columns: 1fr; }
    .group-card-score { font-size: 2rem; }

    .header-actions {
        width: 100%;
    }

    .date-input { flex: 1; min-width: 0; width: auto; }

    .print-filter-row { flex-direction: column; align-items: stretch; }
    .print-btn { width: 100%; justify-content: center; }

    .att-group { width: 100%; }
    .att-label { flex: 1; text-align: center; padding: 5px 6px; font-size: .75rem; }

    .data-table thead th,
    .data-table td { padding: 9px 10px; font-size: .82rem; }
}
