:root {
    --primary-color: #0b59a1;
    --primary-hover: #08437a;
    --bg-color: #f4f7fa;
    --card-bg: #ffffff;
    --text-color: #333333;
    --text-muted: #666666;
    --border-color: #e0e0e0;
    --success-color: #28a745;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --kiosk-btn-bg: #28a745;
    --kiosk-btn-hover: #218838;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden !important;
}

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    height: 100vh;
    overflow-y: hidden;
}

/* PC 사이드바 */
.sidebar {
    width: 250px !important;
    min-width: 250px !important;
    max-width: 250px !important;
    background-color: var(--primary-color);
    color: #ffffff;
    display: flex;
    flex-direction: column;
    padding: 16px 0 0 0;
    height: 100vh;
    overflow-y: auto;
    flex-shrink: 0;
    box-sizing: border-box;
}

.sidebar .brand {
    padding: 0 16px 16px 16px;
    font-size: 1.15rem;
    font-weight: bold;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    text-align: center;
    word-break: keep-all;
}

.sidebar-menu { list-style: none; margin-top: 12px; }

.sidebar-menu li {
    padding: 11px 16px;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}

.sidebar-menu li:hover, .sidebar-menu li.active {
    background-color: var(--primary-hover);
    font-weight: bold;
}

.sidebar-menu li.kiosk-btn {
    background-color: var(--kiosk-btn-bg);
    margin: 6px 10px;
    border-radius: 8px;
    padding: 10px 14px;
    font-weight: bold;
}

.sidebar-menu li.kiosk-btn:hover {
    background-color: var(--kiosk-btn-hover);
}

.sidebar-info-container {
    margin-top: 10px;
    padding: 0 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-height: 0;
}

.sidebar-card {
    background-color: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 10px 12px;
    color: #ffffff;
}

.weather-card {
    text-align: center;
    flex-shrink: 0;
}
.weather-date { font-size: 0.76rem; color: #d0e4ff; }
.weather-clock {
    font-size: 1.15rem;
    font-weight: bold;
    margin: 2px 0 4px 0;
    letter-spacing: 1px;
    font-family: 'Courier New', Courier, monospace;
}
.weather-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.15);
    padding: 4px 8px;
    border-radius: 6px;
}

.notice-card {
    font-size: 0.82rem;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    margin-bottom: 6px;
}

.notice-header {
    font-weight: bold;
    font-size: 0.82rem;
    color: #ffe87c;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    padding-bottom: 4px;
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.notice-body {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-right: 2px;
}

.notice-body::-webkit-scrollbar { width: 4px; }
.notice-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

.notice-item {
    background: rgba(255, 255, 255, 0.08);
    padding: 7px 9px;
    border-radius: 6px;
    line-height: 1.4;
}
.notice-item-title { font-weight: bold; color: #ffffff; margin-bottom: 2px; font-size: 0.82rem; }
.notice-item-date { font-size: 0.68rem; color: #a0c4ff; margin-top: 3px; }
.notice-item-empty { text-align: center; color: #c0d8ff; padding: 12px 0; font-size: 0.78rem; }

/* 본문 메인 레이아웃 (스크롤 및 화면 넘침 방지) */
.main-wrapper {
    flex: 1;
    min-width: 0 !important;
    max-width: calc(100vw - 250px);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden !important;
    box-sizing: border-box;
}

.top-header {
    height: 56px;
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
}

.device-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: bold;
    white-space: nowrap;
}
.status-online { background-color: #d4edda; color: #155724; }
.status-offline { background-color: #f8d7da; color: #721c24; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; }
.status-online .status-dot { background-color: var(--success-color); }
.status-offline .status-dot { background-color: var(--danger-color); }

.tab-content { 
    display: none; 
    padding: 16px 20px; 
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}
.tab-content.active { display: block; }

.card {
    background-color: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.03);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.card-title {
    font-size: 1.02rem;
    font-weight: bold;
    margin-bottom: 12px;
    color: var(--primary-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* 🌟 대시보드 2열 1:1 완벽 정렬 그리드 레이아웃 */
.dashboard-2col-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
    gap: 14px;
    align-items: stretch;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.dashboard-top-card {
    height: 100%;
    min-height: 275px;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
}

.dashboard-bottom-card {
    height: 100%;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* 그리드 시스템 */
.grid-2 { 
    display: grid; 
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); 
    gap: 16px; 
}
.grid-dashboard-top {
    display: grid;
    grid-template-columns: 2fr 3fr;
    gap: 16px;
    margin-bottom: 16px;
}

/* 기본 테이블 컨테이너 */
.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
}

/* 학생 관리 및 재무 테이블 내부 세로 스크롤 및 헤더 상단 고정 */
.student-table-scroll {
    max-height: 600px;
    overflow-y: auto;
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    box-sizing: border-box;
}

.student-table-scroll table {
    margin-top: 0;
}

.student-table-scroll thead th {
    position: sticky;
    top: 0;
    background-color: #f8f9fa;
    z-index: 5;
    box-shadow: inset 0 -1px 0 var(--border-color);
}

table { 
    width: 100%; 
    border-collapse: collapse; 
    margin-top: 4px; 
    min-width: 0;
}
th, td { 
    padding: 10px 10px; 
    text-align: left; 
    border-bottom: 1px solid var(--border-color); 
    font-size: 0.88rem; 
    white-space: nowrap; 
}
th { background-color: #f8f9fa; color: var(--text-muted); font-weight: bold; }

#student-list-tbody tr:hover td, #finance-list-tbody tr:hover td, #expense-list-tbody tr:hover td {
    background-color: #eaf4fd !important;
    transition: background-color 0.12s ease-in-out;
}

.filter-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    background-color: #f8f9fa;
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 14px;
    border: 1px solid var(--border-color);
    flex-wrap: wrap;
    width: 100%;
    box-sizing: border-box;
}

.filter-bar select {
    width: auto;
    min-width: 120px;
}

.template-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    background-color: #eef4fb;
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 14px;
    border: 1px solid #b6d4fe;
    flex-wrap: wrap;
    width: 100%;
    box-sizing: border-box;
}

.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: bold; margin-bottom: 5px; color: var(--text-muted); }
input[type="text"], input[type="tel"], input[type="date"], input[type="number"], select, textarea {
    width: 100%; padding: 8px 10px; border: 1px solid var(--border-color); border-radius: 6px; font-size: 0.9rem; outline: none; box-sizing: border-box;
}
textarea { resize: vertical; min-height: 80px; }

.btn-group { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.btn {
    padding: 8px 14px;
    background-color: var(--primary-color);
    color: #ffffff;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.88rem;
}
.btn:hover { background-color: var(--primary-hover); }
.btn-secondary { background-color: #6c757d; }
.btn-secondary:hover { background-color: #5a6268; }
.btn-warning { background-color: #ffc107; color: #212529; }
.btn-warning:hover { background-color: #e0a800; }
.btn-danger { background-color: #dc3545; color: #ffffff; }
.btn-danger:hover { background-color: #bd2130; }
.btn-sm { padding: 4px 8px; font-size: 0.8rem; }

.badge { padding: 3px 6px; border-radius: 4px; font-size: 0.75rem; font-weight: bold; }
.badge-in { background-color: #cce5ff; color: #004085; }
.badge-out { background-color: #d4edda; color: #155724; }
.badge-msg { background-color: #e2e3e5; color: #383d41; }
.badge-sent { background-color: #d4edda; color: #155724; }
.badge-pending { background-color: #fff3cd; color: #856404; }

.pay-day-normal { color: var(--text-color); font-weight: normal; }
.pay-day-warning { color: var(--success-color); font-weight: bold; }
.pay-day-danger { color: var(--danger-color); font-weight: bold; }

/* 모달 */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background-color: rgba(0,0,0,0.5); z-index: 1000; justify-content: center; align-items: center;
    padding: 16px;
}
.modal-content {
    background-color: var(--card-bg); width: 100%; max-width: 580px; border-radius: 12px; padding: 22px; max-height: 90vh; overflow-y: auto; box-sizing: border-box;
}

/* 미니 달력 그리드 */
#mini-calendar-container {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    text-align: center;
}

.cal-header-day {
    font-size: 0.7rem;
    font-weight: bold;
    color: var(--text-muted);
    padding: 3px 0;
}

.cal-day-cell {
    font-size: 0.76rem;
    padding: 5px 1px;
    border-radius: 6px;
    cursor: pointer;
    min-height: 26px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    user-select: none;
    transition: background 0.15s;
}

.cal-day-cell:hover { background-color: #e2e8f0; }
.cal-day-cell.today { background-color: #0b59a1 !important; color: #ffffff !important; font-weight: bold; }
.cal-day-cell.has-event::after {
    content: ''; width: 4px; height: 4px; background-color: #ff9800; border-radius: 50%; margin-top: 1px;
}
.cal-day-cell.today.has-event::after { background-color: #ffffff; }
.cal-day-cell.other-month { color: #ccc; cursor: default; }

/* 오늘의 주요 알림 카드 아이템 스타일 */
.board-notice-item {
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 0.78rem;
    line-height: 1.35;
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.notice-pay { background-color: #fff3cd; border-left: 3px solid #ffc107; color: #856404; }
.notice-event { background-color: #e2e3e5; border-left: 3px solid #0b59a1; color: #1b1e24; }

#today-notice-board::-webkit-scrollbar { width: 4px; }
#today-notice-board::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
#today-notice-board::-webkit-scrollbar-track { background: transparent; }

/* 문자 내용 요약 툴팁 */
.sms-summary-cell {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: help;
}

.sms-tooltip-text {
    border-bottom: 1px dashed #0b59a1;
    color: #333333;
}

.sms-summary-cell:hover .sms-tooltip-text {
    color: #0b59a1;
    font-weight: 500;
}

.badge-retryable {
    cursor: context-menu;
    user-select: none;
    transition: transform 0.15s, box-shadow 0.15s;
}

.badge-retryable:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 5px rgba(255, 193, 7, 0.4);
}

.custom-context-menu {
    display: none;
    position: absolute;
    z-index: 1050;
    background-color: #ffffff;
    border: 1px solid #cce5ff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 210px;
    padding: 6px 0;
    font-size: 0.88rem;
}

.context-menu-header {
    padding: 6px 14px;
    font-size: 0.78rem;
    font-weight: bold;
    color: #666666;
    border-bottom: 1px solid #edf2f7;
    background-color: #f8fafc;
    margin-bottom: 4px;
}

.context-menu-item {
    padding: 9px 14px;
    color: #333333;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s;
    font-weight: 500;
}

.context-menu-item:hover {
    background-color: #eef4fb;
    color: var(--primary-color);
}

#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.custom-toast {
    background-color: rgba(30, 41, 59, 0.95);
    color: #ffffff;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 0.9rem;
    line-height: 1.5;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(4px);
    border-left: 5px solid var(--primary-color);
    max-width: 360px;
    min-width: 240px;
    pointer-events: auto;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    white-space: pre-line;
}

.custom-toast.toast-show {
    opacity: 1;
    transform: translateY(0);
}

.custom-toast.toast-success { border-left-color: var(--success-color); }
.custom-toast.toast-warning { border-left-color: var(--warning-color); }
.custom-toast.toast-error { border-left-color: var(--danger-color); }

/* 재무 통계 테이블 래퍼 */
.stats-table-container {
    max-height: 250px;
    overflow-y: auto;
    overflow-x: visible;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    position: relative;
    width: 100%;
    box-sizing: border-box;
}

.expense-tooltip-cell {
    position: relative;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.expense-tooltip-cell .expense-hover-badge {
    border-bottom: 1.5px dashed #dc3545;
    color: #dc3545;
    font-weight: bold;
    padding-bottom: 1px;
}

.expense-tooltip-cell .expense-popup-box {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 6px;
    background: #0f172a;
    color: #ffffff;
    border-radius: 8px;
    padding: 10px 14px;
    min-width: 230px;
    max-width: 280px;
    font-size: 0.78rem;
    line-height: 1.5;
    box-shadow: 0 12px 28px rgba(0,0,0,0.35);
    z-index: 99999;
    pointer-events: none;
    text-align: left;
    white-space: normal;
    border: 1.5px solid #38bdf8;
}

.expense-tooltip-cell .expense-popup-box::after {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    margin-left: -6px;
    border-width: 6px;
    border-style: solid;
    border-color: transparent transparent #0f172a transparent;
}

.expense-tooltip-cell:hover .expense-popup-box {
    display: block;
    animation: fadeInTooltip 0.18s ease-out;
}

@keyframes fadeInTooltip {
    from { opacity: 0; transform: translate(-50%, -4px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* 반응형 화면 (992px 이하 태블릿 및 모바일) */
@media (max-width: 992px) {
    body {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
    }

    .sidebar {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        height: auto;
        padding: 14px 16px;
        flex-shrink: 0;
    }

    .sidebar .brand {
        padding: 0 0 10px 0;
        font-size: 1.2rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .sidebar-menu {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        margin-top: 8px;
    }

    .sidebar-menu li {
        padding: 8px 12px;
        font-size: 0.85rem;
        border-radius: 6px;
    }

    .sidebar-menu li.kiosk-btn {
        margin: 0;
        padding: 8px 12px;
    }

    .sidebar-info-container {
        display: none;
    }

    .sidebar div[style*="margin-top: auto"] {
        display: flex;
        gap: 8px;
        padding: 10px 0 0 0 !important;
    }

    .main-wrapper {
        max-width: 100vw;
        overflow: visible;
    }

    .top-header {
        padding: 0 16px;
        height: auto;
        min-height: 50px;
        flex-wrap: wrap;
        gap: 8px;
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .tab-content {
        padding: 14px;
    }

    .grid-dashboard-top,
    .grid-2,
    .dashboard-2col-layout {
        grid-template-columns: 1fr !important;
        gap: 14px;
        margin-bottom: 14px;
    }

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-bar select {
        width: 100%;
    }

    .filter-bar div[style*="margin-left: auto"] {
        margin-left: 0 !important;
        display: flex;
        flex-direction: column;
        gap: 6px;
        width: 100%;
    }

    .filter-bar button {
        width: 100%;
    }

    #toast-container {
        left: 16px;
        right: 16px;
        bottom: 16px;
    }
    .custom-toast {
        max-width: 100%;
    }
}