/**
 * citizen-copilot-shell.css
 * Responsive dockable citizen-action copilot shell.
 *
 * Desktop: left/right dock rail (layout side-rail, not overlay).
 * Compact: full-width canvas + collapsible drawer below breakpoint.
 *
 * No external URLs, no analytics, no persistence.
 *
 * Visual primitives are defined once in citizen-shared-tokens.css and
 * consumed here via assistant-specific aliases. The shared layer provides
 * assistant colors, typography, the radii actually used by the assistant,
 * the focus-ring geometry, status colors, transition timing, and the
 * reduced-motion collapse. This file MUST NOT change any resolved value.
 */

/* ---------------------------------------------------------------------------
   Layout-only token (geometry specific to the dock rail)
   Semantic colors/radii/motion live in citizen-shared-tokens.css.
--------------------------------------------------------------------------- */
:root {
  --copilot-rail-width: 280px;
}

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

body {
  font-family: 'Noto Sans KR', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--mvp-color-surface);
  color: var(--mvp-color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  letter-spacing: -0.3px;
}

/* ---------------------------------------------------------------------------
   Desktop dock rail (always-visible layout side-rail)
--------------------------------------------------------------------------- */
body[data-copilot-dock="left"] {
  flex-direction: row;
}

body[data-copilot-dock="right"] {
  flex-direction: row-reverse;
}

/* ---------------------------------------------------------------------------
   Copilot rail — the dock panel
--------------------------------------------------------------------------- */
.copilot-rail {
  width: var(--copilot-rail-width);
  min-width: var(--copilot-rail-width);
  max-width: var(--copilot-rail-width);
  background: var(--mvp-color-surface);
  border: 1px solid var(--mvp-color-divider);
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  overflow-x: hidden;
  height: 100vh;
  position: sticky;
  top: 0;
}

/* On desktop the canvas takes remaining width — NOT overlaid */
.demo-canvas {
  flex: 1;
  min-width: 0;  /* allow flex shrink */
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------------------------
   Rail header + dock toggle
--------------------------------------------------------------------------- */
.copilot-header {
  background: var(--mvp-color-surface);
  color: var(--mvp-color-text);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.copilot-title {
  font-size: var(--mvp-font-size-md);
  font-weight: var(--mvp-weight-semibold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.copilot-dock-toggle {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: var(--mvp-color-text);
  cursor: pointer;
  font-size: var(--mvp-font-size-md);
  padding: 3px 8px;
  border-radius: var(--mvp-radius-xs);
  flex-shrink: 0;
  line-height: 1;
  transition: background var(--mvp-transition-base);
}

.copilot-dock-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
}

.copilot-dock-toggle:focus-visible {
  outline: var(--mvp-focus-ring-width) solid var(--mvp-color-focus);
  outline-offset: var(--mvp-focus-ring-offset);
}

/* ---------------------------------------------------------------------------
   Section structure
--------------------------------------------------------------------------- */
.copilot-section {
  padding: 10px 12px;
  border-bottom: 1px solid var(--mvp-color-divider);
}

.copilot-section-title {
  font-size: var(--mvp-font-size-xs);
  font-weight: var(--mvp-weight-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--mvp-color-text-muted);
  margin-bottom: 6px;
}

/* ---------------------------------------------------------------------------
   Conversation / clarifying choices
--------------------------------------------------------------------------- */
.copilot-conversation-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 8px;
}

.conv-item {
  font-size: var(--mvp-font-size-base);
  line-height: 1.4;
  padding: 4px 6px;
  border-radius: var(--mvp-radius-sm);
  background: var(--mvp-color-surface);
  border: 1px solid var(--mvp-color-divider);
}

.conv-item--assistant {
  background: var(--mvp-color-surface-subtle);
  border-color: var(--mvp-color-border-accent);
  color: var(--mvp-color-text);
}

.copilot-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.choice-btn {
  background: var(--mvp-color-surface-2);
  border: 1px solid var(--mvp-color-divider);
  border-radius: var(--mvp-radius-sm);
  color: var(--mvp-color-text);
  cursor: pointer;
  font-size: var(--mvp-font-size-sm);
  padding: 3px 7px;
  transition: background var(--mvp-transition-fast);
}

.choice-btn:hover {
  background: var(--mvp-color-border-soft);
}

.choice-btn:focus-visible {
  outline: var(--mvp-focus-ring-width) solid var(--mvp-color-text);
  outline-offset: 1px;
}

.choice-btn:active {
  background: var(--mvp-color-border-soft);
}

/* ---------------------------------------------------------------------------
   Action explanation
--------------------------------------------------------------------------- */
.action-explanation {
  font-size: var(--mvp-font-size-base);
  line-height: 1.5;
  color: var(--mvp-color-text);
}

/* ---------------------------------------------------------------------------
   Action trace
--------------------------------------------------------------------------- */
.action-trace-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.trace-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--mvp-font-size-base);
  color: var(--mvp-color-text-muted);
  padding: 2px 0;
}

.trace-icon {
  font-size: var(--mvp-font-size-xs);
  width: 14px;
  text-align: center;
  flex-shrink: 0;
}

.trace-item--done {
  color: var(--mvp-color-success);
}

.trace-item--active {
  color: var(--mvp-color-text);
  font-weight: var(--mvp-weight-semibold);
}

/* ---------------------------------------------------------------------------
   Confirmation control (visual/local only — no submit/navigate/send)
--------------------------------------------------------------------------- */
.copilot-confirm-section {
  margin-top: auto;  /* push to bottom if rail scrolls */
}

.confirm-notice {
  font-size: var(--mvp-font-size-sm);
  color: var(--mvp-color-text-muted);
  margin-bottom: 8px;
  line-height: 1.4;
}

.confirm-controls {
  display: flex;
  gap: 6px;
}

.confirm-btn {
  flex: 1;
  border: none;
  border-radius: var(--mvp-radius-sm);
  color: var(--mvp-color-surface);
  cursor: pointer;
  font-size: var(--mvp-font-size-base);
  font-weight: var(--mvp-weight-semibold);
  padding: 6px 10px;
  transition: opacity var(--mvp-transition-fast);
}

.confirm-btn:hover {
  opacity: 0.88;
}

.confirm-btn:focus-visible {
  outline: var(--mvp-focus-ring-width) solid var(--mvp-color-text);
  outline-offset: var(--mvp-focus-ring-offset);
}

.confirm-btn:active {
  opacity: 0.75;
}

.confirm-btn--approve {
  background: var(--mvp-color-success);
}

.confirm-btn--cancel {
  background: var(--mvp-color-error);
}

/* ---------------------------------------------------------------------------
   Demo canvas
--------------------------------------------------------------------------- */
.demo-canvas__inner {
  flex: 1;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.demo-canvas__title {
  font-size: var(--mvp-font-size-2xl);
  font-weight: var(--mvp-weight-bold);
  color: #1a252f;
}

.demo-canvas__desc {
  font-size: var(--mvp-font-size-lg);
  color: var(--mvp-color-text-muted);
  line-height: 1.6;
  max-width: 560px;
}

.demo-canvas__placeholder {
  flex: 1;
  border: 2px dashed var(--mvp-color-divider);
  border-radius: var(--mvp-radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--mvp-color-text-muted);
  min-height: 260px;
}

.placeholder-icon {
  font-size: 2.5rem;
}

.placeholder-sub {
  font-size: var(--mvp-font-size-base);
  color: #aab4be;
}

.demo-canvas__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.canvas-btn {
  background: var(--mvp-color-surface-subtle);
  border: 1px solid var(--mvp-color-border-accent);
  border-radius: var(--mvp-radius-sm);
  color: var(--mvp-color-text);
  cursor: pointer;
  font-size: var(--mvp-font-size-md);
  padding: 7px 14px;
  transition: background var(--mvp-transition-fast);
}

.canvas-btn:hover {
  background: #d5eaf7;
}

.canvas-btn:focus-visible {
  outline: var(--mvp-focus-ring-width) solid var(--mvp-color-text);
  outline-offset: var(--mvp-focus-ring-offset);
}

/* ---------------------------------------------------------------------------
   Compact-mode toggle (hidden on desktop, visible below breakpoint)
--------------------------------------------------------------------------- */
.compact-toggle {
  display: none;
}

/* ---------------------------------------------------------------------------
   COMPACT MODE — below breakpoint
   Canvas takes full width; copilot becomes collapsible drawer/sheet
--------------------------------------------------------------------------- */
@media (max-width: 767px) {
  body {
    flex-direction: column !important;
  }

  body[data-copilot-dock="left"],
  body[data-copilot-dock="right"] {
    flex-direction: column;
  }

  .copilot-rail {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
    max-width: 100%;
    min-width: 100%;
    height: 60vh;
    max-height: 70vh;
    z-index: 200;
    border-top: 2px solid var(--mvp-color-surface);
    border-right: none;
    border-bottom: none;
    border-left: none;
    transform: translateY(100%);  /* hidden by default */
    transition: transform 0.25s ease-out;
    overflow-y: auto;
  }

  /* When compact-drawer-open class is added, slide up */
  body[data-copilot-dock="right"].compact-drawer-open .copilot-rail,
  body[data-copilot-dock="left"].compact-drawer-open .copilot-rail {
    transform: translateY(0);
  }

  .demo-canvas {
    width: 100%;
    height: 100vh;
  }

  /* Show the compact toggle */
  .compact-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    position: fixed;
    bottom: 12px;
    right: 16px;
    z-index: 201;
    background: var(--mvp-color-surface);
    border: none;
    border-radius: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    color: #fff;
    cursor: pointer;
    font-size: var(--mvp-font-size-md);
    font-weight: var(--mvp-weight-semibold);
    padding: 8px 16px;
    transition: background var(--mvp-transition-base), box-shadow var(--mvp-transition-base);
  }

  .compact-toggle:hover {
    background: #34495e;
    box-shadow: 0 3px 12px rgba(0,0,0,0.3);
  }

  .compact-toggle:focus-visible {
    outline: var(--mvp-focus-ring-width) solid var(--mvp-color-focus);
    outline-offset: 3px;
  }
}

/* ---------------------------------------------------------------------------
   ARIA state: drawer open — toggle text update
--------------------------------------------------------------------------- */
body.compact-drawer-open .compact-toggle .toggle-icon {
  /* arrow indicator could rotate here */
}

/* ---------------------------------------------------------------------------
   Chat shell — primary right-side panel (replaces copilot-rail)
--------------------------------------------------------------------------- */
.chat-shell {
  width: 300px;
  min-width: 300px;
  max-width: 300px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--mvp-color-surface);
  border-left: 1px solid var(--mvp-color-divider);
  overflow: hidden;
  font-family: 'Noto Sans KR', ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Apple SD Gothic Neo", sans-serif;
}

.chat-shell__header {
  background: var(--mvp-color-surface);
  color: var(--mvp-color-text);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--mvp-color-divider);
}
.chat-shell__title {
  font-weight: var(--mvp-weight-semibold);
  font-size: var(--mvp-font-size-xl);
  letter-spacing: -0.01em;
}
.chat-shell__badge {
  background: #eef0f3;
  color: #8e8ea0;
  font-size: 0.7rem;
  font-weight: var(--mvp-weight-semibold);
  padding: 3px 10px;
  border-radius: 20px;
}

/* #1121: compact partner attribution under the service title (shell only). */
.chat-shell__title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: wrap;
}
.chat-shell__attribution {
  margin: 0;
  max-width: 100%;
  font-size: 0.68rem;
  font-weight: var(--mvp-weight-medium, 500);
  letter-spacing: 0.02em;
  line-height: 1.25;
  color: var(--mvp-color-text-muted, #8e8ea0);
  word-break: break-word;
}
/* #1121: service disclosure below the composer (not official canvas). */
.chat-shell__disclosure {
  margin: 0;
  flex-shrink: 0;
  padding: 6px 14px 10px;
  font-size: 0.65rem;
  line-height: 1.35;
  color: var(--mvp-color-text-muted, #8e8ea0);
  text-align: center;
  border-top: 1px solid var(--mvp-color-divider);
  background: var(--mvp-color-surface);
  word-break: keep-all;
  overflow-wrap: anywhere;
}

/* Conversation thread */
.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-msg {
  display: flex;
  gap: 6px;
  max-width: 100%;
}
.chat-msg--user {
  justify-content: flex-end;
}
.chat-msg--ai {
  justify-content: flex-start;
}

.chat-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--mvp-color-text);
  color: var(--mvp-color-surface);
  font-size: var(--mvp-font-size-sm);
  font-weight: var(--mvp-weight-bold);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 4px;
}

.chat-bubble {
  padding: 12px 15px;
  font-size: var(--mvp-font-size-xl);
  line-height: 1.55;
  max-width: 85%;
  word-break: break-word;
}
.chat-bubble--user {
  background: var(--mvp-color-surface-subtle);
  color: var(--mvp-color-text);
  border-radius: 18px 18px 4px 18px;
}
.chat-bubble--ai {
  background: var(--mvp-color-surface-subtle);
  color: var(--mvp-color-text);
  border: 0;
  border-radius: 18px 18px 18px 4px;
}

/* Compact progress indicator */
.chat-progress {
  background: #f0f4f8;
  border: 1px solid #e0e4ec;
  border-radius: 6px;
  padding: 10px 14px;
  margin-top: 4px;
}
.chat-progress__label {
  font-size: var(--mvp-font-size-xs);
  color: #7f8c9a;
  display: block;
  margin-bottom: 6px;
}
.chat-progress__steps {
  display: flex;
  gap: 4px;
  font-size: var(--mvp-font-size-sm);
  align-items: center;
}
.chat-progress__step {
  color: #aab8c2;
  padding: 2px 6px;
  border-radius: 3px;
}
.chat-progress__step--done {
  color: var(--mvp-color-success);
  font-weight: var(--mvp-weight-semibold);
}
.chat-progress__step--active {
  background: var(--mvp-color-busy);
  color: #fff;
  font-weight: var(--mvp-weight-semibold);
}

/* Chat composer */
.chat-composer {
  border-top: 1px solid var(--mvp-color-divider);
  padding: 12px 14px 14px;
  background: var(--mvp-color-surface);
  flex-shrink: 0;
}
.chat-composer__row {
  display: flex;
  border: 1px solid #d0d0d5;
  border-radius: 22px;
  background: var(--mvp-color-surface);
  padding: 4px;
  align-items: center;
  gap: 4px;
}
.chat-composer__input {
  flex: 1;
  min-width: 0; /* allow the input to shrink inside the flex composer row on narrow viewports */
  border: none;
  border-radius: 18px;
  padding: 8px 12px;
  font-size: var(--mvp-font-size-input);
  color: var(--mvp-color-text);
  background: transparent;
  outline: none;
  font-family: inherit;
}
.chat-composer__input::placeholder {
  color: var(--mvp-color-text-muted);
}
.chat-composer__send {
  background: var(--mvp-color-accent);
  color: var(--mvp-color-surface);
  border: none;
  border-radius: 18px;
  padding: 8px 16px;
  font-size: var(--mvp-font-size-send);
  font-weight: var(--mvp-weight-semibold);
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  flex-shrink: 0;
}
.chat-composer__send:disabled,
.chat-composer__input:disabled {
  opacity: 0.4;
  cursor: default;
}
.chat-composer__hint {
  margin: 6px 0 0;
  font-size: 0.72rem;
  color: var(--mvp-color-text-muted);
  text-align: center;
}
