/* ============================================================
   KMC Workstation v2 — base.css
   Reset + Typography + Layout Shell
   Requires: design-system-v3.css (tokens)
   Target: 1920x1080, 16px base, Pretendard Variable
   ============================================================ */

/* --- Modern Reset --- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  min-width: 1200px;
  overflow-x: auto;
}

img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
}
button { cursor: pointer; }
table { border-collapse: collapse; border-spacing: 0; width: 100%; }
ul, ol { list-style: none; }
h1, h2, h3, h4, h5, h6 { font-weight: 600; line-height: 1.3; letter-spacing: -0.02em; }

/* Scrollbar (Webkit) */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--slate-300); border-radius: var(--radius-pill); }
::-webkit-scrollbar-thumb:hover { background: var(--slate-400); }

/* Focus visible */
:focus-visible {
  outline: none;
  box-shadow: var(--ring-brand);
}

/* Selection */
::selection {
  background: var(--brand-100);
  color: var(--brand-900);
}


/* --- Typography --- */
.text-2xs  { font-size: var(--text-2xs); }
.text-xs   { font-size: var(--text-xs); }
.text-sm   { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg   { font-size: var(--text-lg); }
.text-xl   { font-size: var(--text-xl); }
.text-2xl  { font-size: var(--text-2xl); }
.text-3xl  { font-size: var(--text-3xl); }

.font-normal   { font-weight: 400; }
.font-medium   { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold     { font-weight: 700; }

.text-ink       { color: var(--ink); }
.text-secondary { color: var(--ink-secondary); }
.text-muted     { color: var(--muted); }
.text-brand     { color: var(--brand); }
.text-danger    { color: var(--status-danger); }
.text-success   { color: var(--status-ok); }
.text-warning   { color: var(--status-warn); }

.text-uppercase {
  text-transform: uppercase;
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--muted);
}


/* --- Layout Shell: CSS Grid --- */

/*
  Structure:
  +----------+----------------------------------+-----------+
  |          |           Header (56px)          |           |
  | Sidebar  +----------------------------------+ AI Panel  |
  | (240px)  |           Main Content           | (360px)   |
  |          |           (flex: 1)              | toggle    |
  +----------+----------------------------------+-----------+
*/

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-areas:
    "sidebar header"
    "sidebar main";
  height: 100vh;
  max-width: var(--layout-max);
  margin: 0 auto;
}

/* Variation: with LNB (sub-navigation) */
.app--with-lnb {
  grid-template-columns: 240px 220px 1fr;
  grid-template-areas:
    "sidebar lnb header"
    "sidebar lnb main";
}

/* Variation: detail panel open (master-detail) */
.app--detail-open {
  grid-template-columns: 240px 1fr 480px;
  grid-template-areas:
    "sidebar header  detail"
    "sidebar main    detail";
}

/* Variation: LNB + detail panel */
.app--with-lnb.app--detail-open {
  grid-template-columns: 240px 220px 1fr 480px;
  grid-template-areas:
    "sidebar lnb header  detail"
    "sidebar lnb main    detail";
}

/* Variation: AI panel open */
.app--ai-open {
  grid-template-columns: 240px 1fr 360px;
  grid-template-areas:
    "sidebar header  ai"
    "sidebar main    ai";
}

/* Sidebar collapsed */
.app--sidebar-collapsed {
  grid-template-columns: 64px 1fr;
}
.app--sidebar-collapsed.app--with-lnb {
  grid-template-columns: 64px 220px 1fr;
}
.app--sidebar-collapsed.app--detail-open {
  grid-template-columns: 64px 1fr 480px;
}
.app--sidebar-collapsed.app--ai-open {
  grid-template-columns: 64px 1fr 360px;
}


/* --- Sidebar --- */
.sidebar {
  grid-area: sidebar;
  width: 240px;
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  transition: width 250ms ease;
}

.app--sidebar-collapsed .sidebar {
  width: 64px;
}

.sidebar__logo {
  height: var(--sidebar-logo-h);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-5);
  gap: var(--sp-3);
  flex-shrink: 0;
  border-bottom: 1px solid var(--line-light);
}

.sidebar__logo-title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--brand-900);
  white-space: nowrap;
}

.sidebar__logo-sub {
  font-size: var(--text-2xs);
  color: var(--muted);
  white-space: nowrap;
}

.app--sidebar-collapsed .sidebar__logo-title,
.app--sidebar-collapsed .sidebar__logo-sub {
  display: none;
}

.sidebar__nav {
  flex: 1;
  padding: var(--sp-3) var(--sp-2);
  overflow-y: auto;
}

.sidebar__section-label {
  font-size: var(--text-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--sidebar-group-text);
  padding: var(--sp-4) var(--sp-3) var(--sp-1);
}

.sidebar__footer {
  flex-shrink: 0;
  padding: var(--sp-3) var(--sp-2);
  border-top: 1px solid var(--line-light);
}

.sidebar__user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-md);
}

.sidebar__avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 600;
  flex-shrink: 0;
}

.sidebar__user-name {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
}

.sidebar__user-role {
  font-size: var(--text-2xs);
  color: var(--muted);
  white-space: nowrap;
}

.app--sidebar-collapsed .sidebar__user-name,
.app--sidebar-collapsed .sidebar__user-role {
  display: none;
}


/* --- Nav Items --- */
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-3);
  height: var(--sidebar-item-h);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--ink-secondary);
  transition: background 150ms ease, color 150ms ease;
  white-space: nowrap;
  text-decoration: none;
}

.nav-item:hover {
  background: var(--sidebar-item-hover);
  color: var(--ink);
}

.nav-item--active {
  background: var(--sidebar-item-active-bg);
  color: var(--sidebar-item-active-text);
  font-weight: 500;
  box-shadow: var(--shadow-xs);
}

.nav-item__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-item__icon svg {
  width: 20px;
  height: 20px;
}

.nav-item__label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app--sidebar-collapsed .nav-item__label {
  display: none;
}


/* --- Nav Group (expandable) --- */
.nav-group__toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-3);
  height: var(--sidebar-item-h);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--ink-secondary);
  width: 100%;
  transition: background 150ms ease, color 150ms ease;
}

.nav-group__toggle:hover {
  background: var(--sidebar-item-hover);
  color: var(--ink);
}

.nav-group__arrow {
  margin-left: auto;
  width: 16px;
  height: 16px;
  transition: transform 200ms ease;
}

.nav-group__arrow svg {
  width: 16px;
  height: 16px;
}

.nav-group--open .nav-group__arrow {
  transform: rotate(90deg);
}

.nav-group__children {
  display: none;
  padding-left: var(--sp-8);
}

.nav-group--open .nav-group__children {
  display: block;
}

.nav-group__child {
  display: block;
  padding: var(--sp-1_5) var(--sp-3);
  font-size: var(--text-sm);
  color: var(--ink-secondary);
  border-radius: var(--radius-sm);
  transition: background 150ms ease, color 150ms ease;
  text-decoration: none;
}

.nav-group__child:hover {
  background: var(--sidebar-item-hover);
  color: var(--ink);
}

.nav-group__child--active {
  color: var(--sidebar-item-active-text);
  font-weight: 500;
}

.nav-group__child--disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.6;
}


/* --- Header --- */
.header {
  grid-area: header;
  height: var(--header-h);
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  box-shadow: var(--header-shadow);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-6);
  gap: var(--sp-4);
  z-index: var(--z-sticky);
}

.header__breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-sm);
  color: var(--ink-secondary);
  flex-shrink: 0;
}

.header__breadcrumb a {
  color: var(--ink-secondary);
  transition: color 150ms ease;
}

.header__breadcrumb a:hover {
  color: var(--ink);
}

.header__breadcrumb-sep {
  color: var(--muted);
  font-size: var(--text-2xs);
}

.header__breadcrumb-current {
  color: var(--ink);
  font-weight: 500;
}

.header__spacer {
  flex: 1;
}

.header__search {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--header-search-bg);
  border-radius: var(--radius-md);
  padding: var(--sp-2) var(--sp-3);
  max-width: 480px;
  width: 100%;
  cursor: pointer;
  transition: background 150ms ease;
}

.header__search:hover {
  background: var(--surface-mid);
}

.header__search-icon {
  width: 16px;
  height: 16px;
  color: var(--header-search-text);
  flex-shrink: 0;
}

.header__search-icon svg {
  width: 16px;
  height: 16px;
}

.header__search-text {
  font-size: var(--text-sm);
  color: var(--header-search-text);
}

.header__search-kbd {
  font-size: var(--text-2xs);
  color: var(--muted);
  background: var(--surface-raised);
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--line-light);
  margin-left: auto;
}

.header__spacer2 {
  flex: 1;
}

.header__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
}

.header__icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--header-icon-color);
  transition: background 150ms ease, color 150ms ease;
  position: relative;
}

.header__icon-btn:hover {
  background: var(--surface-mid);
  color: var(--header-icon-hover);
}

.header__icon-btn svg {
  width: 20px;
  height: 20px;
}

.header__badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: var(--status-danger);
  border-radius: var(--radius-pill);
  border: 2px solid var(--header-bg);
}

.header__erp-status {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--text-2xs);
  font-weight: 500;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
}

.header__erp-status--ok {
  color: var(--status-ok);
  background: var(--status-ok-bg);
}

.header__erp-status--error {
  color: var(--status-danger);
  background: var(--status-danger-bg);
}

.header__erp-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
  background: currentColor;
}

.header__user-btn {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-md);
  transition: background 150ms ease;
}

.header__user-btn:hover {
  background: var(--surface-mid);
}

.header__user-name {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ink);
}

.header__logout-form {
  display: flex;
  align-items: center;
  margin: 0;
}


/* --- Sub-Navigation (LNB) --- */
.lnb {
  grid-area: lnb;
  width: 220px;
  height: calc(100vh - var(--header-h));
  background: var(--surface-raised);
  border-right: 1px solid var(--line-light);
  padding: var(--sp-4) var(--sp-2);
  overflow-y: auto;
  margin-top: var(--header-h);
}

.lnb__title {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 0 var(--sp-3) var(--sp-3);
}

.lnb__item {
  display: block;
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-sm);
  color: var(--ink-secondary);
  border-radius: var(--radius-sm);
  transition: background 150ms ease, color 150ms ease;
}

.lnb__item:hover {
  background: var(--surface);
  color: var(--ink);
}

.lnb__item--active {
  background: var(--brand-50);
  color: var(--brand);
  font-weight: 500;
}


/* --- Main Content --- */
.main {
  grid-area: main;
  padding: var(--sp-8);
  overflow-y: auto;
  height: calc(100vh - var(--header-h));
}

.main__title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-6);
}

.main__title {
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--ink);
}

.main__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.main__filter-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}

.main__filter-bar .input,
.main__filter-bar .select {
  width: auto;
  flex: none;
}


/* --- Detail Panel (right side, master-detail) --- */
.detail-panel {
  display: none;
  grid-area: detail;
  width: 480px;
  height: 100vh;
  background: var(--surface-raised);
  border-left: 1px solid var(--line-light);
  box-shadow: var(--shadow-lg);
  flex-direction: column;
  z-index: var(--z-drawer);
}

.app--detail-open .detail-panel {
  display: flex;
}

.detail-panel--360 { width: 360px; }
.detail-panel--480 { width: 480px; }
.detail-panel--540 { width: 540px; }

.detail-panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--line-light);
  flex-shrink: 0;
}

.detail-panel__eyebrow {
  font-size: var(--text-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.detail-panel__title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--ink);
  margin-top: var(--sp-1);
}

.detail-panel__close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--muted);
  transition: background 150ms ease, color 150ms ease;
  flex-shrink: 0;
}

.detail-panel__close:hover {
  background: var(--surface);
  color: var(--ink);
}

.detail-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-6);
}

.detail-panel__footer {
  flex-shrink: 0;
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--line-light);
}


/* --- AI Panel --- */
.ai-panel {
  display: none;
  grid-area: ai;
  width: 360px;
  height: 100vh;
  background: var(--ai-bg);
  border-left: 1px solid var(--ai-border);
  flex-direction: column;
  z-index: var(--z-drawer);
}

.app--ai-open .ai-panel {
  display: flex;
}

.ai-panel__head {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-4);
  gap: var(--sp-3);
  border-bottom: 1px solid var(--ai-border);
  flex-shrink: 0;
}

.ai-panel__title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ai-text);
}

.ai-panel__messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4);
}

.ai-panel__input-area {
  flex-shrink: 0;
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--ai-border);
}


/* --- Sidebar Logo Link --- */
.sidebar__logo-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  text-decoration: none;
  color: inherit;
}

.sidebar__logo-img {
  border-radius: var(--radius-md);
  flex-shrink: 0;
}


/* --- AI Panel Extras --- */
.ai-panel__controls {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.ai-panel__input-row {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
}

.ai-panel__attach-btn {
  cursor: pointer;
  color: var(--muted);
  flex-shrink: 0;
  padding: var(--sp-2);
  display: flex;
  align-items: center;
}

.ai-panel__attach-btn:hover {
  color: var(--ink-secondary);
}

.ai-panel__input {
  flex: 1;
  resize: none;
}

.ai-mode-indicator {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--text-2xs);
  color: var(--ink-secondary);
}

.ai-mode-indicator__dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--status-ok);
}

.ai-log-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-12);
  text-align: center;
  color: var(--muted);
}

.ai-log-empty__icon {
  width: 32px;
  height: 32px;
  margin-bottom: var(--sp-3);
  opacity: 0.5;
}

.ai-log-empty__icon svg {
  width: 32px;
  height: 32px;
}

.ai-log-empty p {
  font-size: var(--text-sm);
}


/* --- Nav Section (from v1 nav-registry) --- */
.nav__section {
  margin-bottom: var(--sp-2);
}

.nav__section-label {
  font-size: var(--text-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--sidebar-group-text);
  padding: var(--sp-4) var(--sp-3) var(--sp-1);
  cursor: pointer;
  user-select: none;
}

.nav__section--collapsed .nav__section-items {
  display: none;
}


/* --- Onboarding Wizard --- */
.onboard-wizard {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
}

.onboard-wizard__card {
  background: var(--surface-raised);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-2xl);
  padding: var(--sp-8);
  max-width: 480px;
  width: 100%;
  text-align: center;
  position: relative;
}

.onboard-wizard__skip {
  position: absolute;
  top: var(--sp-4);
  right: var(--sp-4);
  font-size: var(--text-xs);
  color: var(--muted);
  cursor: pointer;
}

.onboard-wizard__skip:hover {
  color: var(--ink);
}

.onboard-step__icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--sp-4);
  color: var(--brand);
}

.onboard-step__icon svg {
  width: 48px;
  height: 48px;
}

.onboard-step h2 {
  font-size: var(--text-xl);
  margin-bottom: var(--sp-3);
}

.onboard-step__body {
  font-size: var(--text-sm);
  color: var(--ink-secondary);
  line-height: 1.7;
}

.onboard-wizard__dots {
  display: flex;
  justify-content: center;
  gap: var(--sp-2);
  margin: var(--sp-6) 0 var(--sp-4);
}

.onboard-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--slate-300);
}

.onboard-dot--active {
  background: var(--brand);
}

.onboard-wizard__nav {
  display: flex;
  justify-content: center;
  gap: var(--sp-2);
}


/* --- Coach Marks --- */
.coach-mark {
  position: fixed;
  z-index: var(--z-tooltip);
}

.coach-mark__content {
  background: var(--surface-raised);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-sm);
  max-width: 280px;
}

.coach-mark__content p {
  color: var(--ink-secondary);
  margin-bottom: var(--sp-2);
}


/* --- Responsive: sidebar auto-collapse below 1440px --- */
@media (max-width: 1440px) {
  .app {
    grid-template-columns: 64px 1fr;
  }
  .sidebar { width: 64px; }
  .sidebar__logo-title,
  .sidebar__logo-sub,
  .nav-item__label,
  .nav-group__label,
  .nav-group__arrow,
  .sidebar__user-name,
  .sidebar__user-role,
  .sidebar__section-label { display: none; }
  .nav-group__children { padding-left: 0; }
}

/* AI panel overlay mode below 1440px */
@media (max-width: 1440px) {
  .app--ai-open {
    grid-template-columns: 64px 1fr;
  }
  .ai-panel {
    position: fixed;
    right: 0;
    top: 0;
    box-shadow: var(--shadow-2xl);
  }
}


/* --- Utility Classes --- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--sp-1); }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.gap-6 { gap: var(--sp-6); }
.gap-8 { gap: var(--sp-8); }

/* ============================================================
   DARK MODE
   ============================================================ */
[data-theme="dark"] .sidebar__logo-title { color: var(--slate-200); }
[data-theme="dark"] .main__filter-bar { background: var(--surface-raised); border-color: var(--line); }
