@import "tailwindcss";

/* 🔧 Pretendard 폰트는 next/font/local로 로드됨 (layout.tsx) */

@variant dark (&:is(.dark *));
@variant senior (&:is(.senior *));

/* 📱 iOS Safe Area CSS 변수
   - 아이폰 노치/다이나믹 아일랜드/홈바 영역
   - viewportFit: cover와 함께 사용
   - 레이아웃 컴포넌트에서 필요 시 사용
*/
:root {
  --safe-area-inset-top: env(safe-area-inset-top, 0px);
  --safe-area-inset-right: env(safe-area-inset-right, 0px);
  --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-inset-left: env(safe-area-inset-left, 0px);
}

:root {
  --font-size: 16px;
  /* Clean minimalist background */
  --background: #FAFAFA;
  --foreground: #1A1A1A;
  --card: #FFFFFF;
  --card-foreground: #1A1A1A;
  --popover: #FFFFFF;
  --popover-foreground: #1A1A1A;
  /* Modern blue primary palette */
  --primary: #3B82F6;
  --primary-foreground: #FFFFFF;
  --secondary: #F1F5F9;
  --secondary-foreground: #1A1A1A;
  --muted: #F8FAFC;
  --muted-foreground: #6B7280;
  --accent: #F0F9FF;
  --accent-foreground: #1A1A1A;
  /* Clean destructive color */
  --destructive: #EF4444;
  --destructive-foreground: #FFFFFF;
  --border: #E2E8F0;
  --input: #FFFFFF;
  --input-background: #F8FAFC;
  --switch-background: #F1F5F9;
  --font-weight-medium: 500;
  --font-weight-normal: 400;
  --ring: rgba(59, 130, 246, 0.3);
  /* Clean chart colors */
  --chart-1: #3B82F6;
  --chart-2: #10B981;
  --chart-3: #F59E0B;
  --chart-4: #EF4444;
  --chart-5: #8B5CF6;
  /* Minimal rounded corners */
  --radius: 0.75rem;
  /* Clean sidebar */
  --sidebar: #FFFFFF;
  --sidebar-foreground: #1A1A1A;
  --sidebar-primary: #3B82F6;
  --sidebar-primary-foreground: #FFFFFF;
  --sidebar-accent: #F0F9FF;
  --sidebar-accent-foreground: #1A1A1A;
  --sidebar-border: #E2E8F0;
  --sidebar-ring: rgba(59, 130, 246, 0.3);

  /* Clean design tokens */
  --clean-blur: blur(8px);
  --clean-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --clean-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --clean-shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
  --clean-shadow-xl: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
}

.dark {
  /* Clean dark theme */
  --background: #0F172A;
  --foreground: #F8FAFC;
  --card: #1E293B;
  --card-foreground: #F8FAFC;
  --popover: #1E293B;
  --popover-foreground: #F8FAFC;
  --primary: #60A5FA;
  --primary-foreground: #1E293B;
  --secondary: #334155;
  --secondary-foreground: #F8FAFC;
  --muted: #475569;
  --muted-foreground: #94A3B8;
  --accent: #1E40AF;
  --accent-foreground: #F8FAFC;
  --destructive: #F87171;
  --destructive-foreground: #1E293B;
  --border: #334155;
  --input: #1E293B;
  --input-background: #334155;
  --switch-background: #475569;
  --ring: rgba(96, 165, 250, 0.3);

  /* Dark mode chart colors */
  --chart-1: #60A5FA;
  --chart-2: #34D399;
  --chart-3: #FBBF24;
  --chart-4: #F87171;
  --chart-5: #A78BFA;

  /* Dark sidebar */
  --sidebar: #1E293B;
  --sidebar-foreground: #F8FAFC;
  --sidebar-primary: #60A5FA;
  --sidebar-primary-foreground: #1E293B;
  --sidebar-accent: #1E40AF;
  --sidebar-accent-foreground: #F8FAFC;
  --sidebar-border: #334155;
  --sidebar-ring: rgba(96, 165, 250, 0.3);

  /* Dark mode clean shadows */
  --clean-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --clean-shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  --clean-shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.2);
  --clean-shadow-xl: 0 10px 15px rgba(0, 0, 0, 0.4), 0 4px 6px rgba(0, 0, 0, 0.2);
}

.senior {
  /* Senior-friendly theme - High contrast, larger text */
  --font-size: 18px;
  --background: #FFFFFF;
  --foreground: #000000;
  --card: #FFFFFF;
  --card-foreground: #000000;
  --popover: #FFFFFF;
  --popover-foreground: #000000;
  /* High contrast primary */
  --primary: #2563EB;
  --primary-foreground: #FFFFFF;
  --secondary: #E5E7EB;
  --secondary-foreground: #000000;
  --muted: #F3F4F6;
  --muted-foreground: #374151;
  --accent: #DBEAFE;
  --accent-foreground: #000000;
  /* High contrast destructive */
  --destructive: #DC2626;
  --destructive-foreground: #FFFFFF;
  --border: #9CA3AF;
  --input: #FFFFFF;
  --input-background: #F9FAFB;
  --switch-background: #E5E7EB;
  --font-weight-medium: 600;
  --font-weight-normal: 500;
  --ring: rgba(37, 99, 235, 0.5);

  /* Senior mode chart colors - High contrast */
  --chart-1: #2563EB;
  --chart-2: #059669;
  --chart-3: #D97706;
  --chart-4: #DC2626;
  --chart-5: #7C3AED;

  /* Senior sidebar */
  --sidebar: #FFFFFF;
  --sidebar-foreground: #000000;
  --sidebar-primary: #2563EB;
  --sidebar-primary-foreground: #FFFFFF;
  --sidebar-accent: #DBEAFE;
  --sidebar-accent-foreground: #000000;
  --sidebar-border: #9CA3AF;
  --sidebar-ring: rgba(37, 99, 235, 0.5);

  /* Larger shadows for better depth perception */
  --clean-shadow: 0 2px 4px rgba(0, 0, 0, 0.15), 0 2px 3px rgba(0, 0, 0, 0.1);
  --clean-shadow-lg: 0 6px 8px rgba(0, 0, 0, 0.12), 0 3px 5px rgba(0, 0, 0, 0.08);
}

@theme inline {
  --animate-accordion-down: accordion-down 0.2s ease-out;
  --animate-accordion-up: accordion-up 0.2s ease-out;
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --color-card: var(--card);
  --color-card-foreground: var(--card-foreground);
  --color-popover: var(--popover);
  --color-popover-foreground: var(--popover-foreground);
  --color-primary: var(--primary);
  --color-primary-foreground: var(--primary-foreground);
  --color-secondary: var(--secondary);
  --color-secondary-foreground: var(--secondary-foreground);
  --color-muted: var(--muted);
  --color-muted-foreground: var(--muted-foreground);
  --color-accent: var(--accent);
  --color-accent-foreground: var(--accent-foreground);
  --color-destructive: var(--destructive);
  --color-destructive-foreground: var(--destructive-foreground);
  --color-border: var(--border);
  --color-input: var(--input);
  --color-input-background: var(--input-background);
  --color-switch-background: var(--switch-background);
  --color-ring: var(--ring);
  --color-chart-1: var(--chart-1);
  --color-chart-2: var(--chart-2);
  --color-chart-3: var(--chart-3);
  --color-chart-4: var(--chart-4);
  --color-chart-5: var(--chart-5);
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
  --color-sidebar: var(--sidebar);
  --color-sidebar-foreground: var(--sidebar-foreground);
  --color-sidebar-primary: var(--sidebar-primary);
  --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
  --color-sidebar-accent: var(--sidebar-accent);
  --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
  --color-sidebar-border: var(--sidebar-border);
  --color-sidebar-ring: var(--sidebar-ring);
}

@layer base {
  * {
    @apply border-border outline-ring/50;
    font-family: var(--font-pretendard), -apple-system, BlinkMacSystemFont, system-ui, Roboto, 'Helvetica Neue', 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', sans-serif;
  }

  html {
    /* 🔧 Always show scrollbar to prevent layout shift */
    /*overflow-y: scroll;*/
    /* 📱 모바일 확대 후 좌우 패닝 허용 */
    touch-action: manipulation;
  }

  body {
    @apply bg-background text-foreground;
    font-family: var(--font-pretendard), -apple-system, BlinkMacSystemFont, system-ui, Roboto, 'Helvetica Neue', 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', sans-serif;
    font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    background: var(--background);
    min-height: 100vh;
    /* 🔧 Body has no overflow - html handles all scrolling */
    overflow: visible !important;
  }

  /* 🔧 Override Radix's scroll-lock completely to prevent any layout shift */
  body[data-scroll-locked] {
    /*overflow: visible !important;*/
    /*position: static !important;*/
    /*padding-right: 0 !important;*/
    margin-right: 0 !important;
  }

  /* 🔧 Prevent scroll on modal backdrop instead of body */
  [data-radix-portal] {
    /*position: fixed;*/
  }

  /* 🔧 Fix DropdownMenu/Popover/Select positioning to prevent "flying in from far away" */
  [data-radix-popper-content-wrapper] {
    will-change: auto !important;
    transition: none !important; /* 전역 transition 제거 - 날아오는 효과 방지 */
  }

  /* 🔧 Radix UI 컴포넌트의 slide 애니메이션만 제거, 위치 계산은 유지 */
  [data-radix-dropdown-menu-content],
  [data-radix-select-content],
  [data-radix-popover-content] {
    animation-name: none !important;
  }

  /* Clean glass utilities */
  .clean-glass {
    backdrop-filter: var(--clean-blur);
    -webkit-backdrop-filter: var(--clean-blur);
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid var(--border);
    position: relative;
  }

  .dark .clean-glass {
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid var(--border);
  }

  /* Clean shadows */
  .clean-shadow-sm {
    box-shadow: var(--clean-shadow-sm);
  }

  .clean-shadow {
    box-shadow: var(--clean-shadow);
  }

  .clean-shadow-lg {
    box-shadow: var(--clean-shadow-lg);
  }

  .clean-shadow-xl {
    box-shadow: var(--clean-shadow-xl);
  }

  /* Smooth transitions for interactive elements only */
  button, a, input, select, textarea,
  [role="button"], [role="tab"], [role="menuitem"] {
    transition-property: color, background-color, border-color, box-shadow;
    transition-duration: 0.2s;
    transition-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  }

  /* Bell ringing animation for notifications */
  @keyframes bell-ring {
    0%, 100% { transform: rotate(0deg); }
    10% { transform: rotate(14deg); }
    20% { transform: rotate(-12deg); }
    30% { transform: rotate(10deg); }
    40% { transform: rotate(-8deg); }
    50% { transform: rotate(6deg); }
    60% { transform: rotate(-4deg); }
    70% { transform: rotate(2deg); }
    80% { transform: rotate(-1deg); }
    90% { transform: rotate(0deg); }
  }

  .animate-bell-ring {
    animation: bell-ring 1s ease-in-out infinite;
    transform-origin: top center;
  }

  /* ==========================================
     Custom Scrollbar - Auto-hide
     공간은 항상 확보, thumb은 스크롤 시에만 표시.
     JS에서 scroll 이벤트 시 .is-scrolling 클래스 토글.
     ========================================== */

  /* Webkit (Chrome, Safari, Edge) - 공간 확보 */
  ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }

  ::-webkit-scrollbar-track {
    background: transparent;
  }

  ::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 4px;
  }

  /* 스크롤 중일 때 thumb 표시 */
  .is-scrolling::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
  }

  .dark .is-scrolling::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
  }

  .is-scrolling::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
  }

  .dark .is-scrolling::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
  }

  /* Firefox - 공간 확보 + 기본 투명 */
  * {
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
  }

  .is-scrolling {
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
  }

  .dark .is-scrolling {
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
  }

  /* Sidebar scroll - 더 얇은 스크롤바 */
  .sidebar-scroll::-webkit-scrollbar {
    width: 6px;
  }

  .sidebar-scroll.is-scrolling::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
  }

  .dark .sidebar-scroll.is-scrolling::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
  }

  .sidebar-scroll.is-scrolling::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25) !important;
  }

  .dark .sidebar-scroll.is-scrolling::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25) !important;
  }

  /* Firefox sidebar */
  .sidebar-scroll {
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
  }

  .sidebar-scroll.is-scrolling {
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
  }

  .dark .sidebar-scroll.is-scrolling {
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
  }
}

/* ===== Mobile Header Actions Grid ===== */
/* 모바일(<xl)에서 헤더 액션 버튼들을 2열 그리드로 정리 */
@media (max-width: 1279px) {
  .mobile-actions-grid {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
  }

  /* Wrapper div 투명화 - 내부 버튼들이 직접 flex 아이템이 됨 */
  .mobile-actions-grid > div {
    display: contents;
  }

  /* 모든 버튼: 최소 50% 너비, flex-grow로 남은 공간 채움 */
  /* 2개 → 50/50, 3개 → 50/50 + 100%, 4개 → 50/50/50/50 */
  .mobile-actions-grid button {
    flex: 1 1 calc(50% - 0.25rem);
    min-width: calc(50% - 0.25rem);
    /* 프리셋 버튼 사이즈에 맞춤 (h-8, text-xs~sm) */
    height: 2rem !important;
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
    font-size: 0.75rem !important;
  }
}

/* ===== Mobile Tab Grid ===== */
/* 모바일(<xl)에서 탭칩을 3열 그리드로 동등 너비 배치 */
@media (max-width: 1279px) {
  .mobile-tab-grid {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 0.5rem;
    width: 100%;
    min-width: 0 !important;
  }
  .mobile-tab-grid > button {
    flex: 1 1 calc(33.333% - 0.334rem);
    min-width: calc(33.333% - 0.334rem);
    justify-content: center;
    /* 프리셋 버튼 사이즈에 맞춤 */
    padding: 0.375rem 0.5rem;
    font-size: 0.75rem;
  }
}

/* Clean modern component styles */
@layer components {
  .clean-input {
    @apply bg-input-background border border-border rounded-lg px-4 py-3;
    @apply focus:bg-card focus:border-primary focus:ring-2 focus:ring-primary/20;
    @apply transition-all duration-200 ease-out;
  }

  .clean-input::placeholder {
    @apply text-muted-foreground;
  }

  .clean-button {
    @apply rounded-lg px-6 py-3 font-medium transition-colors duration-200;
    @apply bg-primary text-primary-foreground hover:bg-primary/90;
  }

  .clean-button-secondary {
    @apply rounded-lg px-6 py-3 font-medium transition-colors duration-200;
    @apply bg-secondary text-secondary-foreground hover:bg-secondary/80;
  }

  .clean-card {
    @apply bg-card border border-border rounded-lg p-6;
    @apply transition-shadow duration-200;
    box-shadow: var(--clean-shadow);
  }

  .clean-card:hover {
    box-shadow: var(--clean-shadow-lg);
  }
}

html {
  font-size: var(--font-size);
}

/* ==========================================
   Sheet/Dialog Slide Animations
   ========================================== */

/* Keyframes */
@keyframes slideInFromRight {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@keyframes slideOutToRight {
  from { transform: translateX(0); }
  to { transform: translateX(100%); }
}

@keyframes slideInFromLeft {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

@keyframes slideOutToLeft {
  from { transform: translateX(0); }
  to { transform: translateX(-100%); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes accordion-down {
  from { height: 0; }
  to { height: var(--radix-accordion-content-height); }
}

@keyframes accordion-up {
  from { height: var(--radix-accordion-content-height); }
  to { height: 0; }
}

/* Sheet Content - Right side slide animation (기본값, right-0 클래스) */
[data-slot="sheet-content"].right-0[data-state="open"] {
  animation: slideInFromRight 300ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

[data-slot="sheet-content"].right-0[data-state="closed"] {
  animation: slideOutToRight 200ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Sheet Content - Left side slide animation (left-0 클래스) */
[data-slot="sheet-content"].left-0[data-state="open"] {
  animation: slideInFromLeft 300ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

[data-slot="sheet-content"].left-0[data-state="closed"] {
  animation: slideOutToLeft 200ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Sheet Overlay - Fade animation */
[data-slot="sheet-overlay"][data-state="open"] {
  animation: fadeIn 300ms ease-out forwards;
}

[data-slot="sheet-overlay"][data-state="closed"] {
  animation: fadeOut 200ms ease-out forwards;
}

/* ==========================================
   Print Styles - 인쇄 시 문서만 출력
   ========================================== */
@media print {
  /* A4 용지 설정 */
  @page {
    size: A4 portrait;
    margin: 10mm;
  }

  /* 배경색 유지 */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  /* ========================================
     인쇄 스타일 (JavaScript printArea 사용 시 기본값)
     ======================================== */

  /* 기본 설정 - printArea 유틸리티가 새 창에서 인쇄하므로 간단하게 유지 */
  html, body {
    background: white !important;
  }

  /* print-hidden 클래스 숨김 */
  .print-hidden {
    display: none !important;
  }

  /* ========================================
     테이블 & 페이지 설정
     ======================================== */

  /* 페이지 나눔 방지 */
  table, figure, .page-break-avoid {
    page-break-inside: avoid;
  }

  /* 인쇄용 테이블 스타일 */
  .print-area table {
    border-collapse: collapse !important;
  }

  .print-area th,
  .print-area td {
    border: 1px solid #000 !important;
  }

  /* print-area 내부 문서 wrapper - transform 제거 */
  .print-area > div {
    max-width: none !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    transform: none !important;
  }

  /* 실제 문서 컨테이너 - A4에 맞게 조정 */
  .print-area > div > div {
    width: 100% !important;
    max-width: 190mm !important;
    min-height: auto !important;
    margin: 0 auto !important;
    padding: 5mm !important;
    box-shadow: none !important;
    font-size: 10pt !important;
  }

  /* 테이블 폰트 크기 축소 */
  .print-area table {
    font-size: 9pt !important;
  }

  .print-area .text-xs {
    font-size: 8pt !important;
  }

  .print-area .text-sm {
    font-size: 9pt !important;
  }

  .print-area .text-3xl {
    font-size: 18pt !important;
  }
}