/* ==========================================
 * InsureMate - 공통 스타일
 * Twenty Design Tokens 의존: css/twenty-tokens.css 먼저 로드 필수
 * ========================================== */

/* 기본 리셋 */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans KR', 'Malgun Gothic', sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* 스크롤바 스타일 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* 서비스 카드 호버 효과 */
.service-card {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.service-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 40px -12px rgba(0, 0, 0, 0.15);
}

/* 카드 편집 모드 */
.service-card.edit-mode-card {
    animation: card-wiggle 0.4s ease-in-out;
}

.service-card.edit-mode-card:hover {
    transform: scale(1.02);
    box-shadow: 0 8px 25px -5px rgba(37, 99, 235, 0.25);
}

.service-card.drag-over {
    border-color: #2563eb !important;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
    transform: scale(1.03);
}

@keyframes card-wiggle {
    0% { transform: rotate(0deg); }
    25% { transform: rotate(-0.5deg); }
    75% { transform: rotate(0.5deg); }
    100% { transform: rotate(0deg); }
}

/* 네비게이션 */
.nav-link {
    transition: all 0.2s ease;
}

.nav-link:hover {
    background: rgba(59, 130, 246, 0.08);
}

.nav-link.active {
    background: rgba(59, 130, 246, 0.12);
    color: var(--tw-accent, #3b82f6);
    font-weight: 600;
}

/* 테이블 */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.data-table th {
    background: var(--tw-surface-alt, #F4F4F5);
    padding: 12px 16px;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    color: var(--tw-text-2, #71717a);
    border-bottom: 2px solid var(--tw-border, #e4e4e7);
    white-space: nowrap;
}

.data-table td {
    padding: 12px 16px;
    font-size: 14px;
    color: var(--tw-text-1, #141414);
    border-bottom: 1px solid var(--tw-border, #e4e4e7);
}

.data-table tbody tr:hover {
    background: var(--tw-row-hover, #FAFBFF);
}

/* 상태 뱃지 */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
}

.badge-pending {
    background: #fef3c7;
    color: #92400e;
}

.badge-approved {
    background: #d1fae5;
    color: #065f46;
}

.badge-rejected {
    background: #fee2e2;
    color: #991b1b;
}

.badge-admin {
    background: #ede9fe;
    color: #5b21b6;
}

/* 로딩 스피너 */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--tw-border, #e4e4e7);
    border-top-color: var(--tw-accent, #3b82f6);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* 모달 오버레이 */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: white;
    border-radius: 24px;
    padding: 36px 40px;
    max-width: 480px;
    width: 90%;
    transform: scale(0.95);
    transition: transform 0.2s ease;
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

/* 조직도 트리 */
/* ===== 조직도 — 가로(좌→우) 트리 ===== */
.org-chart { display:flex; align-items:flex-start; padding:12px 0; }
.org-node { display:flex; align-items:center; position:relative; }

/* 자식 컨테이너: 세로 스택 (부모 오른쪽에 배치) */
.org-children { display:flex; flex-direction:column; justify-content:center; padding-left:24px; position:relative; }
/* 부모→자식 가로선 */
.org-children::before { content:''; position:absolute; left:0; top:50%; height:1px; width:24px; background:#94a3b8; }

/* 각 자식 왼쪽 가로선 */
.org-children > .org-node { padding:6px 0; }
.org-children > .org-node::before { content:''; position:absolute; left:-24px; top:50%; height:1px; width:24px; background:#94a3b8; }

/* 형제 간 세로 연결선 */
.org-children > .org-node::after { content:''; position:absolute; left:-24px; border-left:1px solid #94a3b8; }
.org-children > .org-node:first-child:not(:only-child)::after { top:50%; bottom:0; }
.org-children > .org-node:last-child:not(:only-child)::after { top:0; bottom:50%; }
.org-children > .org-node:not(:first-child):not(:last-child)::after { top:0; bottom:0; }
.org-children > .org-node:only-child::after { display:none; }

/* 카드 공통 */
.org-card { padding:8px 14px; border-radius:6px; text-align:center; cursor:pointer; transition:all .1s; border:1px solid #d1d5db; position:relative; background:#fff; min-width:100px; }
.org-card:hover { box-shadow:0 2px 8px rgba(0,0,0,.1); }
.org-card.lv0 { background:linear-gradient(135deg,#1e3a5f,#2563eb); color:white; border-color:#1e3a5f; padding:10px 20px; min-width:120px; }
.org-card.lv1 { background:#eff6ff; border-color:#93c5fd; color:#1e40af; }
.org-card.lv2 { background:#f0fdf4; border-color:#86efac; color:#166534; }
.org-card.lv3 { background:#fefce8; border-color:#fde047; color:#854d0e; }
.org-card.lv4 { background:#f8fafc; border-color:#e2e8f0; color:#475569; }
.org-card.unassigned { opacity:.5; border-style:dashed; }
.org-card.unassigned:hover { opacity:1; }

/* 카드 내부 */
.org-card .org-avatar { width:28px; height:28px; border-radius:50%; margin:0 auto 3px; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:12px; }
.org-card.lv0 .org-avatar { background:rgba(255,255,255,.2); color:white; width:32px; height:32px; font-size:14px; }
.org-card.lv1 .org-avatar { background:#dbeafe; color:#1d4ed8; }
.org-card.lv2 .org-avatar { background:#dcfce7; color:#15803d; }
.org-card.lv3 .org-avatar { background:#fef9c3; color:#a16207; }
.org-card.lv4 .org-avatar { background:#f1f5f9; color:#475569; }
.org-card .org-title { font-size:9px; font-weight:700; opacity:.6; margin-bottom:1px; letter-spacing:.4px; text-transform:uppercase; }
.org-card .org-name { font-size:13px; font-weight:700; }
.org-card .org-pos { font-size:10px; opacity:.5; }
.org-card .org-count { font-size:10px; opacity:.5; margin-top:2px; }

/* 자동 팀원은 카드 아래 이름 목록으로 (개별 카드 아님) */
.org-card.org-auto-member { display:none; }
.org-members-list { margin-left:16px; display:grid; grid-template-columns:repeat(3, 1fr); gap:3px; max-width:220px; align-self:center; }
.org-member-chip { font-size:10px; padding:3px 6px; background:#f1f5f9; border:1px solid #e2e8f0; border-radius:3px; text-align:center; color:#475569; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

/* 액션 버튼 */
.org-card .org-actions { position:absolute; top:-8px; right:-8px; display:none; gap:2px; }
.org-card:hover .org-actions { display:flex; }
.org-action-btn { width:20px; height:20px; border-radius:50%; border:1px solid #e2e8f0; background:white; display:flex; align-items:center; justify-content:center; cursor:pointer; font-size:9px; color:#64748b; transition:all .1s; box-shadow:0 1px 3px rgba(0,0,0,.06); }
.org-action-btn:hover { background:#fee2e2; color:#dc2626; border-color:#fca5a5; }
.org-action-btn.add:hover { background:#dbeafe; color:#2563eb; border-color:#93c5fd; }

/* 하위 추가 버튼 */
.org-add-child-btn { width:20px; height:20px; border-radius:50%; border:1px dashed #94a3b8; background:white; display:flex; align-items:center; justify-content:center; cursor:pointer; font-size:9px; color:#94a3b8; transition:all .1s; margin-left:4px; }
.org-add-child-btn:hover { border-color:#2563eb; color:#2563eb; background:#eff6ff; }

/* 드래그앤드롭 */
.org-card[draggable="true"] { cursor:grab; }
.org-card[draggable="true"]:active { cursor:grabbing; }
.org-card.org-drop-target { outline:2px dashed #93c5fd; outline-offset:3px; }
.org-card.org-drag-hover { outline:2px solid #2563eb !important; outline-offset:3px; background:#eff6ff !important; transform:scale(1.05); }

/* 탭 스타일 */
.tab-btn {
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #64748b;
    transition: all 0.2s ease;
    cursor: pointer;
    border: none;
    background: transparent;
}

.tab-btn:hover {
    color: #334155;
    background: #f1f5f9;
}

.tab-btn.active {
    background: var(--tw-accent, #3b82f6);
    color: white;
}

/* 입력 필드 공통 */
.input-field {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-field:focus {
    border-color: var(--tw-accent, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* 버튼 공통 */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    min-height: 40px;
}

.btn-primary {
    background: var(--tw-accent, #3b82f6);
    color: white;
}

.btn-primary:hover {
    background: var(--tw-accent-hover, #2563eb);
}

.btn-success {
    background: #059669;
    color: white;
}

.btn-success:hover {
    background: #047857;
}

.btn-danger {
    background: #dc2626;
    color: white;
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-ghost {
    background: transparent;
    color: #64748b;
}

.btn-ghost:hover {
    background: #f1f5f9;
    color: #334155;
}

/* 차트 컨테이너 */
.chart-container {
    position: relative;
    width: 100%;
    max-height: 300px;
}

/* 반응형 */
@media (max-width: 768px) {
    .data-table th,
    .data-table td {
        padding: 8px 10px;
        font-size: 12px;
    }

    .tab-btn {
        padding: 6px 12px;
        font-size: 13px;
    }

    .btn {
        padding: 7px 12px;
        font-size: 13px;
    }

    .modal-content {
        width: 95%;
        padding: 20px 16px;
    }
}

@media (max-width: 480px) {
    .data-table th,
    .data-table td {
        padding: 6px 8px;
        font-size: 11px;
    }
}

/* 포털로 돌아가기 버튼 (하위 앱용) */
.back-to-portal {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 9999;
    background: var(--tw-accent, #3b82f6);
    color: white;
    padding: 8px 16px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    transition: all 0.2s ease;
    border: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.back-to-portal:hover {
    background: var(--tw-accent-hover, #2563eb);
    transform: translateY(-1px);
}

/* ==========================================
 * 공통 Shell Bar (SAP Fiori 스타일)
 * — 높이는 CSS variable로 관리: 수정 시 여기만 변경
 * ========================================== */
:root {
    --im-shell-h: 48px;
    --im-tab-h: 36px;
    --im-top: calc(var(--im-shell-h) + var(--im-tab-h)); /* 84px */
}
.im-shell {
    position: fixed; top: 0; left: 0; right: 0; z-index: 100;
    height: var(--im-shell-h);
    background: var(--tw-shell-bg, #1B1B1B);
    display: flex; align-items: center;
    padding: 0 16px;
    font-family: 'Pretendard Variable', -apple-system, sans-serif;
}
.im-shell-left {
    display: flex; align-items: center; gap: 4px; height: 100%;
}
.im-shell-btn {
    height: 36px; padding: 0 14px;
    display: flex; align-items: center; justify-content: center; gap: 6px;
    color: #fff; font-size: 14px; font-weight: 700;
    background: rgba(255,255,255,.15); border: none; cursor: pointer;
    transition: all .12s; text-decoration: none;
}
.im-shell-btn i { font-size: 15px; }
.im-shell-btn:hover { background: rgba(255,255,255,.3); }
.im-shell-sep {
    width: 1px; height: 24px;
    background: rgba(255,255,255,.2);
    margin: 0 10px;
}
.im-shell-title {
    font-size: 17px; font-weight: 700; color: #fff;
    white-space: nowrap;
}
.im-shell-badge {
    font-size: 13px; font-weight: 600;
    color: rgba(255,255,255,.7);
    background: rgba(255,255,255,.1);
    padding: 3px 10px; margin-left: 8px;
}
.im-shell-right {
    margin-left: auto;
    display: flex; align-items: center; gap: 4px;
}
.im-shell-text-btn {
    padding: 0 14px; height: 36px;
    background: none; border: none;
    color: rgba(255,255,255,.7); font-size: 14px; font-weight: 600;
    cursor: pointer; display: flex; align-items: center; gap: 6px;
    transition: all .1s; text-decoration: none;
}
.im-shell-text-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
/* ===== Tab Bar (Shell Bar 아래) ===== */
.im-tabs {
    position: fixed; top: var(--im-shell-h); left: 0; right: 0; z-index: 99;
    height: var(--im-tab-h);
    background: var(--tw-shell-bg, #1B1B1B);
    display: flex; align-items: stretch;
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    font-family: 'Pretendard Variable', -apple-system, sans-serif;
}
.im-tabs::-webkit-scrollbar { height: 0; }
.im-tab {
    display: flex; align-items: center; gap: 8px;
    padding: 0 18px;
    font-size: 14px; font-weight: 600;
    color: rgba(255,255,255,.6);
    background: transparent;
    border: none; border-right: 1px solid rgba(255,255,255,.06);
    cursor: pointer;
    white-space: nowrap;
    transition: all .08s;
    text-decoration: none;
    max-width: 200px;
    min-width: 0;
    flex-shrink: 0;
    position: relative;
}
.im-tab:hover { background: rgba(255,255,255,.08); color: rgba(255,255,255,.85); }
.im-tab.active {
    background: var(--tw-surface, #fff);
    color: var(--tw-text-1, #141414);
}
.im-tab .tab-label {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.im-tab .tab-close {
    width: 20px; height: 20px;
    display: none; align-items: center; justify-content: center;
    font-size: 15px; color: rgba(255,255,255,.4);
    cursor: pointer; flex-shrink: 0;
    transition: all .1s;
    background: none; border: none; padding: 0;
    line-height: 1;
}
.im-tab:hover .tab-close { display: flex; }
.im-tab .tab-close:hover { color: #fff; background: rgba(255,255,255,.15); }
.im-tab.active .tab-close { color: #8b8e91; display: flex; }
.im-tab.active .tab-close:hover { color: #bb0000; background: rgba(187,0,0,.1); }

/* Shell Bar + Tab Bar 아래 컨텐츠 밀기 */
body.has-shell { padding-top: var(--im-top); }
body.has-shell .timer-header,
body.has-shell .page-header:not(.crm-page-header),
body.has-shell .setup-header { top: var(--im-top) !important; }

/* ===== 페이지 전환 애니메이션 ===== */
/* Shell Bar + Tab Bar는 고정, 컨텐츠만 페이드 */
body.has-shell {
    animation: imPageIn .2s ease-out;
}
/* Shell Bar/Tab Bar는 애니메이션에서 제외 (항상 고정) */
.im-shell, .im-tabs {
    animation: none !important;
    opacity: 1 !important;
}
@keyframes imPageIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
/* 페이지 나갈 때 페이드아웃 */
body.im-leaving {
    opacity: 0;
    transition: opacity .12s ease-in;
}
body.im-leaving .im-shell,
body.im-leaving .im-tabs {
    opacity: 1 !important;
}

/* 모바일: Shell Bar + Tab Bar 컴팩트 */
@media (max-width: 640px) {
    .im-shell { height: 40px; padding: 0 8px; }
    .im-shell-btn { padding: 0 8px; font-size: 12px; height: 40px; }
    .im-shell-btn i { font-size: 14px; }
    .im-shell-btn span { display: none; }
    .im-shell-btn { padding: 0 8px; font-size: 0; }
    .im-shell-btn i { font-size: 16px !important; }
    .im-shell-title { font-size: 14px; white-space: nowrap; }
    .im-shell-badge { font-size: 11px; padding: 2px 6px; margin-left: 4px; }
    .im-shell-text-btn { padding: 0 8px; height: 40px; font-size: 12px; }
    .im-shell-text-btn span { display: none; }
    .im-shell-right { gap: 0; }
    .im-tabs { height: 30px; top: 40px; }
    .im-tab { padding: 0 10px; font-size: 12px; gap: 4px; }
    .im-tab i { font-size: 10px; }
    body.has-shell { --im-top: 70px; }
}

/* 인쇄 시 AI 비서 숨김 (전체 페이지 공통) */
/* page-tabs 있으면 portal-nav 홈/메뉴 버튼 숨김 (중복 방지) */
body:has(#imTabBar) .pn-fixed-wrap { display: none !important; }

@media print {
    #aiAssistBtn, #aiChatWindow { display: none !important; }
    .im-shell, .im-tabs, #imTabBar { display: none !important; }
    @page { margin: 10mm; }
    title { display: none !important; }
}
