:root {
  color-scheme: light;
  --bg: #F2F2F2;
  --paper: #F7F6F2;
  --ink: #1A1A1A;
  --muted: rgba(26,26,26,.62);
  --faint: rgba(26,26,26,.42);
  --line: rgba(26,26,26,.19);
  --line-strong: #1A1A1A;
  --wash: rgba(26,26,26,.035);
  --blue: #1649D8;
  --green: #237A4B;
  --amber: #9A6512;
  --red: #A23C43;
  --grid-line: rgba(26,26,26,.14);
  font-family: "Aptos", "Segoe UI Variable", "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #1A1A1A;
    --paper: #202020;
    --ink: #F2F2F2;
    --muted: rgba(242,242,242,.64);
    --faint: rgba(242,242,242,.42);
    --line: rgba(242,242,242,.18);
    --line-strong: #F2F2F2;
    --wash: rgba(242,242,242,.045);
    --blue: #8BA8FF;
    --green: #7ED7A5;
    --amber: #E9C078;
    --red: #FFADB3;
    --grid-line: rgba(242,242,242,.13);
  }
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #F2F2F2;
  --paper: #F7F6F2;
  --ink: #1A1A1A;
  --muted: rgba(26,26,26,.62);
  --faint: rgba(26,26,26,.42);
  --line: rgba(26,26,26,.19);
  --line-strong: #1A1A1A;
  --wash: rgba(26,26,26,.035);
  --blue: #1649D8;
  --green: #237A4B;
  --amber: #9A6512;
  --red: #A23C43;
  --grid-line: rgba(26,26,26,.14);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1A1A1A;
  --paper: #202020;
  --ink: #F2F2F2;
  --muted: rgba(242,242,242,.64);
  --faint: rgba(242,242,242,.42);
  --line: rgba(242,242,242,.18);
  --line-strong: #F2F2F2;
  --wash: rgba(242,242,242,.045);
  --blue: #8BA8FF;
  --green: #7ED7A5;
  --amber: #E9C078;
  --red: #FFADB3;
  --grid-line: rgba(242,242,242,.13);
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; }
body { overflow: hidden; background: var(--bg); color: var(--ink); }
button, a { font: inherit; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
[hidden] { display: none !important; }

.shell {
  position: relative;
  height: calc(100vh - 72px);
  min-height: 0;
  padding: 0;
  overflow: hidden;
  background: var(--bg);
}

.ambient-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .38;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(135deg, black, transparent 82%);
}

.workspace-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 286px minmax(0,1fr);
  width: 100%;
  height: 100%;
  min-height: 0;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  animation: workspaceEnter 420ms cubic-bezier(.2,.75,.25,1) both;
}

.account-panel {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
  padding: 24px 20px;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid var(--line-strong);
  background:
    linear-gradient(155deg, transparent 0 70%, color-mix(in srgb, var(--blue) 8%, transparent) 70%),
    color-mix(in srgb, var(--paper) 92%, transparent);
}

.panel-index {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: clamp(34px,5vh,66px);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  color: var(--faint);
  font: 750 11px/1 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: .12em;
}
.panel-index strong { color: var(--blue); font-size: 17px; letter-spacing: 0; }

.account-heading > span {
  color: var(--blue);
  font: 800 11px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: .11em;
}

.account-heading h1 {
  margin: 12px 0 0;
  font: 500 32px/1 Georgia, "Times New Roman", serif;
  letter-spacing: -.045em;
}

.account-heading p { margin-top: 14px; font-size: 13px; }

.brand-row, .status-card, .profile-row { display: flex; align-items: center; }
.brand-row { gap: 16px; }
.brand-badge { display: block; width: 48px; height: 48px; flex: 0 0 auto; }
.brand-copy { min-width: 0; }
.brand-wordmark {
  display: flex;
  align-items: baseline;
  margin: 0;
  font: 500 34px/.95 Georgia, "Times New Roman", serif;
  letter-spacing: -.055em;
}
.brand-wordmark-vero { color: var(--blue); font-style: italic; font-weight: 400; }
p { margin: 8px 0 0; color: var(--muted); font-size: 14px; line-height: 1.65; }
.brand-copy p { max-width: 270px; margin-top: 13px; }

.status-card {
  display: none;
  gap: 12px;
  min-height: 64px;
  margin-top: 30px;
  padding: 14px 0;
  border-block: 1px solid var(--line);
}
.status-card[data-status="error"],
body.is-extension-complete .status-card { display: flex; }
.status-card strong, .profile-row strong { display: block; font-size: 14px; font-weight: 720; }
.status-card span, .profile-row span { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; }
.status-dot { width: 9px; height: 9px; flex: 0 0 auto; background: var(--faint); }
.status-dot[data-status="success"] { background: var(--green); }
.status-dot[data-status="error"] { background: var(--red); }
.status-dot[data-status="loading"] { background: var(--blue); animation: pulse 1.2s ease-in-out infinite; }

.profile-row { gap: 11px; min-width: 0; padding: 0 0 18px; border-bottom: 1px solid var(--line); }
.profile-row img { width: 38px; height: 38px; flex: 0 0 auto; border: 1px solid var(--line-strong); object-fit: cover; }
.profile-row div { min-width: 0; }
.profile-row strong, .profile-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.membership-row {
  display: grid;
  grid-template-columns: 1fr;
  margin-top: 18px;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}
.membership-row > div { display: flex; min-width: 0; min-height: 58px; padding: 0 14px; align-items: center; justify-content: space-between; gap: 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.membership-row span, .membership-row strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.membership-row span { color: var(--faint); font: 760 11px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .07em; }
.membership-row strong { margin: 0; font: 500 18px/1 Georgia, "Times New Roman", serif; text-align: right; }

.account-note {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.account-note p { margin: 0; font-size: 13px; }
.note-index { color: var(--blue); font: 800 11px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace; }
.actions { display: grid; gap: 8px; margin-top: auto; padding-top: 30px; }

.primary-button, .ghost-button, .chat-entry-button {
  display: flex;
  min-height: 44px;
  padding: 0 14px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 760;
  text-decoration: none;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}
.primary-button, .chat-entry-button { background: var(--ink); color: var(--bg); }
.chat-entry-button { justify-content: space-between; }
.primary-button:hover, .chat-entry-button:hover, .ghost-button:hover:not(:disabled) { transform: translateY(-2px); }
.ghost-button:hover:not(:disabled) { background: var(--ink); color: var(--bg); }
.ghost-button:disabled { cursor: progress; opacity: .55; }
.chat-entry-button span:last-child { font-size: 16px; }

.library-panel { min-width: 0; min-height: 0; overflow-y: auto; background: color-mix(in srgb, var(--bg) 95%, transparent); }
.library-header {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 28px;
  min-height: 220px;
  padding: clamp(30px,5vw,72px);
  align-items: end;
  border-bottom: 1px solid var(--line-strong);
}
.library-heading-copy { max-width: 760px; }
.eyebrow, .resource-eyebrow, .detail-section-heading {
  color: var(--blue);
  font: 800 11px/1.3 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.library-header h2, .detail-meta h3 {
  margin: 16px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
  letter-spacing: -.05em;
}
.library-header h2 { max-width: 720px; font-size: clamp(38px,5vw,72px); line-height: .98; }
.library-header p { max-width: 620px; margin-top: 20px; font-size: 15px; }
.library-heading-actions { display: flex; min-height: 100%; align-items: flex-end; flex-direction: column; justify-content: space-between; }
.library-index { color: var(--faint); font: 760 11px/1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .1em; }
.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 20px;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}
.icon-button:hover { transform: rotate(-12deg); background: var(--ink); color: var(--bg); }
.icon-button.is-loading { animation: spin 850ms linear infinite; }

.tab-list { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line-strong); }
.tab-button {
  position: relative;
  display: flex;
  min-height: 58px;
  padding: 0 clamp(18px,3vw,34px);
  align-items: center;
  justify-content: space-between;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 760;
  text-align: left;
}
.tab-button:last-child { border-right: 0; }
.tab-button::before { position: absolute; top: -1px; right: 0; left: 0; height: 3px; background: var(--blue); content: ""; transform: scaleX(0); transform-origin: left; transition: transform 180ms ease; }
.tab-button.is-active { color: var(--ink); background: var(--wash); }
.tab-button.is-active::before { transform: scaleX(1); }
.tab-count { font: 760 11px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }

.list-panel { padding: clamp(16px,2.6vw,34px); }
.resource-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(390px,100%),1fr)); gap: 0; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.resource-card {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 176px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: transparent;
  animation: itemIn 300ms ease-out both;
  transition: background 160ms ease;
}
.resource-card::before { position: absolute; top: 0; left: 0; width: 3px; height: 0; background: var(--amber); content: ""; transition: height 180ms ease; }
.resource-card[data-tone="ready"]::before { background: var(--green); }
.resource-card[data-tone="failed"]::before { background: var(--red); }
.resource-card:hover { background: var(--wash); }
.resource-card:hover::before { height: 100%; }
.resource-open-button { display: grid; gap: 24px; width: 100%; min-width: 0; padding: 22px; border: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; }
.resource-card.is-deletable .resource-open-button { padding-right: 78px; }
.resource-body { min-width: 0; }
.resource-card h3 { margin: 9px 0 0; overflow: hidden; font: 500 22px/1.15 Georgia, "Times New Roman", serif; letter-spacing: -.025em; text-overflow: ellipsis; white-space: nowrap; }
.resource-card p { display: -webkit-box; margin-top: 10px; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow-wrap: anywhere; }
.resource-footer { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; }
.metric-list { display: flex; flex-wrap: wrap; gap: 10px; }
.metric-list span { color: var(--faint); font: 720 11px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.resource-open-hint { flex: 0 0 auto; color: var(--ink); font-size: 12px; font-weight: 780; text-decoration: underline; text-underline-offset: 4px; transition: transform 160ms ease; }
.resource-open-button:hover .resource-open-hint { transform: translateX(3px); }
.delete-button { position: absolute; top: 18px; right: 18px; z-index: 2; padding: 5px 0; border: 0; border-bottom: 1px solid currentColor; background: transparent; color: var(--red); cursor: pointer; font-size: 12px; font-weight: 760; }
.delete-button:disabled { color: var(--faint); cursor: progress; }

.detail-panel { min-height: 460px; }
.detail-nav { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px clamp(18px,3vw,34px); border-bottom: 1px solid var(--line-strong); background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(18px); }
.detail-back-button { min-height: 36px; padding: 0 12px; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; font-size: 13px; font-weight: 760; transition: transform 160ms ease, border-color 160ms ease; }
.detail-back-button:hover { transform: translateX(-3px); border-color: var(--line-strong); }
.detail-context { color: var(--faint); font: 760 11px/1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .1em; }
.detail-content { display: grid; gap: 20px; padding: clamp(24px,4vw,54px); }
.detail-hero { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.detail-meta { min-width: 0; }
.detail-meta h3 { font-size: clamp(30px,4vw,56px); line-height: 1; overflow-wrap: anywhere; }
.source-link { display: block; max-width: 100%; margin-top: 16px; overflow: hidden; color: var(--blue); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.detail-actions { flex: 0 0 auto; }
.knowledge-action-button { min-height: 40px; padding: 0 14px; border: 1px solid var(--line-strong); background: var(--ink); color: var(--bg); cursor: pointer; font-size: 13px; font-weight: 780; }
.knowledge-action-button:disabled { cursor: not-allowed; opacity: .55; }
.detail-action-message, .detail-error { padding: 13px 15px; border-left: 3px solid var(--line-strong); background: var(--wash); color: var(--muted); font-size: 13px; line-height: 1.55; }
.detail-action-message[data-type="success"] { border-color: var(--green); color: var(--green); }
.detail-action-message[data-type="error"], .detail-error { border-color: var(--red); color: var(--red); }
.detail-stats { display: flex; flex-wrap: wrap; gap: 14px; color: var(--faint); }
.detail-stats span { font: 730 11px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.detail-section { position: relative; display: grid; gap: 14px; padding: clamp(18px,2.4vw,28px); border: 1px solid var(--line); background: transparent; }
.detail-section::before { position: absolute; top: -1px; left: -1px; width: 4px; height: calc(100% + 2px); background: var(--blue); content: ""; }
.detail-group-fact::before { background: var(--green); }
.detail-group-opinion::before { background: var(--amber); }
.detail-group-fact .detail-section-heading { color: var(--green); }
.detail-group-opinion .detail-section-heading { color: var(--amber); }
.detail-summary > p { margin: 0; color: var(--ink); font-size: 15px; line-height: 1.75; }
.detail-item { display: grid; grid-template-columns: 34px minmax(0,1fr); gap: 14px; padding-top: 17px; border-top: 1px solid var(--line); }
.detail-item:first-of-type { padding-top: 4px; border-top: 0; }
.detail-item-index { padding-top: 2px; color: var(--faint); font: 760 11px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.detail-item blockquote { display: grid; gap: 7px; margin: 12px 0 0; padding: 13px 15px; border-left: 2px solid var(--line-strong); background: var(--wash); }
.detail-item blockquote span { color: var(--faint); font-size: 11px; font-weight: 800; letter-spacing: .08em; }
.detail-item blockquote p { margin: 0; font-size: 13px; line-height: 1.65; }
.detail-empty { margin: 0; }
.detail-item-description { font-size: 14px; }
.detail-item-description { margin: 0; color: var(--ink); line-height: 1.7; }

.list-message { display: grid; min-height: 300px; padding: 40px; place-content: center; justify-items: center; text-align: center; }
.list-message::before { display: grid; width: 48px; height: 48px; margin-bottom: 18px; place-items: center; border: 1px solid var(--line-strong); color: var(--blue); content: "· · ·"; font-weight: 900; letter-spacing: 2px; }
.list-message.error::before { color: var(--red); content: "!"; }
.list-message.loading::before { content: "↻"; animation: spin 850ms linear infinite; }
.list-message strong { font: 500 22px/1.1 Georgia, "Times New Roman", serif; }
.list-message span { margin-top: 10px; color: var(--muted); font-size: 13px; }

@keyframes workspaceEnter { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes itemIn { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .35; } }

@media (max-width: 900px) {
  body { overflow-y: auto; }
  .shell { height: auto; min-height: calc(100dvh - 72px); overflow: visible; }
  .workspace-shell { grid-template-columns: 1fr; height: auto; min-height: calc(100dvh - 72px); }
  .account-panel { border-right: 0; border-bottom: 1px solid var(--line-strong); }
  .panel-index { margin-bottom: 26px; }
  .actions { margin-top: 0; }
  .library-header { min-height: 190px; }
}

@media (max-width: 600px) {
  .shell { min-height: calc(100dvh - 56px); }
  .workspace-shell { min-height: calc(100dvh - 56px); }
  .workspace-shell { border-inline: 0; }
  .account-panel { padding: 16px 16px 18px; }
  .panel-index { margin-bottom: 16px; padding-bottom: 8px; }
  .panel-index strong { font-size: 14px; }
  .account-heading h1 { font-size: 28px; }
  .account-heading p { display: none; }
  .status-card { min-height: 48px; margin-top: 16px; padding: 10px 0; }
  .status-card[data-status="success"] { display: none; }
  .profile-row { padding: 10px 0 0; }
  .status-card[data-status="success"] + .profile-row { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
  .profile-row img { width: 32px; height: 32px; }
  .status-card span, .profile-row span { font-size: 12px; }
  .membership-row { grid-template-columns: 1fr; margin-top: 16px; }
  .membership-row > div { min-height: 54px; padding: 0 12px; }
  .membership-row strong { margin: 0; font-size: 16px; }
  .account-note { display: none; }
  .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; padding-top: 16px; }
  .primary-button, #chatButton { grid-column: 1 / -1; }
  .primary-button, .ghost-button, .chat-entry-button { min-height: 40px; font-size: 12px; }
  .library-header { position: relative; grid-template-columns: 1fr; gap: 0; min-height: 0; padding: 24px 62px 20px 16px; }
  .library-header h2 { margin-top: 12px; font-size: 30px; }
  .library-header p { display: -webkit-box; margin-top: 12px; overflow: hidden; font-size: 13px; line-height: 1.5; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
  .library-index { display: none; }
  .icon-button { width: 38px; height: 38px; }
  .library-heading-actions { position: absolute; top: 19px; right: 16px; min-height: 0; }
  .tab-list { position: sticky; z-index: 6; top: 0; background: var(--bg); }
  .tab-button { min-height: 50px; padding-inline: 14px; font-size: 12px; }
  .list-panel { padding: 8px; }
  .resource-list { grid-template-columns: 1fr; }
  .resource-card { min-height: 148px; }
  .resource-open-button { gap: 18px; padding: 18px; }
  .resource-card h3 { font-size: 20px; }
  .resource-card p { font-size: 13px; }
  .resource-footer { align-items: flex-start; flex-direction: column; }
  .detail-content { padding: 24px 18px; }
  .detail-hero { display: grid; }
  .detail-actions, .knowledge-action-button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
