/* ============================================================
   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);
  min-height: 40px;
  background: var(--header-search-bg);
  border: 1px solid var(--line-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-precision-sm);
  padding: 0 14px;
  max-width: 420px;
  width: 100%;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.header__search:hover {
  background: var(--shell-glass-bg-strong);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-precision-md);
}

.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: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--header-icon-color);
  border: 1px solid transparent;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
  position: relative;
}

.header__icon-btn:hover {
  background: var(--surface-raised);
  border-color: var(--line-subtle);
  box-shadow: var(--shadow-precision-sm);
  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);
  min-height: 30px;
  font-size: var(--text-2xs);
  font-weight: 700;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
}

.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);
  min-height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  background: rgba(255,255,255,0.58);
  transition: background 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.header__user-btn:hover {
  background: var(--surface-raised);
  border-color: var(--line-subtle);
  box-shadow: var(--shadow-precision-sm);
}

.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); }


/* ============================================================
   P0 Shell Layout Override
   ============================================================ */
.app.app--has-lnav {
  display: grid;
  grid-template-columns: var(--shell-rail-w) var(--shell-lnav-w) minmax(0, 1fr);
  grid-template-rows: var(--shell-header-h) minmax(0, 1fr);
  grid-template-areas:
    "rail header header"
    "rail lnav main";
  max-width: none;
  height: 100vh;
  margin: 0;
  background: var(--shell-surface);
}

.app.app--has-lnav.app--sidebar-collapsed {
  grid-template-columns: var(--shell-rail-w-collapsed) var(--shell-lnav-w) minmax(0, 1fr);
}

.app.app--has-lnav.app--ai-open,
.app.app--has-lnav.app--context-open {
  grid-template-columns: var(--shell-rail-w) var(--shell-lnav-w) minmax(0, 1fr) var(--shell-context-w);
  grid-template-areas:
    "rail header header context"
    "rail lnav main context";
}

.app.app--has-lnav.app--sidebar-collapsed.app--ai-open,
.app.app--has-lnav.app--sidebar-collapsed.app--context-open {
  grid-template-columns: var(--shell-rail-w-collapsed) var(--shell-lnav-w) minmax(0, 1fr) var(--shell-context-w);
}

.app-rail {
  grid-area: rail;
  background: var(--shell-rail-surface);
  border-right: 1px solid var(--shell-rail-border);
  box-shadow: inset -1px 0 0 rgba(255,255,255,0.04);
  color: var(--shell-rail-ink);
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 12px 10px;
  gap: 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.app-rail__brand,
.app-rail__footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.app-rail__items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.app-rail__logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--shell-rail-ink);
}

.app-rail__logo-img {
  border-radius: 14px;
  box-shadow: var(--shadow-md);
}

.app-rail__logo-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--shell-rail-muted);
}

.rail-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 60px;
  padding: 10px 8px;
  border-radius: 14px;
  border: 1px solid transparent;
  color: var(--shell-rail-muted);
  transition: background 150ms ease, color 150ms ease, transform 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.rail-item:hover {
  background: rgba(148, 163, 184, 0.12);
  border-color: rgba(148,163,184,0.12);
  color: var(--shell-rail-ink);
}

.rail-item--active {
  background: var(--shell-rail-active-bg);
  border-color: rgba(191,219,254,0.18);
  box-shadow: var(--shadow-precision-sm);
  color: var(--shell-rail-active-ink);
}

.rail-item--utility {
  min-height: 56px;
}

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

.rail-item__label {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.1;
}

.app-rail__logout-form {
  margin: 0;
}

.app-rail__user {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-top: 8px;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
}

.app-rail__user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-weight: 700;
}

.app-rail__user-name {
  font-size: 11px;
  font-weight: 600;
}

.app-rail__user-role {
  font-size: 10px;
  color: var(--shell-rail-muted);
}

.app--sidebar-collapsed .rail-item__label,
.app--sidebar-collapsed .app-rail__logo-label,
.app--sidebar-collapsed .app-rail__user-name,
.app--sidebar-collapsed .app-rail__user-role {
  display: none;
}

.local-nav {
  grid-area: lnav;
  background: var(--shell-lnav-surface);
  border-right: 1px solid var(--shell-lnav-border);
  backdrop-filter: blur(var(--shell-glass-blur));
  -webkit-backdrop-filter: blur(var(--shell-glass-blur));
  padding: 20px 14px 18px;
  overflow-y: auto;
}

.lnb__header {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.lnb__eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.10em;
  color: var(--muted);
}

.lnb__title-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.lnb__title {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink-strong);
}

.lnb__subtitle {
  font-size: 12px;
  color: var(--ink-secondary);
}

.lnb__content {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lnb__item {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 13px;
  color: var(--ink-secondary);
  transition: background 150ms ease, border-color 150ms ease, box-shadow 150ms ease, color 150ms ease;
}

.lnb__item:hover {
  background: var(--surface-raised);
  border-color: var(--line-subtle);
  box-shadow: var(--shadow-precision-sm);
  color: var(--ink);
}

.lnb__item--active {
  background: rgba(37,99,235,0.08);
  border-color: rgba(59,130,246,0.14);
  box-shadow: var(--shadow-precision-sm);
  color: var(--brand);
  font-weight: 600;
}

.lnb-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lnb-group__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  color: var(--ink);
  background: rgba(255,255,255,0.72);
  border: 1px solid var(--line-subtle);
  box-shadow: var(--shadow-precision-sm);
}

.lnb-group__label {
  font-size: 13px;
  font-weight: 600;
}

.lnb-group__arrow svg {
  width: 16px;
  height: 16px;
  transition: transform 150ms ease;
}

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

.lnb-group__children {
  display: none;
  padding-left: 8px;
  flex-direction: column;
  gap: 6px;
}

.lnb-group--open .lnb-group__children {
  display: flex;
}

.header {
  grid-area: header;
  height: var(--shell-header-h);
  padding: 0 20px;
  background: var(--shell-glass-bg);
  border-bottom: 1px solid var(--shell-glass-border);
  box-shadow: var(--shadow-precision-sm);
  backdrop-filter: blur(var(--shell-glass-blur));
  -webkit-backdrop-filter: blur(var(--shell-glass-blur));
}

.main {
  grid-area: main;
  min-width: 0;
  height: calc(100vh - var(--shell-header-h));
  padding: var(--shell-main-pad-y) var(--shell-main-pad-x);
  overflow-y: auto;
}

.workspace-body {
  min-width: 0;
  display: grid;
  gap: var(--shell-summary-gap);
}

.detail-panel,
.ai-panel {
  grid-area: context;
  width: var(--shell-context-w);
  height: 100vh;
  border-left: 1px solid var(--shell-context-border);
  background: var(--shell-context-surface);
  box-shadow: var(--shadow-precision-lg);
  backdrop-filter: blur(var(--shell-glass-blur));
  -webkit-backdrop-filter: blur(var(--shell-glass-blur));
}

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

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

.ai-panel__eyebrow {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.ai-panel {
  display: none;
  flex-direction: column;
}

.ai-panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line-subtle);
}

.ai-panel__title {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink-strong);
}

.ai-panel__controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ai-mode-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(37,99,235,0.08);
  border: 1px solid rgba(59,130,246,0.12);
  color: var(--brand);
  font-size: 11px;
  font-weight: 700;
}

.ai-mode-indicator__dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
}

.ai-chat-list-panel {
  border-bottom: 1px solid var(--line-subtle);
  background: rgba(255,255,255,0.72);
}

.ai-chat-list-panel__head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 16px 10px;
}

.ai-chat-list-panel__title {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-strong);
}

.ai-chat-list-panel__meta {
  font-size: 11px;
  color: var(--ink-secondary);
}

.ai-chat-list-panel__list {
  max-height: 180px;
  overflow-y: auto;
  padding: 0 8px 10px;
}

.ai-chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  min-height: 38px;
  padding: 0 10px;
  border-radius: 10px;
  color: var(--ink-secondary);
  transition: background 150ms ease, color 150ms ease;
}

.ai-chat-item:hover {
  background: rgba(37,99,235,0.06);
  color: var(--ink-strong);
}

.ai-chat-item--active {
  background: rgba(37,99,235,0.08);
  color: var(--brand);
}

.ai-chat-item__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
}

.ai-chat-item__delete {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--muted);
}

.ai-chat-item__delete:hover {
  background: rgba(239,68,68,0.10);
  color: var(--status-danger);
}

.ai-panel__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ai-log-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 36px 18px;
  border: 1px dashed var(--line-subtle);
  border-radius: 16px;
  background: rgba(255,255,255,0.58);
  color: var(--ink-secondary);
  text-align: center;
  font-size: 13px;
}

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

.ai-panel__input-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px 16px;
  border-top: 1px solid var(--line-subtle);
  background: rgba(255,255,255,0.72);
}

.ai-panel__attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ai-panel__helper {
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-secondary);
}

.ai-panel__input-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
}

.ai-panel__attach-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--line-subtle);
  background: rgba(255,255,255,0.96);
  color: var(--ink-secondary);
  cursor: pointer;
  box-shadow: var(--shadow-precision-sm);
}

.ai-panel__attach-btn:hover {
  color: var(--ink-strong);
  border-color: var(--line-strong);
}

.ai-panel__input {
  min-height: 40px;
  max-height: 120px;
  resize: vertical;
  padding: 10px 12px;
}

.ai-attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(37,99,235,0.08);
  border: 1px solid rgba(59,130,246,0.12);
  color: var(--brand);
}

.ai-attach-chip__name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 700;
}

.ai-attach-chip__size {
  font-size: 10px;
  color: var(--ink-secondary);
}

.ai-attach-chip__remove {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--muted);
}

.ai-attach-chip__remove:hover {
  background: rgba(239,68,68,0.12);
  color: var(--status-danger);
}

.ai-msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 100%;
}

.ai-msg__role {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.ai-msg__body {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255,255,255,0.96);
  border: 1px solid var(--line-subtle);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.6;
  box-shadow: var(--shadow-precision-sm);
}

.ai-msg--user .ai-msg__body {
  background: rgba(37,99,235,0.08);
  border-color: rgba(59,130,246,0.12);
}

.ai-msg--system .ai-msg__body,
.ai-msg--system {
  color: var(--ink-secondary);
}

.context-help-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid var(--shell-help-border);
  background: linear-gradient(180deg, var(--shell-help-bg), var(--shell-glass-bg-strong));
  box-shadow: var(--shadow-precision-sm);
}

.context-help-banner__copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.context-help-banner__title {
  color: var(--shell-help-ink);
  font-size: 14px;
}

.context-help-banner__body {
  font-size: 13px;
  color: var(--ink-secondary);
}

.context-help-banner__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 1440px) {
  .app.app--has-lnav,
  .app.app--has-lnav.app--ai-open,
  .app.app--has-lnav.app--context-open,
  .app.app--has-lnav.app--sidebar-collapsed,
  .app.app--has-lnav.app--sidebar-collapsed.app--ai-open,
  .app.app--has-lnav.app--sidebar-collapsed.app--context-open {
    grid-template-columns: var(--shell-rail-w-collapsed) minmax(220px, 248px) minmax(0, 1fr);
    grid-template-areas:
      "rail header header"
      "rail lnav main";
  }

  .detail-panel,
  .ai-panel {
    position: fixed;
    right: 0;
    top: 0;
    z-index: var(--z-drawer);
  }
}


.ai-workspace-context {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line-subtle);
  background: linear-gradient(180deg, rgba(255,255,255,0.86), rgba(244,247,251,0.96));
}

.ai-workspace-context--active {
  background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(239,244,251,0.98));
}

.ai-workspace-context__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.ai-workspace-context__eyebrow {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.ai-workspace-context__title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-strong);
}

.ai-workspace-context__clear {
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line-light);
  background: rgba(255,255,255,0.9);
  color: var(--ink-secondary);
  font-size: 11px;
  font-weight: 700;
}

.ai-workspace-context__chips,
.ai-workspace-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ai-workspace-context__chips {
  margin-bottom: 10px;
}

.ai-workspace-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line-light);
  background: rgba(255,255,255,0.92);
  color: var(--ink-secondary);
  font-size: 11px;
  font-weight: 700;
}

.ai-workspace-chip--page {
  color: var(--ink-strong);
}

.ai-workspace-chip--entity {
  border-color: rgba(37,99,235,0.2);
  background: rgba(37,99,235,0.08);
  color: rgb(37, 99, 235);
}

.ai-workspace-context__summary {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink-secondary);
}

.ai-workspace-output {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(148,163,184,0.16);
  border-radius: 14px;
  background: rgba(255,255,255,0.72);
}

.ai-workspace-output__head {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.ai-workspace-output__title {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-strong);
}

.ai-workspace-output__hint {
  font-size: 11px;
  line-height: 1.5;
  color: var(--ink-secondary);
}

.ai-workspace-output__modes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ai-workspace-output-mode {
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line-light);
  background: rgba(255,255,255,0.92);
  color: var(--ink-secondary);
  font-size: 11px;
  font-weight: 700;
}

.ai-workspace-output-mode--active {
  border-color: rgba(37,99,235,0.22);
  background: rgba(37,99,235,0.10);
  color: rgb(29, 78, 216);
}

.ai-workspace-quick-actions {
  margin-top: 10px;
}

.ai-workspace-action {
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(37,99,235,0.14);
  background: rgba(37,99,235,0.08);
  color: rgb(29, 78, 216);
  font-size: 11px;
  font-weight: 700;
}

.ai-workspace-action:hover {
  border-color: rgba(37,99,235,0.24);
  background: rgba(37,99,235,0.12);
}
