/* ==========================================================================
   공공주차 관리시스템 - Design System
   깔끔하고 모던한 관리자 UI
   ========================================================================== */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* Colors */
    --primary: #2563eb;
    --primary-light: #eff6ff;
    --primary-dark: #1d4ed8;
    --success: #22c55e;
    --success-light: #f0fdf4;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --info: #3b82f6;
    --info-light: #eff6ff;

    /* Neutrals */
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    /* Layout */
    --sidebar-width: 260px;
    --header-height: 60px;
    --border-radius: 8px;
    --border-radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --transition: all 0.2s ease;
}

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans KR', sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    font-size: 14px;
    line-height: 1.6;
}

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

/* --- Layout --- */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: #fff;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease, transform 0.3s ease;
}

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

.sidebar-header .logo-icon {
    width: 36px; height: 36px;
    background: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-header .logo-icon i { font-size: 16px; color: #fff; }

.sidebar-header .logo-text h2 {
    font-size: 15px; font-weight: 700; color: #fff;
    line-height: 1.2;
}
.sidebar-header .logo-text span {
    font-size: 11px; color: var(--gray-400);
}

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

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

.nav-section {
    padding: 0 12px;
    margin-bottom: 8px;
}

.nav-section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 8px 12px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-radius: 8px;
    color: var(--gray-400);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    margin-bottom: 2px;
}

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

.nav-item.active {
    background: var(--primary);
    color: #fff;
}

.nav-item i {
    width: 20px;
    text-align: center;
    font-size: 14px;
}

.nav-item .badge {
    margin-left: auto;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    padding: 1px 7px;
    border-radius: 10px;
    font-weight: 600;
}

/* --- Main Content --- */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
}

/* --- Header --- */
.top-header {
    height: var(--header-height);
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.top-header .page-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--gray-900);
}

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

.header-btn {
    width: 36px; height: 36px;
    border: none;
    background: var(--gray-100);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray-600);
    transition: var(--transition);
    position: relative;
}

.header-btn:hover { background: var(--gray-200); color: var(--gray-800); }

.header-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px 6px 6px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}
.header-user:hover { background: var(--gray-100); }

.header-user .avatar {
    width: 32px; height: 32px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
}

.header-user .user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
}

.collapse-menu-btn {
    width: 36px; height: 36px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--gray-600);
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: var(--transition);
}
.collapse-menu-btn:hover { background: var(--gray-100); }

/* --- Page Content --- */
.page-content {
    padding: 24px 28px;
    flex: 1;
}

/* --- Cards --- */
.card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--gray-900);
}

.card-body {
    padding: 20px;
}

.card-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--gray-100);
}

/* --- Stat Cards --- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius-lg);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    transition: var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.stat-card .stat-icon {
    width: 44px; height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.stat-card .stat-icon.blue { background: var(--info-light); color: var(--info); }
.stat-card .stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-card .stat-icon.orange { background: var(--warning-light); color: var(--warning); }
.stat-card .stat-icon.red { background: var(--danger-light); color: var(--danger); }
.stat-card .stat-icon.purple { background: var(--primary-light); color: var(--primary); }

.stat-card .stat-info { flex: 1; }
.stat-card .stat-label {
    font-size: 12px; color: var(--gray-500);
    font-weight: 500; margin-bottom: 4px;
}
.stat-card .stat-value {
    font-size: 24px; font-weight: 700;
    color: var(--gray-900); line-height: 1.2;
}
.stat-card .stat-change {
    font-size: 12px; margin-top: 4px;
    display: inline-flex; align-items: center; gap: 2px;
}
.stat-card .stat-change.up { color: var(--success); }
.stat-card .stat-change.down { color: var(--danger); }

/* --- Tables --- */
.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table thead th {
    background: var(--gray-50);
    padding: 10px 14px;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-500);
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

table tbody td {
    padding: 12px 14px;
    font-size: 13px;
    color: var(--gray-700);
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}

table tbody tr:hover {
    background: var(--gray-50);
}

table tbody tr:last-child td {
    border-bottom: none;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--border-radius);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }

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

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

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

.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #d97706; color: #fff; }

.btn-outline {
    background: #fff;
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
}
.btn-outline:hover {
    background: var(--gray-50);
    border-color: var(--gray-400);
    color: var(--gray-700);
}

.btn-ghost {
    background: transparent;
    color: var(--gray-600);
}
.btn-ghost:hover { background: var(--gray-100); }

/* --- Forms --- */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    height: 40px;
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius);
    padding: 0 12px;
    font-size: 13px;
    color: var(--gray-800);
    background: #fff;
    transition: var(--transition);
    outline: none;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

textarea.form-control {
    height: auto;
    padding: 10px 12px;
    resize: vertical;
    min-height: 80px;
}

.form-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* --- Search Bar --- */
.search-bar {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius-lg);
    padding: 16px 20px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: nowrap;
}

/* select 등 고정 요소는 폭 고정 */
.search-bar .form-control {
    flex: 0 0 auto;
    width: auto;
    max-width: 200px;
}
/* 텍스트 검색 input이 남은 영역을 모두 채움 → 검색 버튼은 자연히 맨 우측 */
.search-bar input[type="text"].form-control {
    flex: 1 1 auto;
    width: auto;
    max-width: none;
    min-width: 120px;
}
.search-bar > .btn-primary,
.search-bar .search-btn,
.search-bar .btn {
    flex: 0 0 auto;
    white-space: nowrap;
}

/* --- Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }
.badge-purple { background: #ede9fe; color: #7c3aed; }

/* --- Pagination --- */
.pagination {
    display: flex;
    list-style: none;
    gap: 4px;
    justify-content: center;
    padding: 0;
    margin: 16px 0 0;
}

.page-item .page-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 34px; height: 34px;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    font-size: 13px;
    color: var(--gray-600);
    background: #fff;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    padding: 0 8px;
}

.page-item .page-link:hover {
    background: var(--gray-100);
    border-color: var(--gray-300);
}

.page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
}
.modal-overlay.show { display: flex; }

.modal {
    background: #fff;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    /* 헤더/푸터 고정 + body만 스크롤 */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0; /* 헤더 고정 */
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 700;
}

.modal-close {
    width: 32px; height: 32px;
    border: none; background: none;
    cursor: pointer;
    color: var(--gray-400);
    font-size: 18px;
    border-radius: 6px;
    transition: var(--transition);
}
.modal-close:hover { background: var(--gray-100); color: var(--gray-600); }

.modal-body {
    padding: 24px;
    flex: 1 1 auto;
    overflow-y: auto; /* 내용만 스크롤 */
    min-height: 0;    /* flex 자식 스크롤 필수 */
}
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--gray-100);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-shrink: 0; /* 푸터 고정 */
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--gray-400);
}
.empty-state i { font-size: 48px; margin-bottom: 16px; }
.empty-state p { font-size: 14px; }

/* --- Status dot --- */
.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}
.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--gray-300); }
.status-dot.warning { background: var(--warning); }
.status-dot.error { background: var(--danger); }

/* --- Responsive --- */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }

    .main-content { margin-left: 0; }


    .page-content { padding: 16px; }

    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-card { padding: 14px; }
    .stat-card .stat-value { font-size: 20px; }

    .search-bar { flex-direction: column; align-items: stretch; }
    .search-bar .form-control,
    .search-bar input[type="text"].form-control { max-width: 100%; width: 100%; }

    .top-header { padding: 0 16px; }
    .top-header .page-title { font-size: 16px; }
}

@media (max-width: 480px) {
    .stat-grid { grid-template-columns: 1fr; }
}

/* --- Sidebar overlay (mobile) --- */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.3);
    z-index: 999;
}
.sidebar-overlay.show { display: block; }

/* --- Utility --- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--gray-500); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-primary { color: var(--primary); }
.font-bold { font-weight: 700; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 24px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.flex-wrap { flex-wrap: wrap; }

/* SweetAlert2 z-index 보정 (모달 위에 표시) */
.swal2-container { z-index: 3000 !important; }

/* --- Sidebar Submenu --- */
.nav-group { position: relative; }
.nav-toggle { position: relative; }
.nav-toggle .nav-arrow {
    margin-left: auto;
    font-size: 10px;
    transition: transform 0.2s ease;
    width: auto !important;
}
.nav-group.open > .nav-toggle .nav-arrow { transform: rotate(180deg); }
.nav-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}
.nav-group.open > .nav-submenu { max-height: 200px; }
.nav-sub-item {
    padding-left: 46px !important;
    font-size: 12.5px !important;
}
.nav-sub-item i { font-size: 12px !important; }

/* --- Sidebar Collapsed --- */
.sidebar.collapsed { width: 68px; }
.sidebar.collapsed .logo-text { display: none; }
.sidebar.collapsed .nav-section-title { display: none; }
.sidebar.collapsed .nav-text { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px; }
.sidebar.collapsed .nav-item i { margin: 0; width: auto; font-size: 16px; }
.sidebar.collapsed .nav-item .badge { display: none; }
.sidebar.collapsed .sidebar-header { padding: 20px 16px; justify-content: center; }
.sidebar.collapsed .sidebar-header .logo-icon { margin: 0; }
.sidebar.collapsed .nav-arrow { display: none; }
.sidebar.collapsed .nav-submenu { display: none; }
.app-layout.collapsed .main-content { margin-left: 68px; }
