/* KS Office ERP - Main Stylesheet (Bootstrap 5 + Navy Theme) */

:root {
    --primary: #1e3a5f;
    --primary-hover: #152a45;
    --primary-light: rgba(30, 58, 95, 0.1);
    --navy: #0f2744;
    --bg: #f4f6f9;
    --card: #ffffff;
    --border: #e2e8f0;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #0284c7;
    --text: #1e293b;
    --text-muted: #64748b;
    --sidebar-width: 260px;
    --header-height: 64px;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(15, 39, 68, 0.06), 0 1px 2px rgba(15, 39, 68, 0.04);
    --shadow-lg: 0 4px 6px -1px rgba(15, 39, 68, 0.08), 0 2px 4px -2px rgba(15, 39, 68, 0.05);
}

[data-theme="dark"] {
    --bg: #0f172a;
    --card: #1e293b;
    --border: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Malgun Gothic', 'Apple SD Gothic Neo', system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    margin: 0;
}

/* ===== Layout ===== */
.app-body { min-height: 100vh; }

.app-wrapper {
    display: flex;
    padding-top: var(--header-height);
    min-height: 100vh;
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: margin-left 0.25s ease;
}

.app-content {
    flex: 1;
    padding: 24px;
    max-width: 1600px;
}

.app-footer {
    padding: 16px 24px;
    color: var(--text-muted);
    font-size: 12px;
    border-top: 1px solid var(--border);
    background: var(--card);
}

/* ===== Header ===== */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--navy);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1030;
    box-shadow: var(--shadow-lg);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: #fff;
    font-weight: 600;
}

.header-logo { height: 32px; width: auto; }

.header-brand-text { color: #fff; }

/* 대시보드 컨텍스트 전환 (KS Office / KS Energy) */
.header-context-switch {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 4px;
}

.context-btn {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    color: rgba(255, 255, 255, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.06);
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.context-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.25);
}

.context-btn.active {
    color: #fff;
    border-color: transparent;
}

.context-btn.context-office.active {
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.context-btn.context-energy.active {
    background: linear-gradient(135deg, #065f46 0%, #10b981 100%);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.35);
}

@media (max-width: 575px) {
    .app-header { padding: 0 10px; }
    .header-left { gap: 8px; min-width: 0; }
    .header-context-switch {
        margin-left: 0;
        gap: 4px;
        flex-shrink: 0;
    }
    .context-btn {
        padding: 5px 8px;
        font-size: 11px;
    }
    .header-right { gap: 4px; }
    /* 모바일: 컨텍스트 전환 우선 — 알림·다크모드는 md 이상에서만 */
    .header-right .btn-icon { display: none; }
}

/* KS Energy 대시보드 테마 */
[data-dashboard="energy"] .welcome-banner {
    background: linear-gradient(135deg, #065f46 0%, #047857 50%, #0f766e 100%);
}

[data-dashboard="energy"] .stat-primary .stat-icon { background: rgba(16, 185, 129, 0.15); color: #059669; }
[data-dashboard="energy"] .stat-primary { border-left-color: #10b981; }

.header-page-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    color: #fff;
}

.header-search {
    position: relative;
    width: 280px;
}

.header-search i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.header-search input {
    padding-left: 36px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 13px;
}

.header-search input::placeholder { color: rgba(255, 255, 255, 0.5); }
.header-search input:focus {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
    color: #fff;
    box-shadow: none;
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.75);
    border-radius: 8px;
    position: relative;
}

.btn-icon:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }

.badge-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background: var(--danger);
    border-radius: 50%;
}

.btn-profile {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 4px 12px 4px 4px;
    font-size: 13px;
    color: #fff;
}

.btn-profile:hover, .btn-profile:focus {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.profile-avatar {
    width: 32px;
    height: 32px;
    background: var(--primary);
    color: #fff;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.sidebar-toggle { color: #fff !important; }

/* Sidebar 컨텍스트 표시 */
.sidebar-context {
    padding: 16px 16px 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
}

.sidebar-context-badge {
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 6px;
    color: #fff;
}

.sidebar-context-badge.context-office {
    background: linear-gradient(135deg, #1e3a5f, #2563eb);
}

.sidebar-context-badge.context-energy {
    background: linear-gradient(135deg, #065f46, #10b981);
}

.sidebar-context-desc {
    display: block;
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Energy 사이드바 활성 색상 */
.sidebar-energy .sidebar-link.active {
    background: rgba(16, 185, 129, 0.12);
    color: #059669;
}

[data-dashboard="energy"] {
    --primary: #047857;
    --primary-light: rgba(16, 185, 129, 0.12);
}

/* ===== Sidebar ===== */
.app-sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    background: var(--card);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    z-index: 1020;
    transition: transform 0.25s ease;
}

.sidebar-menu {
    list-style: none;
    padding: 12px;
    margin: 0;
}

.sidebar-divider {
    height: 1px;
    margin: 10px 14px;
    background: var(--border-color, #dee2e6);
    pointer-events: none;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.15s ease;
}

.sidebar-link i { font-size: 18px; width: 20px; text-align: center; }

.sidebar-link:hover {
    background: var(--bg);
    color: var(--text);
}

.sidebar-link.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 500;
}

.sidebar-link.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border: none;
    background: transparent;
    text-align: left;
}

.sidebar-toggle-group {
    border: none;
    background: transparent;
}

.sidebar-submenu {
    list-style: none;
    padding: 0 0 4px 0;
    margin: 0 0 0 12px;
}

.sidebar-sublink {
    padding: 8px 14px 8px 36px !important;
    font-size: 13px;
}

.sidebar-group .toggle-icon {
    font-size: 12px;
    transition: transform 0.2s;
}

.sidebar-group .sidebar-toggle-group[aria-expanded="true"] .toggle-icon {
    transform: rotate(180deg);
}

/* 빠른메뉴 */
.quick-menu {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.quick-menu-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100px;
    height: 88px;
    border: 1px solid var(--border);
    border-radius: 10px;
    text-decoration: none;
    color: var(--text);
    font-size: 12px;
    gap: 8px;
    transition: border-color 0.15s, background 0.15s;
}

.quick-menu-item i { font-size: 22px; color: var(--primary); }

.quick-menu-item:hover:not(.disabled) {
    border-color: var(--primary);
    background: var(--primary-light);
}

.quick-menu-item.disabled {
    opacity: 0.45;
    pointer-events: none;
}

.badge-soon {
    margin-left: auto;
    font-size: 10px;
    padding: 2px 6px;
    background: var(--bg);
    border-radius: 4px;
    color: var(--text-muted);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1010;
}

/* ===== Welcome Banner ===== */
.welcome-banner {
    background: linear-gradient(135deg, var(--navy) 0%, var(--primary) 100%);
    border-radius: var(--radius);
    padding: 24px 28px;
    color: #fff;
}

.welcome-title {
    font-size: 22px;
    font-weight: 700;
    margin: 0 0 4px;
}

.welcome-subtitle {
    opacity: 0.85;
    font-size: 14px;
}

.welcome-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    flex-shrink: 0;
}

/* ===== Cards ===== */
.app-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.app-card .card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 16px 20px;
}

.app-card .card-body { padding: 20px; }

.card-title { font-size: 15px; font-weight: 600; }

/* ===== Stats ===== */
.stat-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.stat-primary .stat-icon { background: var(--primary-light); color: var(--primary); }
.stat-success .stat-icon { background: rgba(5, 150, 105, 0.1); color: var(--success); }
.stat-warning .stat-icon { background: rgba(217, 119, 6, 0.1); color: var(--warning); }
.stat-info .stat-icon { background: rgba(2, 132, 199, 0.1); color: var(--info); }

.stat-label { display: block; font-size: 13px; color: var(--text-muted); }
.stat-value { display: block; font-size: 28px; font-weight: 700; line-height: 1.2; color: var(--text); }

.badge-type {
    font-size: 11px;
    font-weight: 500;
    background: var(--primary-light);
    color: var(--primary);
}

/* ===== Tables ===== */
.app-table thead th {
    background: var(--bg);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    white-space: nowrap;
}

.app-table tbody td {
    padding: 14px 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
}

.app-table tbody tr:last-child td { border-bottom: none; }
.app-table tbody tr:hover { background: rgba(30, 58, 95, 0.02); }

/* ===== Forms ===== */
.form-label { font-weight: 500; font-size: 13px; margin-bottom: 6px; }
.form-label.required::after { content: ' *'; color: var(--danger); }

.form-control, .form-select {
    border-radius: 8px;
    border: 1px solid var(--border);
    padding: 8px 12px;
    font-size: 14px;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* ===== Buttons ===== */
.btn {
    border-radius: 8px;
    font-weight: 500;
    font-size: 14px;
    padding: 8px 16px;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover, .btn-primary:focus {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-lg { padding: 12px 24px; }

/* ===== Page ===== */
.page-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.page-header { margin-bottom: 20px; }
.page-title { font-size: 20px; font-weight: 600; margin: 0; }

.list-item-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px !important;
}

.item-title { font-weight: 500; }
.item-date { color: var(--text-muted); font-size: 12px; }

.empty-state { text-align: center; color: var(--text-muted); }

/* ===== Auth (Login) ===== */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #e8eef5 0%, var(--bg) 50%, #f0f4f8 100%);
}

.auth-container { width: 100%; max-width: 420px; padding: 20px; }

.auth-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px 32px;
    box-shadow: var(--shadow-lg);
}

.auth-logo { text-align: center; margin-bottom: 32px; }

.auth-logo-icon {
    width: 64px;
    height: 64px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    margin-bottom: 16px;
}

.auth-title { font-size: 20px; font-weight: 700; margin: 0 0 4px; color: var(--navy); }
.auth-subtitle { color: var(--text-muted); font-size: 13px; margin: 0; }

.auth-form .input-group-text {
    background: var(--bg);
    border-color: var(--border);
    color: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); }
    .app-sidebar.show { transform: translateX(0); }
    .sidebar-overlay.show { display: block; }
    .app-main { margin-left: 0; }
}

@media (max-width: 767.98px) {
    .app-content { padding: 16px; }
    .stat-value { font-size: 22px; }
    .welcome-title { font-size: 18px; }
}

/* ===== Dark mode ===== */
[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select {
    background: #0f172a;
    color: var(--text);
    border-color: var(--border);
}

[data-theme="dark"] .app-table thead th { background: #0f172a; }
[data-theme="dark"] .app-table tbody tr:hover { background: rgba(255, 255, 255, 0.03); }
[data-theme="dark"] .dropdown-menu { background: var(--card); border-color: var(--border); }
[data-theme="dark"] .dropdown-item { color: var(--text); }

/* ===== KS Energy — Phase 3 UX ===== */
.btn-energy {
    background: linear-gradient(135deg, #059669, #047857);
    border: none;
    color: #fff;
    font-weight: 600;
}
.btn-energy:hover { background: linear-gradient(135deg, #047857, #065f46); color: #fff; }

.energy-page-header .energy-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: #059669;
    background: rgba(16, 185, 129, 0.12);
    padding: 4px 10px;
    border-radius: 20px;
}

.energy-stat-card { border-left: 4px solid #10b981; }
.energy-quick-menu .quick-menu-item:not(.disabled):hover {
    border-color: #10b981;
    color: #059669;
}

.stage-badge {
    background: color-mix(in srgb, var(--stage-color, #64748b) 15%, white);
    color: var(--stage-color, #64748b);
    border: 1px solid color-mix(in srgb, var(--stage-color, #64748b) 30%, white);
}

.project-pipeline {
    display: flex;
    align-items: flex-start;
    overflow-x: auto;
    padding-bottom: 4px;
    gap: 0;
}
.pipeline-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 72px;
    flex-shrink: 0;
}
.pipeline-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #e2e8f0;
    border: 2px solid #cbd5e1;
    margin-bottom: 6px;
}
.pipeline-step.done .pipeline-dot,
.pipeline-step.current .pipeline-dot {
    background: var(--step-color, #10b981);
    border-color: var(--step-color, #10b981);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--step-color, #10b981) 25%, transparent);
}
.pipeline-step.current .pipeline-label { font-weight: 700; color: var(--step-color, #059669); }
.pipeline-label { font-size: 11px; text-align: center; color: var(--text-muted); white-space: nowrap; }
.pipeline-connector {
    flex: 1;
    min-width: 20px;
    height: 2px;
    background: #e2e8f0;
    margin-top: 6px;
    align-self: flex-start;
}
.pipeline-connector.active { background: #10b981; }

.stage-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
}
.stage-summary-item {
    text-align: center;
    padding: 12px 8px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--stage-color, #64748b) 8%, white);
    border: 1px solid color-mix(in srgb, var(--stage-color, #64748b) 20%, white);
}
.stage-summary-count { font-size: 22px; font-weight: 700; color: var(--stage-color, #059669); }
.stage-summary-name { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.energy-tabs .nav-link.active {
    color: #059669;
    border-color: #dee2e6 #dee2e6 #fff;
    font-weight: 600;
}
.energy-table thead { background: rgba(16, 185, 129, 0.06); }

.energy-progress .progress-bar { background: linear-gradient(90deg, #10b981, #059669); }

[data-theme="dark"] .dropdown-item:hover { background: #0f172a; }
[data-theme="dark"] .app-header { background: #0a1628; }
[data-theme="dark"] .welcome-banner { background: linear-gradient(135deg, #0a1628 0%, var(--primary) 100%); }
