/* ============================================================
   Platform shared design system
   Source: prototype/html-v1/styles.css (colors/typography/cards)
   :root tokens copied verbatim; component rules copied for the
   classes listed in .superpowers/sdd/task-5-brief.md; shell-only
   chrome classes appended at the bottom using the REAL html-v1
   variable names (no invented variables).
   ============================================================ */

:root {
  --page-gutter: 12px;
  --bg: #f4f6f2;
  --surface: #ffffff;
  --surface-2: #f9faf7;
  --line: #dfe5dc;
  --line-strong: #c8d2c7;
  --text: #172019;
  --muted: #69746c;
  --green: #1f7a63;
  --green-dark: #125642;
  --amber: #b8751a;
  --red: #b64f3d;
  --blue: #376f98;
  --violet: #6d6598;
  --navy: #315f7a;
  --navy-dark: #21475f;
  --navy-soft: #eef5f8;
  --rank-up: #c94538;
  --rank-up-soft: #fff0ed;
  --rank-down: #236bb8;
  --rank-down-soft: #edf5ff;
  --shadow: 0 18px 40px rgba(24, 32, 25, 0.08);
  --radius: 8px;
  --font: Inter, Pretendard, "Noto Sans KR", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html {
  background: var(--bg) !important;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 24px;
  min-height: 72px;
  padding: 0 clamp(18px, 3.2vw, 48px);
  background: rgba(244, 246, 242, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

/* 디자인 로고: 인사이트(성장 막대)를 담은 위치 핀 + 그라디언트 워드마크 */
.brand {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 11px;
  min-height: 34px;
  overflow: visible;
  text-decoration: none;
}

.brand-mark {
  display: block;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  color: var(--text);
}

.brand-name {
  display: inline-flex;
  align-items: baseline;
  overflow: visible;
  font-family: var(--font);
  font-size: 18px;
  letter-spacing: -0.045em;
  line-height: 1;
  white-space: nowrap;
}

.brand-name span {
  font-weight: 500;
}

.brand-name strong {
  color: var(--green);
  font-weight: 900;
}

.topbar-tail {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  justify-self: end;
  gap: 10px;
}

.topbar .login-widget {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto;
  min-width: 0;
  justify-content: flex-end;
  flex: 0 0 auto;
}

.topbar .login-widget.is-authenticated {
  padding: 4px 5px 4px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
}

.topbar .login-state {
  width: auto;
  min-width: 0;
  max-width: 200px;
  overflow: hidden;
  font-size: 14px;
  font-weight: 650;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .tier-badge {
  flex: 0 0 auto;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  background: var(--surface);
}

.topbar .tier-badge[data-tier="member"] {
  border-color: #3b5bdb;
  color: #3b5bdb;
  background: rgba(59, 91, 219, 0.08);
}

.topbar .tier-badge[data-tier="master"] {
  border-color: #b7791f;
  color: #8a5a12;
  background: rgba(183, 121, 31, 0.12);
}

.topbar .login-button {
  width: max-content;
  min-width: 76px;
  padding: 8px 13px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  border-radius: 10px;
  cursor: pointer;
  flex: 0 0 auto;
  white-space: nowrap;
}

.topbar .login-button:hover {
  border-color: var(--green);
  color: var(--green);
}

.topbar .login-button[data-logged-in="true"] {
  min-width: 0;
  padding: 6px 11px;
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  border-color: transparent;
  border-radius: 999px;
}

.topbar .login-button[data-logged-in="true"]:hover {
  color: #c0392b;
  border-color: currentColor;
  background: rgba(192, 57, 43, 0.06);
}

/* Member gateway: the actual workspace is mounted only after Supabase Auth
   and the tenant membership endpoint both succeed. */
.auth-gate {
  display: grid;
  min-height: calc(100vh - 77px);
  place-items: center;
  padding: clamp(24px, 5vw, 72px) var(--page-gutter);
}

.auth-card {
  display: grid;
  grid-template-columns: minmax(260px, 0.85fr) minmax(340px, 1.15fr);
  grid-template-areas:
    "intro content"
    "intro demo";
  width: min(920px, 100%);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-intro {
  grid-area: intro;
  min-height: 510px;
  padding: clamp(34px, 5vw, 58px);
  background: var(--navy-dark);
  color: #fff;
}

.auth-eyebrow {
  margin: 0 0 18px;
  color: #9ed4c6;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.auth-intro h1 {
  max-width: 310px;
  margin: 0;
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.12;
  letter-spacing: -0.055em;
}

.auth-intro > p:last-child {
  max-width: 320px;
  margin: 26px 0 0;
  color: rgba(255, 255, 255, 0.74);
  font-size: 15px;
  line-height: 1.75;
}

.auth-loading,
.auth-forms,
.auth-setup {
  grid-area: content;
  align-self: center;
  margin: 46px clamp(28px, 5vw, 64px) 20px;
}

.auth-loading {
  display: flex;
  align-items: center;
  gap: 13px;
  color: var(--muted);
}

.auth-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: auth-spin 0.8s linear infinite;
}

@keyframes auth-spin {
  to { transform: rotate(360deg); }
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 26px;
  padding: 4px;
  border-radius: 10px;
  background: var(--surface-2);
}

.auth-tab {
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.auth-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(24, 32, 25, 0.08);
}

.auth-form {
  display: grid;
  gap: 15px;
}

.auth-form label {
  display: grid;
  gap: 7px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.auth-form input {
  width: 100%;
  height: 44px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.auth-form input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 122, 99, 0.12);
}

.auth-form .auth-consent {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.45;
}

.auth-form .auth-consent input {
  width: 16px;
  height: 16px;
  margin: 1px 0 0;
  flex: 0 0 auto;
  accent-color: var(--green);
}

.auth-form .auth-consent a {
  color: var(--navy);
  text-underline-offset: 2px;
}

.auth-captcha {
  min-height: 65px;
}

.auth-mfa-enrollment {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  text-align: center;
}

.auth-mfa-enrollment img {
  width: min(220px, 100%);
  aspect-ratio: 1;
  border: 8px solid #fff;
  border-radius: 8px;
}

.auth-mfa-enrollment code {
  max-width: 100%;
  padding: 7px 9px;
  overflow-wrap: anywhere;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
}

.auth-mfa-enrollment p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.auth-submit {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border: 1px solid var(--navy);
  border-radius: 8px;
  background: var(--navy);
  color: #fff;
  font-weight: 800;
}

.auth-submit:hover {
  border-color: var(--navy-dark);
  background: var(--navy-dark);
}

.auth-submit:disabled {
  cursor: wait;
  opacity: 0.65;
}

.auth-text-button {
  justify-self: start;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--navy);
  font-size: 13px;
  font-weight: 700;
}

.auth-help,
.auth-form-heading span,
.auth-setup p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.auth-form-heading {
  display: grid;
  gap: 6px;
  margin-bottom: 6px;
}

.auth-form-heading strong,
.auth-setup strong {
  font-size: 20px;
  letter-spacing: -0.025em;
}

.auth-setup {
  display: grid;
  gap: 14px;
}

.auth-message {
  margin: 16px 0 0;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  line-height: 1.55;
}

.auth-message[data-tone="error"] {
  border-color: rgba(182, 79, 61, 0.28);
  background: #fff5f2;
  color: var(--red);
}

.auth-message[data-tone="success"] {
  border-color: rgba(31, 122, 99, 0.25);
  background: #f0f8f5;
  color: var(--green-dark);
}

.auth-demo-link {
  grid-area: demo;
  align-self: end;
  justify-self: center;
  margin: 12px 28px 34px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-underline-offset: 4px;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 42px;
  margin-top: 10px;
  border: 0;
  border-radius: 8px;
  background: var(--navy);
  color: #ffffff;
  font-weight: 800;
}

.primary-button:hover {
  background: var(--navy-dark);
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 62px;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
}

.secondary-button:hover {
  border-color: rgba(49, 95, 122, 0.45);
  color: var(--navy-dark);
}

.secondary-button:disabled,
.secondary-button.is-running {
  cursor: wait;
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--muted);
}

.secondary-button.danger {
  color: var(--red);
}

.secondary-button.danger:hover {
  border-color: rgba(182, 79, 61, 0.48);
  background: #fff5f2;
  color: #8f2f20;
}

.scenario-select,
.text-input {
  height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

.text-input {
  width: 100%;
  padding: 0 12px;
}

.scenario-select:focus,
.text-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 122, 99, 0.14);
}

.metric-tile {
  min-height: 70px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.metric-tile span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-tile strong {
  display: block;
  margin-top: 5px;
  font-size: 19px;
  line-height: 1.25;
  white-space: nowrap;
}

.metric-tile .timestamp-value {
  font-size: 14px;
  line-height: 1.35;
  white-space: normal;
}

.dashboard-command {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 4px 0 18px;
  border-bottom: 2px solid var(--text);
}

.dashboard-command h2 {
  margin: 0;
  line-height: 1.25;
  font-size: 24px;
}

.dashboard-command p {
  max-width: 940px;
  margin-bottom: 0;
}

.analysis-board {
  display: grid;
  gap: 14px;
  padding: 0;
}

.analysis-table-wrap {
  overflow-x: auto;
  border-top: 2px solid var(--text);
}

/* ============================================================
   Shell chrome (platform-only; not present in html-v1)
   Placeholder -> real html-v1 variable mapping:
     --border         -> --line
     --accent         -> --green
     --surface-strong -> --navy-soft (html-v1's own "active surface"
                         token, used consistently for active/selected
                         states: .chip.active, .explore-history-item.active,
                         .admin-slot-meta strong)
   ============================================================ */

.category-nav {
  display: flex;
  gap: 6px;
  justify-content: center;
  justify-self: center;
}

.cat-item {
  position: relative;
}

/* 버튼과 드롭다운 사이를 이동할 때 hover가 끊기지 않도록 투명 연결 영역을 둔다. */
.cat-item::before {
  content: "";
  position: absolute;
  top: 100%;
  right: -10px;
  left: -10px;
  height: 12px;
}

.cat-button {
  padding: 10px 18px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  border-radius: 10px;
  white-space: nowrap;
}

.cat-button::after {
  content: "";
  display: inline-block;
  margin-left: 7px;
  width: 6px;
  height: 6px;
  border-right: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  opacity: 0.5;
  transition: transform 0.15s ease;
}

.cat-button.active {
  background: var(--navy-soft);
  color: var(--text);
}

.cat-item:hover .cat-button::after,
.cat-item.dropdown-open .cat-button::after {
  transform: translateY(0) rotate(45deg);
  opacity: 0.9;
}

/* 상단 카테고리 아래로 펼쳐지는 세부 메뉴 드롭다운 */
.cat-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 190px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.14s ease, transform 0.14s ease;
  z-index: 60;
}

.cat-item:hover .cat-dropdown,
.cat-item.dropdown-open .cat-dropdown {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.dropdown-item {
  text-align: left;
  padding: 9px 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px;
  font-size: 14px;
  white-space: nowrap;
}

.dropdown-item:hover {
  background: var(--bg);
  color: var(--text);
}

.dropdown-item.active {
  color: var(--green);
  font-weight: 600;
  background: var(--navy-soft);
}

.category-panel {
  display: none;
}

.category-panel.active {
  display: block;
}

.view-host {
  display: none;
}

.view-host.active {
  display: block;
  padding: var(--page-gutter);
}

@media (max-width: 1120px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  }
}

@media (max-width: 820px) {
  .topbar {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    min-height: 72px;
    padding: 0 clamp(18px, 3.2vw, 30px);
  }

  .brand-name {
    font-size: 18px;
  }

  .topbar-tail {
    margin-left: auto;
  }

  .topbar .login-widget {
    display: none;
  }

  .category-nav {
    order: 3;
    width: 100%;
    justify-content: stretch;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .cat-item {
    flex: 1 0 auto;
  }

  .cat-button {
    width: 100%;
    padding: 9px 12px;
    font-size: 12px;
  }

  .view-host.active {
    padding: 10px;
  }

  .auth-gate {
    min-height: calc(100vh - 66px);
    padding: 12px;
  }

  .auth-card {
    grid-template-columns: 1fr;
    grid-template-areas: "intro" "content" "demo";
  }

  .auth-intro {
    min-height: 0;
    padding: 30px 26px;
  }

  .auth-intro h1 {
    max-width: none;
    font-size: 30px;
  }

  .auth-intro > p:last-child {
    margin-top: 15px;
  }

  .auth-loading,
  .auth-forms,
  .auth-setup {
    margin: 28px 24px 12px;
  }

  .auth-demo-link {
    margin-bottom: 28px;
  }
}

@media (max-width: 720px) {
  .topbar {
    min-height: 64px;
    padding: 0 16px;
  }

  .brand-mark {
    width: 31px;
    height: 31px;
  }

  .brand-name {
    font-size: 17px;
  }
}

/* Action 라우트에서는 브라우저 전체 스크롤을 잠그고 내부 패널만 스크롤한다. */
@media (min-width: 1181px) {
  body.place-action-route {
    height: 100dvh;
    overflow: hidden;
  }

  body.place-action-route > .app {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  body.place-action-route .view-root {
    min-height: 0;
    overflow: hidden;
  }

  body.place-action-route .category-panel.active,
  body.place-action-route .view-host.active,
  body.place-action-route .place-bundle {
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  body.place-action-route .view-host.active {
    padding-right: var(--page-gutter);
    padding-left: var(--page-gutter);
  }
}
.route-error { margin: 24px; padding: 20px; border: 1px solid #e2b8b0; border-radius: 8px; background: #fff7f5; color: #8f3528; }
.route-error strong { display: block; font-size: 17px; }
.route-error p { margin: 8px 0 14px; }
.route-error button { min-height: 38px; padding: 0 14px; border: 1px solid currentColor; border-radius: 7px; background: #fff; color: inherit; font: inherit; font-weight: 700; }
