:root {
  --bg: #f6f7fb;
  --bg-alt: #eef0f7;
  --surface: rgba(255, 255, 255, 0.68);
  --surface-2: rgba(255, 255, 255, 0.82);
  --border: rgba(255, 255, 255, 0.62);
  --line: #e5e7eb;
  --text: #111827;
  --heading: #0f172a;
  --muted: #6b7280;
  --subtle: #9ca3af;
  --brand: #2563eb;
  --brand-soft: #3b82f6;
  --brand-muted: #1e3a8a;
  --success: #1F7D38;
  --warning: #A86200;
  --danger: #A11D38;
  --soft-session: #E8F8EC;
  --soft-flow: #FCE5EB;
  --soft-gem: #F4E9FB;
  --soft-research: #ECECFB;
  --soft-debug: #FFF1DD;
  --soft-output: #EFEFF4;
  --shadow-card: 0 2px 8px rgba(15, 23, 42, 0.04);
  --shadow-island: 0 18px 48px rgba(37, 99, 235, 0.10);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  color-scheme: light;
}

body {
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(60% 50% at 85% 5%, rgba(255, 200, 220, 0.55), transparent 60%),
    radial-gradient(55% 50% at 5% 25%, rgba(180, 215, 255, 0.55), transparent 65%),
    radial-gradient(55% 50% at 95% 95%, rgba(200, 230, 255, 0.50), transparent 60%),
    radial-gradient(70% 60% at 0% 100%, rgba(230, 215, 255, 0.50), transparent 65%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-alt) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-loading {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(60% 50% at 85% 5%, rgba(255, 200, 220, 0.55), transparent 60%),
    radial-gradient(55% 50% at 5% 25%, rgba(180, 215, 255, 0.55), transparent 65%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-alt) 100%);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.app-loading.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.app-loading-card {
  width: min(360px, calc(100vw - 48px));
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  padding: 22px;
  box-shadow: var(--shadow-island);
}

.brand-row,
.header-brand,
.title-row,
.header-dock,
.panel-title,
.tabs,
.form-row,
.toggle-row,
.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
}

.brand-row {
  gap: 14px;
}

.brand-row strong,
.brand-row span:not(.brand-mark) {
  display: block;
}

.brand-row strong {
  color: var(--heading);
  font-size: 18px;
  line-height: 1.2;
}

.brand-row span:not(.brand-mark) {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.brand-mark {
  display: inline-flex;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--heading), var(--brand));
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.18);
  color: #fff;
  font-weight: 800;
}

.loading-bar {
  position: relative;
  overflow: hidden;
  height: 4px;
  margin-top: 20px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.12);
}

.loading-bar span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 42%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), #34C759, #AF52DE);
  animation: app-loading-slide 1050ms ease-in-out infinite;
}

@keyframes app-loading-slide {
  0% { transform: translateX(-110%); }
  55% { transform: translateX(85%); }
  100% { transform: translateX(260%); }
}

.app-shell {
  width: min(1360px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 30px 0 52px;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
  align-items: flex-start;
  justify-content: space-between;
  padding-bottom: 22px;
}

.header-brand {
  gap: 13px;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 30px;
  background: linear-gradient(to right, #0f172a 0%, #2563eb 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: 0;
}

.header-brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.title-row {
  gap: 10px;
}

.header-dock {
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.version-pill,
.status-pill,
.metric,
.tab,
.btn-secondary,
.btn-primary,
.icon-btn,
.action-tile {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  backdrop-filter: blur(18px) saturate(170%);
  -webkit-backdrop-filter: blur(18px) saturate(170%);
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.version-pill {
  border-color: rgba(37, 99, 235, 0.28);
  border-radius: 999px;
  background: #eff6ff;
  padding: 4px 10px;
  color: var(--brand-muted);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
  font-weight: 700;
}

.metric {
  min-width: 78px;
  border-radius: 14px;
  padding: 8px 10px;
  text-align: left;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  line-height: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metric strong {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  color: var(--brand);
  font-size: 15px;
  line-height: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  min-height: 42px;
  border-radius: 999px;
  padding: 0 12px;
  color: var(--warning);
  font-weight: 700;
}

.status-ready {
  color: var(--success);
  border-color: rgba(31, 125, 56, 0.24);
  background: var(--soft-session);
}

.status-error {
  color: var(--danger);
  border-color: rgba(161, 29, 56, 0.24);
  background: var(--soft-flow);
}

.icon-btn {
  display: inline-flex;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 800;
}

.icon-btn.primary,
.btn-primary {
  border-color: rgba(37, 99, 235, 0.38);
  background: var(--brand);
  color: #fff;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.12);
}

.tabs {
  gap: 10px;
  overflow-x: auto;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.48);
  padding: 8px;
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
}

.tab {
  min-height: 44px;
  min-width: 84px;
  border-radius: 16px;
  padding: 0 12px;
  color: var(--muted);
  white-space: nowrap;
}

.tab span,
.tab strong {
  display: block;
  line-height: 1.1;
}

.tab span {
  color: var(--brand);
  font-size: 16px;
}

.tab strong {
  margin-top: 3px;
  font-size: 11px;
}

.tab.active,
.tab:hover,
.icon-btn:hover,
.metric:hover,
.version-pill:hover,
.btn-secondary:hover,
.action-tile:hover {
  border-color: rgba(37, 99, 235, 0.28);
  background: #eff6ff;
  color: var(--text);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chat-grid {
  grid-template-columns: minmax(340px, 0.85fr) minmax(420px, 1.15fr);
}

.panel {
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  padding: 16px;
}

.panel + .panel,
.grid + .panel {
  margin-top: 18px;
}

.panel-title {
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  margin-bottom: 13px;
  color: var(--heading);
  font-size: 13px;
  font-weight: 800;
}

.form-row {
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.toolbar {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.toolbar select {
  width: auto;
  min-width: 104px;
  height: 38px;
}

.path-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 8px;
}

.path-field .icon-btn {
  width: 42px;
  height: 40px;
}

label {
  min-width: 160px;
  flex: 1 1 160px;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: rgba(255, 255, 255, 0.76);
  color: var(--text);
}

input,
select {
  height: 40px;
  padding: 0 10px;
}

textarea {
  min-height: 180px;
  resize: vertical;
  padding: 12px;
}

.file-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 10px;
  margin-top: 12px;
}

#chatFiles {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-drop {
  display: flex;
  min-width: 0;
  min-height: 42px;
  align-items: center;
  gap: 10px;
  border: 1px dashed rgba(37, 99, 235, 0.38);
  border-radius: 14px;
  background: #eff6ff;
  padding: 0 12px;
  color: var(--brand-muted);
  cursor: pointer;
}

.file-drop span {
  margin: 0;
  color: var(--brand);
  font-size: 16px;
}

.file-drop strong {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(37, 99, 235, 0.55);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.toggle-row {
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

.toggle-row label {
  min-width: 0;
  flex: 0 0 auto;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch > span {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #e5e7eb;
  transition: background 140ms ease;
}

.switch > span::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.18);
  content: "";
  transition: transform 140ms ease;
}

.switch input:checked + span {
  background: var(--brand);
}

.switch input:checked + span::after {
  transform: translateX(18px);
}

.switch strong {
  color: var(--muted);
  font-size: 12px;
}

.result-box {
  min-height: 320px;
  max-height: 520px;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.74);
  padding: 14px;
  color: #1f2937;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.result-box.compact {
  min-height: 160px;
  max-height: 360px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.status-grid div {
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.58);
  padding: 12px;
}

.status-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.status-grid strong {
  display: block;
  overflow: hidden;
  margin-top: 9px;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-line {
  overflow: hidden;
  height: 8px;
  margin: 4px 0 12px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.10);
}

.progress-line span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2563eb, #34C759, #FF2D55);
  transition: width 180ms ease;
}

.quick-grid,
.list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
}

.action-tile {
  min-height: 86px;
  border-radius: 18px;
  font-size: 22px;
}

.action-tile.session-accent {
  background: var(--soft-session);
  color: var(--success);
}

.action-tile strong {
  display: block;
  margin-top: 8px;
  font-size: 13px;
}

.action-tile.danger {
  color: var(--danger);
}

.danger-soft {
  border-color: rgba(161, 29, 56, 0.24);
  background: var(--soft-flow);
  color: var(--danger);
}

.cookie-table {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.cookie-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.58);
  padding: 9px 10px;
  font-size: 12px;
}

.cookie-row strong {
  overflow: hidden;
  color: var(--heading);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 11px;
  font-weight: 800;
}

.badge.ok {
  background: var(--soft-session);
  color: var(--success);
}

.badge.warn {
  background: var(--soft-debug);
  color: var(--warning);
}

.badge.miss {
  background: var(--soft-flow);
  color: var(--danger);
}

.list-item {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.58);
  padding: 12px;
}

.list-item strong,
.list-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.list-item .item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.list-item .item-actions button {
  min-height: 30px;
  border-radius: 10px;
  padding: 0 10px;
  font-size: 12px;
}

.library-summary {
  margin-bottom: 12px;
}

.library-page-label {
  min-width: 82px;
  color: var(--muted);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.library-list {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.opal-list {
  grid-template-columns: 1fr;
}

.library-item {
  min-height: 142px;
}

.opal-item {
  min-height: 154px;
}

.library-item strong,
.library-item span,
.opal-item strong,
.opal-item span {
  white-space: normal;
}

.opal-summary {
  margin-bottom: 12px;
}

.opal-prompt {
  min-height: 150px;
  max-height: 240px;
}

.opal-notes {
  min-height: 92px;
  max-height: 160px;
  margin-top: 10px;
}

.library-path {
  display: -webkit-box;
  min-height: 32px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  word-break: break-word;
}

.library-meta {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-size: 11px;
}

.btn-secondary,
.btn-primary {
  min-height: 40px;
  border-radius: 12px;
  padding: 0 14px;
  font-weight: 800;
}

.log-console {
  height: 560px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.74);
  padding: 10px;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
}

.log-line {
  display: grid;
  grid-template-columns: 86px 84px 1fr;
  gap: 8px;
  padding: 5px 2px;
  border-bottom: 1px solid rgba(229, 231, 235, 0.88);
  color: #1f2937;
}

.log-line .level-error {
  color: var(--danger);
}

.log-line .level-warn {
  color: var(--warning);
}

.log-line .level-info {
  color: var(--brand-soft);
}

.modal {
  width: min(760px, calc(100vw - 42px));
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  color: var(--text);
  box-shadow: 0 28px 110px -36px rgba(15, 23, 42, 0.45);
  padding: 18px;
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.26);
  backdrop-filter: blur(8px);
}

.modal-head {
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-head strong,
.modal-head span {
  display: block;
}

.modal-head span {
  margin-top: 4px;
  color: var(--brand-muted);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
}

.modal-grid {
  margin-bottom: 12px;
}

.modal-actions {
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.update-links {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

@media (max-width: 980px) {
  .app-shell {
    width: min(100vw - 24px, 100%);
  }

  .grid.two,
  .chat-grid,
  .status-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
