/* ============================================
   Shaiya Version Patcher - 반응형 스타일
   모바일 + 태블릿 + 데스크톱 지원
   ============================================ */

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

:root {
    --primary: #4f46e5; --primary-hover: #4338ca;
    --success: #10b981; --warning: #f59e0b; --danger: #ef4444;
    --bg: #f8fafc; --card-bg: #ffffff;
    --text: #1e293b; --text-muted: #64748b; --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.1);
    --radius: 10px;
    --sidebar-width: 250px;
    --header-height: 60px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans KR', sans-serif;
    background: var(--bg); color: var(--text); line-height: 1.6;
    min-height: 100vh; -webkit-font-smoothing: antialiased;
}

/* 내비게이션 - 모바일 햄버거 */
.navbar {
    background: var(--card-bg); border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow); position: sticky; top: 0; z-index: 100;
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.nav-container {
    max-width: 1280px; margin: 0 auto; padding: 0 16px;
    display: flex; align-items: center; justify-content: space-between;
    height: var(--header-height);
}
.nav-brand {
    font-size: 1.1rem; font-weight: 700; color: var(--primary);
    text-decoration: none; white-space: nowrap;
}
.nav-menu {
    list-style: none; display: flex; align-items: center; gap: 4px;
}
.nav-menu li a {
    text-decoration: none; color: var(--text); padding: 8px 12px;
    border-radius: 8px; font-size: 0.85rem; transition: all 0.2s;
    white-space: nowrap;
}
.nav-menu li a:hover { background: var(--bg); color: var(--primary); }
.nav-user {
    display: flex; align-items: center; gap: 8px; margin-left: 12px;
    padding-left: 12px; border-left: 1px solid var(--border); font-size: 0.85rem;
}
.nav-user span { color: var(--text-muted); }
.btn-logout { color: var(--danger) !important; font-weight: 500; }

/* 햄버거 메뉴 버튼 */
.hamburger {
    display: none; background: none; border: none; cursor: pointer;
    padding: 8px; border-radius: 8px;
}
.hamburger span {
    display: block; width: 22px; height: 2px; background: var(--text);
    margin: 5px 0; transition: 0.3s; border-radius: 2px;
}

/* 메인 */
.main-content {
    max-width: 1280px; margin: 0 auto; padding: 20px 16px;
}

h1 { font-size: 1.5rem; margin-bottom: 16px; }
h2 { font-size: 1.15rem; margin-bottom: 12px; }

/* 카드 */
.card {
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
    box-shadow: var(--shadow);
}
.card-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px; flex-wrap: wrap; gap: 8px;
}

/* 통계 */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px; margin-bottom: 20px;
}
.stat-card {
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; text-align: center;
    box-shadow: var(--shadow); transition: transform 0.2s;
}
.stat-card:active { transform: scale(0.97); }
.stat-icon { font-size: 1.8rem; margin-bottom: 6px; }
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--primary); }
.stat-label { color: var(--text-muted); font-size: 0.8rem; }

/* 테이블 - 모바일 스크롤 */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.table th {
    background: var(--bg); padding: 10px 12px; text-align: left;
    font-weight: 600; font-size: 0.75rem; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.05em;
    border-bottom: 2px solid var(--border); white-space: nowrap;
}
.table td {
    padding: 10px 12px; border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table tr:hover { background: #f8fafc; }
.table tr:active { background: #f1f5f9; }

/* 카드형 모바일 테이블 (작은 화면) */
@media (max-width: 640px) {
    .table-card thead { display: none; }
    .table-card tr {
        display: block; margin-bottom: 12px;
        border: 1px solid var(--border); border-radius: var(--radius);
        padding: 12px; background: var(--card-bg);
    }
    .table-card td {
        display: flex; justify-content: space-between; padding: 6px 0;
        border-bottom: 1px solid #f1f5f9; white-space: normal;
    }
    .table-card td:last-child { border-bottom: none; }
    .table-card td::before {
        content: attr(data-label); font-weight: 600;
        color: var(--text-muted); font-size: 0.75rem;
    }
}

/* 뱃지 */
.badge {
    display: inline-block; padding: 4px 10px; border-radius: 20px;
    font-size: 0.7rem; font-weight: 600; white-space: nowrap;
}
.badge-active { background: #d1fae5; color: #065f46; }
.badge-inactive { background: #fee2e2; color: #991b1b; }

/* 버튼 */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px; padding: 10px 18px; border: 1px solid transparent;
    border-radius: 8px; font-size: 0.85rem; font-weight: 500;
    cursor: pointer; text-decoration: none; transition: all 0.2s;
    touch-action: manipulation; min-height: 40px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover, .btn-primary:active { background: var(--primary-hover); }
.btn-secondary { background: var(--bg); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 0.75rem; min-height: 32px; }
.btn-block { width: 100%; }

/* 폼 */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.85rem;
}
.required { color: var(--danger); }
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="file"],
.form-group textarea {
    width: 100%; padding: 10px 14px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 0.9rem; transition: border-color 0.2s;
    background: #fff; -webkit-appearance: none;
}
.form-group input:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions {
    display: flex; gap: 10px; justify-content: flex-end;
    margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border);
}

/* 파일 업로드 */
.file-upload-area {
    border: 2px dashed var(--border); border-radius: var(--radius);
    padding: 30px 20px; text-align: center; cursor: pointer;
    transition: all 0.2s; position: relative;
}
.file-upload-area input[type="file"] {
    position: absolute; inset: 0; opacity: 0; cursor: pointer;
}
.upload-icon { font-size: 2.5rem; display: block; margin-bottom: 8px; }

/* 플래시 */
.flash {
    padding: 12px 16px; border-radius: 8px; margin-bottom: 16px;
    font-size: 0.85rem; border: 1px solid transparent;
}
.flash-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.flash-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

/* 로그인 페이지 */
.login-page {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 16px;
}
.login-container { width: 100%; max-width: 400px; }
.login-card {
    background: #fff; border-radius: 16px; padding: 32px 24px;
    box-shadow: var(--shadow-lg);
}
.login-header { text-align: center; margin-bottom: 28px; }
.login-header h1 { font-size: 1.3rem; margin-bottom: 6px; }
.login-header p { color: var(--text-muted); font-size: 0.85rem; }
.login-footer-text { text-align: center; margin-top: 20px; color: var(--text-muted); font-size: 0.75rem; }

/* 빈 상태 */
.empty-state { text-align: center; padding: 32px 16px; color: var(--text-muted); }
.empty-state p { font-size: 1rem; margin-bottom: 12px; }

/* 푸터 */
.footer {
    text-align: center; padding: 16px; color: var(--text-muted);
    font-size: 0.8rem; border-top: 1px solid var(--border); margin-top: 32px;
}

/* 서버 상태 페이지 */
.status-indicator {
    display: inline-block; width: 10px; height: 10px;
    border-radius: 50%; margin-right: 6px;
}
.status-online { background: #10b981; animation: pulse 2s infinite; }
.status-offline { background: #ef4444; animation: none; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }
.agent-connected, .agent-disconnected {
    padding: 12px 16px; border-radius: 8px; margin-bottom: 20px;
    font-weight: 500; font-size: 0.85rem; display: flex; align-items: center;
}
.agent-connected { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.agent-disconnected { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }

/* 반응형 - 태블릿 */
@media (max-width: 768px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    h1 { font-size: 1.3rem; }
    .card { padding: 16px; }
    .form-row { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* 반응형 - 모바일 */
@media (max-width: 640px) {
    :root { --header-height: 52px; }
    
    /* 햄버거 메뉴 */
    .hamburger { display: block; }
    .nav-menu {
        display: none; position: fixed; top: var(--header-height);
        left: 0; right: 0; background: var(--card-bg);
        flex-direction: column; padding: 8px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 99;
    }
    .nav-menu.active { display: flex; }
    .nav-menu li { width: 100%; }
    .nav-menu li a { display: block; padding: 12px 16px; }
    .nav-user {
        margin-left: 0; padding-left: 0; border-left: none;
        flex-direction: column; align-items: flex-start; gap: 4px;
        padding: 12px 16px; border-top: 1px solid var(--border);
    }
    
    .main-content { padding: 12px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat-card { padding: 12px; }
    .stat-value { font-size: 1.3rem; }
    
    .table th, .table td { padding: 8px 10px; font-size: 0.75rem; }
    
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; }
    
    .file-upload-area { padding: 20px 16px; }
    .upload-icon { font-size: 2rem; }
    
    .login-card { padding: 24px 16px; }
    
    .agent-connected, .agent-disconnected { flex-direction: column; text-align: center; gap: 6px; }
}

/* 모바일 초소형 */
@media (max-width: 380px) {
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
    .stat-icon { font-size: 1.4rem; }
    .stat-value { font-size: 1.1rem; }
    .btn { padding: 10px 14px; font-size: 0.8rem; }
}
