/* SafeRail Common Layout - Sidebar Menu System */
/* Theme System: Dark (default) / Light / System */

:root {
    /* Layout */
    --sidebar-width: 260px;
    --sidebar-collapsed: 60px;
    --header-height: 56px;

    /* Colors */
    --accent-primary: #667eea;
    --accent-secondary: #764ba2;
    --success: #4ade80;
    --warning: #fbbf24;
    --danger: #f87171;

    /* Typography - Readable Font Sizes (increased for accessibility) */
    --font-2xs: 11px;
    --font-xs: 12px;
    --font-sm: 13px;
    --font-base: 14px;
    --font-md: 15px;
    --font-lg: 16px;
    --font-xl: 18px;
    --font-2xl: 20px;
    --font-3xl: 24px;
    --font-4xl: 32px;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 6px;
    --space-md: 8px;
    --space-lg: 10px;
    --space-xl: 12px;
    --space-2xl: 16px;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 10px;
}

/* Dark Theme (Default) */
:root, [data-theme="dark"] {
    --bg-dark: #0f0f23;
    --bg-darker: #0a0a1a;
    --bg-card: rgba(255,255,255,0.03);
    --bg-body: linear-gradient(135deg, #0f0f23 0%, #1a1a3e 100%);
    --border-color: rgba(255,255,255,0.08);
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --card-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

/* Light Theme */
[data-theme="light"] {
    --bg-dark: #f8fafc;
    --bg-darker: #ffffff;
    --bg-card: rgba(0,0,0,0.02);
    --bg-body: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    --border-color: rgba(0,0,0,0.08);
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --card-shadow: 0 4px 20px rgba(0,0,0,0.08);
}

/* ========== 6 STYLE THEMES ========== */

/* 1. Minimal - 깔끔하고 절제된 */
[data-style="minimal"] {
    --accent-primary: #3b82f6;
    --accent-secondary: #6366f1;
    --card-radius: 8px;
}
[data-style="minimal"][data-theme="light"] {
    --bg-body: #ffffff;
    --bg-card: #f8fafc;
    --border-color: #e2e8f0;
}

/* 2. Glass - 글래스모피즘 */
[data-style="glass"] {
    --accent-primary: #06b6d4;
    --accent-secondary: #8b5cf6;
    --card-radius: 16px;
}
[data-style="glass"] .card,
[data-style="glass"] .stat-card,
[data-style="glass"] .summary-card {
    background: rgba(255,255,255,0.08) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.15) !important;
}
[data-style="glass"][data-theme="light"] .card,
[data-style="glass"][data-theme="light"] .stat-card {
    background: rgba(255,255,255,0.7) !important;
    border: 1px solid rgba(0,0,0,0.1) !important;
}

/* 3. Futuristic - 다크 사이버 느낌 */
[data-style="futuristic"] {
    --accent-primary: #00ffcc;
    --accent-secondary: #ff00ff;
    --bg-body: linear-gradient(135deg, #0a0a1a 0%, #1a0a2e 100%);
}
[data-style="futuristic"] .card,
[data-style="futuristic"] .sidebar {
    border-color: rgba(0,255,204,0.2) !important;
    box-shadow: 0 0 20px rgba(0,255,204,0.1);
}
[data-style="futuristic"] .menu-item.active {
    border-color: #00ffcc !important;
    box-shadow: 0 0 10px rgba(0,255,204,0.3);
}

/* 4. Soft 3D - 뉴모피즘 */
[data-style="soft3d"] {
    --accent-primary: #6366f1;
    --accent-secondary: #a855f7;
    --card-radius: 20px;
}
[data-style="soft3d"][data-theme="light"] {
    --bg-body: #e8eef3;
}
[data-style="soft3d"][data-theme="light"] .card,
[data-style="soft3d"][data-theme="light"] .stat-card,
[data-style="soft3d"][data-theme="light"] .summary-card {
    background: #e8eef3 !important;
    border: none !important;
    box-shadow: 8px 8px 16px #c5ccd3, -8px -8px 16px #ffffff !important;
}

/* 5. Brutal - 굵은 보더, 강렬한 대비 */
[data-style="brutal"] {
    --accent-primary: #facc15;
    --accent-secondary: #f97316;
    --card-radius: 0;
}
[data-style="brutal"] .card,
[data-style="brutal"] .stat-card,
[data-style="brutal"] .summary-card {
    border: 3px solid var(--text-primary) !important;
    border-radius: 0 !important;
    box-shadow: 4px 4px 0 var(--text-primary) !important;
}
[data-style="brutal"] .btn-primary {
    border-radius: 0 !important;
    border: 2px solid #000 !important;
}

/* 6. Enterprise - 전통적 비즈니스 */
[data-style="enterprise"] {
    --accent-primary: #0369a1;
    --accent-secondary: #0891b2;
    --card-radius: 4px;
}
[data-style="enterprise"] .sidebar {
    background: #1e3a5f !important;
}
[data-style="enterprise"][data-theme="light"] .sidebar {
    background: #1e3a5f !important;
    color: #fff;
}
[data-style="enterprise"][data-theme="light"] {
    --bg-body: #f0f4f8;
    --bg-card: #ffffff;
}

/* Theme Toggle Button */
.theme-toggle {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s;
}

.theme-toggle:hover {
    background: rgba(102, 126, 234, 0.1);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Noto Sans KR', -apple-system, sans-serif;
    background: var(--bg-body);
    min-height: 100vh;
    color: var(--text-primary);
    transition: background 0.3s, color 0.3s;
}

[data-theme="light"] .sidebar {
    background: #ffffff;
    border-right-color: rgba(0,0,0,0.08);
}

[data-theme="light"] .main-header {
    background: #ffffff;
    border-bottom-color: rgba(0,0,0,0.08);
}

[data-theme="light"] .card,
[data-theme="light"] .stat-card {
    background: #ffffff;
    border-color: rgba(0,0,0,0.08);
    box-shadow: var(--card-shadow);
}

/* Light theme text colors - ensure dark text on light backgrounds */
[data-theme="light"] body,
[data-theme="light"] .main-content,
[data-theme="light"] .page-content,
[data-theme="light"] .card,
[data-theme="light"] .dashboard,
[data-theme="light"] h1, [data-theme="light"] h2, [data-theme="light"] h3,
[data-theme="light"] h4, [data-theme="light"] h5, [data-theme="light"] h6,
[data-theme="light"] p, [data-theme="light"] span, [data-theme="light"] div,
[data-theme="light"] label, [data-theme="light"] td, [data-theme="light"] th {
    color: var(--text-primary);
}

[data-theme="light"] .text-muted,
[data-theme="light"] .text-secondary {
    color: var(--text-secondary) !important;
}

/* Layout Container */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-darker);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text-primary);
}

.sidebar-logo .logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.sidebar-logo .logo-text {
    font-size: 20px;
    font-weight: 700;
}

.sidebar-logo .logo-text span {
    color: var(--accent-primary);
}

/* Menu */
.sidebar-menu {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
}

.menu-section {
    margin-bottom: 8px;
}

.menu-section-title {
    padding: 8px 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 15px;
    transition: all 0.2s;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.menu-item:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
}

.menu-item.active {
    background: rgba(102, 126, 234, 0.15);
    color: var(--accent-primary);
    border-right: 3px solid var(--accent-primary);
}

.menu-item .icon {
    width: 20px;
    text-align: center;
    font-size: 16px;
}

.menu-item .badge {
    margin-left: auto;
    background: var(--danger);
    color: white;
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 10px;
    font-weight: 600;
}

/* Menu Category */
.menu-category {
    margin-bottom: 16px;
}

.category-header {
    padding: 10px 20px 6px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 0.3px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    margin-bottom: 4px;
}

.menu-item.sub {
    padding: 10px 20px 10px 32px;
    font-size: 14px;
}

.menu-item.sub .icon {
    font-size: 14px;
    opacity: 0.8;
}

/* Submenu */
.menu-group .submenu {
    display: none;
    padding-left: 32px;
}

.menu-group.open .submenu {
    display: block;
}

.menu-group > .menu-item::after {
    content: '›';
    margin-left: auto;
    transition: transform 0.2s;
}

.menu-group.open > .menu-item::after {
    transform: rotate(90deg);
}

.submenu .menu-item {
    padding: 10px 20px;
    font-size: 14px;
}

.submenu .menu-item .icon {
    font-size: 12px;
    opacity: 0.7;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.sidebar-footer .version {
    font-size: 12px;
    color: var(--text-muted);
}

/* Main Content - slightly lighter for distinction from sidebar */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    background: var(--bg-body);
}

/* Dark theme main content gradient */
[data-theme="dark"] .main-content {
    background: linear-gradient(180deg, #12122e 0%, #1a1a42 100%);
}

/* Light theme main content */
[data-theme="light"] .main-content {
    background: var(--bg-body);
}

/* Header */
.main-header {
    height: var(--header-height);
    background: var(--bg-darker);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    padding: 8px 12px;
    transition: all 0.2s;
}

.menu-toggle:hover {
    background: rgba(102, 126, 234, 0.1);
    border-color: var(--accent-primary);
}

.page-title {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.header-btn:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
}

/* Page Content */
.page-content {
    padding: 16px;
}

@media (min-width: 769px) {
    .page-content { padding: 20px; }
}

/* Cards - Ultra Compact Design for Mobile */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
}

@media (min-width: 769px) {
    .card { padding: 16px; margin-bottom: 14px; border-radius: 10px; }
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Grid System - Ultra Compact */
.grid {
    display: grid;
    gap: 8px;
}

@media (min-width: 769px) {
    .grid { gap: 12px; }
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* Responsive */
@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .menu-toggle {
        display: block;
    }

    /* Mobile: Keep 2 columns, readable spacing */
    .grid-4 { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .grid-3 { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .grid-2 { grid-template-columns: repeat(2, 1fr); gap: 8px; }

    .page-content {
        padding: 12px;
    }

    .page-title {
        font-size: 13px;
        max-width: 120px;
    }

    .main-header {
        padding: 0 12px;
        height: 48px;
    }

    .card {
        padding: 12px;
        margin-bottom: 10px;
    }

    .card-title {
        font-size: 15px;
    }

    /* iPhone Safe Area */
    .page-content {
        padding-bottom: env(safe-area-inset-bottom, 12px);
    }

    .main-header {
        padding-top: env(safe-area-inset-top, 0);
    }
}

/* Overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

.sidebar-overlay.show {
    display: block;
}

/* Status Badges */
.status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
}

.status-success { background: rgba(74,222,128,0.15); color: var(--success); }
.status-warning { background: rgba(251,191,36,0.15); color: var(--warning); }
.status-danger { background: rgba(248,113,113,0.15); color: var(--danger); }
.status-info { background: rgba(96,165,250,0.15); color: #60a5fa; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
}

.btn-success {
    background: linear-gradient(135deg, #16a34a, #15803d);
    color: white;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn:hover {
    transform: translateY(-1px);
    opacity: 0.9;
}

/* Control Center - Full Screen Mode */
.fullscreen-mode .sidebar,
.fullscreen-mode .main-header {
    display: none;
}

.fullscreen-mode .main-content {
    margin-left: 0;
}

.fullscreen-mode .page-content {
    padding: 0;
    height: 100vh;
}

/* ========== COLLAPSIBLE SIDEBAR ========== */

/* Sidebar Toggle Button */
.sidebar-toggle {
    position: absolute;
    right: -12px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 48px;
    background: var(--bg-darker);
    border: 1px solid var(--border-color);
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 16px;
    font-weight: bold;
    transition: all 0.2s;
    z-index: 10;
}

.sidebar-toggle:hover {
    background: rgba(102, 126, 234, 0.1);
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

.sidebar-header {
    position: relative;
}

/* Collapsed State */
.sidebar.collapsed {
    width: var(--sidebar-collapsed);
}

.sidebar.collapsed .logo-text,
.sidebar.collapsed .category-header,
.sidebar.collapsed .menu-item .label,
.sidebar.collapsed .menu-item .badge,
.sidebar.collapsed .lea-hint,
.sidebar.collapsed .sidebar-footer .version {
    display: none;
}

.sidebar.collapsed .sidebar-logo {
    justify-content: center;
}

.sidebar.collapsed .menu-item {
    justify-content: center;
    padding: 12px 0;
}

.sidebar.collapsed .menu-item .icon {
    margin: 0;
    font-size: 20px;
}

.sidebar.collapsed .sidebar-toggle {
    right: -12px;
}

.sidebar.collapsed .toggle-icon {
    transform: rotate(180deg);
}

/* Main content adjustment */
body.sidebar-collapsed .main-content {
    margin-left: var(--sidebar-collapsed);
}

/* Tooltip for collapsed menu */
.sidebar.collapsed .menu-item {
    position: relative;
}

.sidebar.collapsed .menu-item::after {
    content: attr(title);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-darker);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 12px;
    white-space: nowrap;
    font-size: 13px;
    color: var(--text-primary);
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
    z-index: 1000;
    margin-left: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.sidebar.collapsed .menu-item:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Badge styles */
.menu-item .badge {
    margin-left: auto;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 9px;
    font-weight: 600;
    color: white;
}

.menu-item .badge.live {
    background: #dc2626;
}

.menu-item .badge.new {
    background: #22c55e;
}

/* Lea button hint */
.menu-item .lea-hint {
    margin-left: auto;
    font-size: 10px;
    color: #a5b4fc;
}

/* Menu bottom section */
.menu-bottom {
    margin-top: auto;
    border-top: 1px solid var(--border-color);
    padding-top: 10px;
}

.lea-btn {
    background: linear-gradient(135deg, rgba(102,126,234,0.15), rgba(118,75,162,0.1)) !important;
}

/* Notification badge */
.notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #f87171;
    color: white;
    font-size: 10px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-btn {
    position: relative;
}

/* Mobile: hide toggle button, show hamburger menu */
@media (max-width: 768px) {
    .sidebar-toggle {
        display: none;
    }

    .sidebar.collapsed {
        width: var(--sidebar-width);
        transform: translateX(-100%);
    }

    body.sidebar-collapsed .main-content {
        margin-left: 0;
    }
}
