/* KST Design System v2 — Toss + THE VC Mix */
/* Tailwind CSS + CSS 커스텀 속성 + 컴포넌트 */

@import "tailwindcss";

/* ── Fonts ── */
@font-face {
  font-family: 'Pretendard';
  src: url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard-dynamic-subset.min.css');
  font-display: swap;
}
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── Design Tokens (CSS Custom Properties) ── */
:root {
  /* Colors */
  --c-primary: #3182F6;
  --c-primary-hover: #1A6DF5;
  --c-primary-active: #0B5CD6;
  --c-primary-bg: #EBF4FF;

  --c-green: #00C471;
  --c-green-bg: rgba(0, 196, 113, 0.10);
  --c-red: #F04452;
  --c-red-bg: rgba(240, 68, 82, 0.10);
  --c-yellow: #FFC83C;
  --c-yellow-bg: rgba(255, 200, 60, 0.10);

  --c-ink: #191F28;
  --c-ink-secondary: #4E5968;
  --c-ink-tertiary: #8B95A1;
  --c-ink-disabled: #CCD1D8;

  --c-surface: #FFFFFF;
  --c-surface-secondary: #F9FAFB;
  --c-surface-tertiary: #F3F4F6;
  --c-surface-hover: #F0F2F5;
  --c-border: #EEEEEE;
  --c-border-light: #F5F5F5;

  /* Typography Scale */
  --fs-h1: 32px;
  --fs-h2: 22px;
  --fs-h3: 18px;
  --fs-body: 15px;
  --fs-small: 13px;
  --fs-caption: 11px;
  --lh-h1: 1.3;
  --lh-h2: 1.4;
  --lh-h3: 1.5;
  --lh-body: 1.6;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Shadows */
  --shadow-card: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-card-hover: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-popup: 0 8px 24px rgba(0,0,0,0.12);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
}

/* ── Base ── */
@layer base {
  html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
  }

  body {
    font-family: 'Pretendard', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    color: var(--c-ink);
    background-color: var(--c-surface-secondary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
  }

  /* Typography */
  h1 { font-size: var(--fs-h1); line-height: var(--lh-h1); font-weight: 700; letter-spacing: -0.02em; }
  h2 { font-size: var(--fs-h2); line-height: var(--lh-h2); font-weight: 600; letter-spacing: -0.01em; }
  h3 { font-size: var(--fs-h3); line-height: var(--lh-h3); font-weight: 600; }

  /* Focus visible (accessibility) */
  *:focus-visible {
    outline: 2px solid var(--c-primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
  }
  *:focus:not(:focus-visible) {
    outline: none;
  }

  /* Scrollbar */
  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: #D1D6DB; border-radius: 3px; }
  ::-webkit-scrollbar-thumb:hover { background: #9CA3AF; }

  /* Selection */
  ::selection { background: var(--c-primary-bg); color: var(--c-primary); }

  /* Accessible skip link */
  .skip-link {
    position: absolute; top: -100%; left: 0; z-index: 1000;
    padding: var(--space-2) var(--space-4);
    background: var(--c-primary); color: white;
    font-size: var(--fs-small); font-weight: 600;
  }
  .skip-link:focus { top: 0; }
}

/* ── Button Component ── */
@layer components {
  .kst-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    padding: var(--space-2) var(--space-5);
    font-size: var(--fs-small); font-weight: 600;
    line-height: 1; white-space: nowrap;
    border: none; border-radius: var(--radius-md);
    cursor: pointer; text-decoration: none;
    transition: all var(--transition-fast);
    min-height: 36px;
  }
  .kst-btn:active { transform: scale(0.97); }

  /* Primary */
  .kst-btn-primary {
    background: var(--c-primary); color: white; box-shadow: 0 1px 3px rgba(49, 130, 246, 0.3);
  }
  .kst-btn-primary:hover { background: var(--c-primary-hover); }
  .kst-btn-primary:active { background: var(--c-primary-active); }

  /* Secondary */
  .kst-btn-secondary {
    background: var(--c-surface-tertiary); color: var(--c-ink-secondary);
  }
  .kst-btn-secondary:hover { background: #E8EAED; }

  /* Ghost */
  .kst-btn-ghost {
    background: transparent; color: var(--c-ink-secondary);
  }
  .kst-btn-ghost:hover { background: var(--c-surface-hover); }

  /* Danger */
  .kst-btn-danger {
    background: var(--c-red); color: white;
  }
  .kst-btn-danger:hover { background: #D93A47; }

  /* Sizes */
  .kst-btn-sm { padding: var(--space-1) var(--space-3); font-size: 12px; min-height: 28px; }
  .kst-btn-lg { padding: 12px var(--space-6); font-size: var(--fs-body); min-height: 44px; }
}

/* ── State Components ── */
@layer components {
  /* Empty State */
  .kst-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: var(--space-12) var(--space-4); text-align: center;
  }
  .kst-empty-icon {
    width: 48px; height: 48px; color: var(--c-ink-disabled); margin-bottom: var(--space-3);
  }
  .kst-empty-title {
    font-size: var(--fs-body); font-weight: 600; color: var(--c-ink); margin-bottom: var(--space-1);
  }
  .kst-empty-desc {
    font-size: var(--fs-small); color: var(--c-ink-tertiary); max-width: 280px;
  }

  /* Loading Skeleton */
  @keyframes shimmer {
    0% { background-position: -200px 0; }
    100% { background-position: calc(200px + 100%) 0; }
  }
  .kst-skeleton {
    background: linear-gradient(90deg, var(--c-surface-tertiary) 25%, var(--c-surface-hover) 50%, var(--c-surface-tertiary) 75%);
    background-size: 200px 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
  }
  .kst-skeleton-text { height: 14px; margin-bottom: var(--space-2); width: 100%; }
  .kst-skeleton-title { height: 20px; margin-bottom: var(--space-3); width: 60%; }

  /* Toast / Alert */
  .kst-toast {
    position: fixed; top: var(--space-4); right: var(--space-4); z-index: 9999;
    display: flex; align-items: center; gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md); font-size: var(--fs-small); font-weight: 500;
    box-shadow: var(--shadow-popup);
    animation: slideIn 0.3s ease-out;
  }
  .kst-toast-success { background: #E8FAF1; color: #00994E; border: 1px solid #B8F0D6; }
  .kst-toast-error { background: #FEF0F0; color: #CC3333; border: 1px solid #FCD5D5; }
  .kst-toast-info { background: var(--c-primary-bg); color: var(--c-primary); border: 1px solid #C7E0FF; }

  @keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
  }
}

/* ── KST Card ── */
@layer components {
  .kst-card {
    background: var(--c-surface); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card); border: 1px solid var(--c-border);
    transition: box-shadow var(--transition-base);
  }
  .kst-card:hover { box-shadow: var(--shadow-card-hover); }
  .kst-card-header {
    padding: var(--space-5) var(--space-5) var(--space-4);
    border-bottom: 1px solid var(--c-border-light);
  }
  .kst-card-body { padding: var(--space-5); }
}

/* ── Table ── */
@layer components {
  .kst-table { width: 100%; border-collapse: collapse; }
  .kst-table th {
    padding: var(--space-3) var(--space-4);
    text-align: left; font-size: 11px; font-weight: 600;
    color: var(--c-ink-tertiary); text-transform: uppercase; letter-spacing: 0.05em;
    border-bottom: 1px solid var(--c-border);
  }
  .kst-table td {
    padding: var(--space-3) var(--space-4);
    font-size: var(--fs-small); color: var(--c-ink);
    border-bottom: 1px solid var(--c-border-light);
  }
  .kst-table tr:last-child td { border-bottom: none; }
  .kst-table tbody tr { transition: background var(--transition-fast); cursor: pointer; }
  .kst-table tbody tr:hover td { background: var(--c-surface-hover); }
  .kst-table tbody tr:focus-visible { outline: 2px solid var(--c-primary); outline-offset: -2px; }

  /* Mobile card view for tables */
  @media (max-width: 767px) {
    .kst-table thead { display: none; }
    .kst-table tr {
      display: block; padding: var(--space-4);
      border-bottom: 1px solid var(--c-border);
    }
    .kst-table td {
      display: flex; justify-content: space-between; align-items: center;
      padding: var(--space-1) 0; border: none; font-size: var(--fs-body);
    }
    .kst-table td::before {
      content: attr(data-label);
      font-size: var(--fs-small); color: var(--c-ink-tertiary); font-weight: 500;
    }
  }
}

/* ── Badges ── */
@layer components {
  .badge-up {
    display: inline-flex; align-items: center; gap: 2px;
    padding: 2px 8px; border-radius: 999px;
    font-size: 12px; font-weight: 600;
    background: var(--c-green-bg); color: var(--c-green);
  }
  .badge-down {
    display: inline-flex; align-items: center; gap: 2px;
    padding: 2px 8px; border-radius: 999px;
    font-size: 12px; font-weight: 600;
    background: var(--c-red-bg); color: var(--c-red);
  }
  .badge-neutral {
    display: inline-flex; align-items: center;
    padding: 2px 8px; border-radius: 999px;
    font-size: 12px; font-weight: 500;
    background: var(--c-surface-tertiary); color: var(--c-ink-tertiary);
  }
}

/* ── Sector Tag ── */
@layer components {
  .sector-tag {
    display: inline-flex; align-items: center;
    padding: 4px 12px; border-radius: 999px;
    font-size: 12px; font-weight: 500;
    background: var(--c-surface-tertiary); color: var(--c-ink-secondary);
    transition: all var(--transition-fast); cursor: default;
  }
  .sector-tag[role="button"], .sector-tag.clickable { cursor: pointer; }
  .sector-tag[role="button"]:hover, .sector-tag.clickable:hover {
    background: #E2E5E8; color: var(--c-ink);
  }
  .sector-tag.active {
    background: var(--c-primary); color: white;
  }
}

/* ── Mobile Bottom Nav ── */
@layer components {
  .mobile-tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    padding: 6px 12px; min-height: 48px;
    color: var(--c-ink-tertiary); text-decoration: none;
    transition: color var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-tab.active { color: var(--c-primary); }
  .mobile-tab svg { width: 22px; height: 22px; }
  .mobile-tab span { font-size: 10px; font-weight: 500; }
  .mobile-tab.active span { font-weight: 600; }

  /* Active indicator */
  .mobile-tab.active::before {
    content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 24px; height: 3px; border-radius: 0 0 2px 2px;
    background: var(--c-primary);
  }
}

/* ── Utilities ── */
@layer utilities {
  .animate-in {
    animation: fadeIn 0.3s ease-out, slideUp 0.35s ease-out;
  }
  @keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }
  @keyframes slideUp {
    from { transform: translateY(12px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }

  /* Responsive typography helpers */
  .text-h1 { font-size: var(--fs-h1); line-height: var(--lh-h1); font-weight: 700; letter-spacing: -0.02em; }
  .text-h2 { font-size: var(--fs-h2); line-height: var(--lh-h2); font-weight: 600; }
  .text-h3 { font-size: var(--fs-h3); line-height: var(--lh-h3); font-weight: 600; }
  .text-body { font-size: var(--fs-body); line-height: var(--lh-body); }
  .text-small { font-size: var(--fs-small); line-height: 1.5; }
  .text-caption { font-size: var(--fs-caption); line-height: 1.4; font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }

  @media (max-width: 767px) {
    .text-h1 { font-size: 24px; }
    .text-h2 { font-size: 18px; }
  }
}

/* ── Mobile Bottom Nav Container ── */
@media (max-width: 1023px) {
  .mobile-bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: var(--c-surface); border-top: 1px solid var(--c-border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

/* ── Safe area for notched devices ── */
.safe-area-bottom { padding-bottom: env(safe-area-inset-bottom, 0px); }
