:root {
  --page: #f4f7f5;
  --surface: #ffffff;
  --surface-muted: #f7faf8;
  --ink: #172326;
  --heading: #102b2c;
  --muted: #526467;
  --accent: #417175;
  --border: #cbdad5;
  --input-border: #aebfba;
  --topbar: #ffffff;
  --topbar-ink: #102b2c;
  --topbar-status: #526467;
  --button-hover: #e8f1ee;
  --logo-divider: #cbdad5;
  color: var(--ink);
  background: var(--page);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  --page: #142022;
  --surface: #1d2b2d;
  --surface-muted: #192628;
  --ink: #edf5f1;
  --heading: #ffffff;
  --muted: #b5c8c3;
  --accent: #9dcc3b;
  --border: #405553;
  --input-border: #5a706d;
  --topbar: #102b2c;
  --topbar-ink: #ffffff;
  --topbar-status: #c9dad6;
  --button-hover: #2a4141;
  --logo-divider: #42605c;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--page); -webkit-text-size-adjust: 100%; }
body { min-width: 320px; min-height: 100vh; min-height: 100dvh; margin: 0; overflow-x: hidden; background: var(--page); }
button, input, textarea, select { font: inherit; }
button { min-height: 40px; cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid #8fbfc0; outline-offset: 2px; }

.topbar { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 32px; border-bottom: 1px solid var(--border); background: var(--topbar); color: var(--topbar-ink); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-logo { width: auto; height: 30px; object-fit: contain; }
.brand-logo-dark { display: none; }
:root[data-theme="dark"] .brand-logo-light { display: none; }
:root[data-theme="dark"] .brand-logo-dark { display: block; }
.brand-divider { width: 1px; height: 24px; background: var(--logo-divider); }
.brand-product { white-space: nowrap; }
.connection { min-width: 0; display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.status { color: var(--topbar-status); font-size: 14px; }
.status.ready { color: var(--accent); }
.status.error { color: #ffc2b6; }
.role-badge { padding: 5px 8px; border: 1px solid var(--accent); border-radius: 999px; color: var(--accent); font-size: 12px; font-weight: 800; white-space: nowrap; }
button { border: 1px solid var(--border); border-radius: 4px; padding: 9px 13px; background: var(--surface); color: var(--heading); font-weight: 650; }
button:hover { border-color: var(--accent); background: var(--button-hover); }
.topbar button { border-color: var(--border); background: var(--surface); }
.topbar .danger { border-color: #bb6657; color: #c46c5e; }
.topbar .danger:hover { border-color: #bb6657; background: #fff0ec; color: #9d4438; }
:root[data-theme="dark"] .topbar .danger:hover { background: #482b29; color: #ffb2a3; }
.compact-select { width: auto; min-height: 36px; padding: 6px 8px; background: var(--surface); color: var(--heading); }
.icon-button { width: 36px; min-width: 36px; padding: 6px; font-size: 18px; line-height: 1; }
.mobile-menu-toggle { display: none; }
.menu-icon { width: 20px; display: grid; gap: 4px; }
.menu-icon span { display: block; height: 2px; border-radius: 2px; background: currentColor; transition: transform .2s ease, opacity .2s ease; }

main { width: min(1240px, calc(100% - 48px)); margin: 0 auto; padding: 52px 0 64px; }
.access-panel { max-width: 700px; padding: 28px 0 38px; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
h1, h2 { margin: 0; color: var(--heading); letter-spacing: 0; }
h1 { font-size: 34px; line-height: 1.15; }
h2 { font-size: 20px; }
.access-panel > p:last-child { max-width: 600px; color: var(--muted); line-height: 1.55; }

.workspace { border-top: 1px solid var(--border); padding-top: 22px; }
.workspace-nav { display: flex; gap: 8px; margin-bottom: 24px; overflow-x: auto; border-bottom: 1px solid var(--border); scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
.workspace-nav button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; }
.workspace-nav button.active { border-bottom-color: var(--accent); color: var(--accent); }
.dao-page { min-height: 320px; }
.list-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.muted, .dao-index-status { color: var(--muted); }
.dao-groups { display: grid; gap: 24px; margin-top: 28px; }
.dao-group { border-top: 1px solid var(--border); padding-top: 18px; }
.dao-group h3, .detail-section h3 { margin: 0 0 8px; color: var(--heading); font-size: 17px; }
.dao-index-status { margin: 0 0 14px; font-size: 13px; }
.dao-list-item { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) auto; align-items: center; gap: 14px; margin: 8px 0; padding: 14px; text-align: left; }
.dao-list-item span { overflow-wrap: anywhere; color: var(--muted); font-size: 13px; }
.dao-list-item span:last-child { color: var(--accent); font-weight: 700; }
.detail-heading { margin: 24px 0; }
.detail-heading h2 { font-size: 26px; overflow-wrap: anywhere; }
.detail-heading p:last-child { max-width: 760px; color: var(--muted); line-height: 1.5; }
.detail-section { border-top: 1px solid var(--border); padding: 20px 0; }
.detail-section summary { margin-bottom: 14px; color: var(--heading); cursor: pointer; font-weight: 700; }
.detail-fields { display: grid; grid-template-columns: minmax(130px, 220px) minmax(0, 1fr); gap: 8px 18px; margin: 0; }
.detail-fields dt { color: var(--muted); font-size: 13px; }
.detail-fields dd { min-width: 0; margin: 0; overflow-wrap: anywhere; font-size: 14px; }
.detail-fields .detail-fields { margin: 8px 0; }
.detail-array { display: grid; gap: 12px; }
.detail-array > .detail-fields { padding: 12px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface-muted); }
.detail-token-panel { max-width: 520px; margin-top: 12px; padding-top: 24px; border-top: 1px solid var(--border); }
.token-selector { display: flex; gap: 0; width: max-content; max-width: 100%; overflow-x: auto; border: 1px solid var(--border); -webkit-overflow-scrolling: touch; }
.token-selector button { border: 0; border-right: 1px solid var(--border); border-radius: 0; min-width: 118px; background: transparent; }
.token-selector button:last-child { border-right: 0; }
.token-selector button.active { background: var(--heading); color: var(--surface); }
.type-note { min-height: 23px; margin: 14px 0 22px; color: var(--muted); font-size: 14px; }
.operator-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.surface { padding: 22px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.inspect-dao { grid-column: 1 / -1; }
.section-title { margin-bottom: 18px; }
.admin-notice { margin-bottom: 18px; padding: 13px 14px; border-left: 4px solid var(--accent); background: var(--surface-muted); color: var(--ink); }
.admin-notice strong { color: var(--heading); }
.admin-notice p { margin: 5px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; color: var(--ink); font-size: 14px; font-weight: 650; }
input, textarea { width: 100%; min-height: 40px; padding: 9px 10px; border: 1px solid var(--input-border); border-radius: 4px; background: var(--surface); color: var(--heading); }
textarea { min-height: 76px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 16px; min-height: 16px; }
.primary { border-color: var(--heading); background: var(--heading); color: var(--surface); }
.primary:hover { background: var(--accent); color: #102b2c; }
.danger { border-color: #bb6657; background: var(--surface); color: #c46c5e; }
.danger:hover { background: #fff0ec; }
.command-row { display: flex; gap: 10px; }
.inline-form { grid-template-columns: minmax(0, 1fr) auto; align-items: start; }
.result { min-height: 100px; max-height: 310px; overflow: auto; margin: 18px 0 0; padding: 14px; border: 1px solid var(--border); background: var(--surface-muted); color: var(--ink); font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; white-space: pre-wrap; }
.result.empty { color: var(--muted); }
.activity { position: fixed; right: 24px; bottom: 24px; width: min(460px, calc(100% - 48px)); padding: 14px 16px; border-left: 4px solid var(--accent); background: var(--heading); color: var(--surface); box-shadow: 0 10px 28px rgba(16, 43, 44, .25); line-height: 1.45; }
.activity.error { border-left-color: #ff9c87; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.modal { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 24px; background: rgba(16, 43, 44, .58); }
.modal[hidden] { display: none; }
.modal-dialog { width: min(560px, 100%); max-height: min(640px, calc(100vh - 48px)); overflow: auto; padding: 24px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); box-shadow: 0 20px 48px rgba(16, 43, 44, .35); }
.settings-dialog { width: min(440px, 100%); }
select { width: 100%; min-height: 40px; padding: 9px 10px; border: 1px solid var(--input-border); border-radius: 4px; background: var(--surface); color: var(--heading); }
.progress-track { height: 10px; overflow: hidden; border-radius: 2px; background: var(--border); }
.progress-value { width: 0; height: 100%; background: var(--accent); transition: width .25s ease; }
.operation-message { min-height: 24px; margin: 16px 0 12px; color: var(--ink); }
.operation-events { display: grid; gap: 8px; max-height: 190px; overflow: auto; margin: 0 0 20px; padding-left: 20px; color: var(--muted); font-size: 14px; line-height: 1.4; }
body.operation-active { overflow: hidden; }

@media (max-width: 760px) {
  button { min-height: 44px; }
  input, textarea, select { min-height: 44px; font-size: 16px; }
  .check input { width: 20px; min-height: 20px; }
  .topbar { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 44px; align-items: center; gap: 12px; padding: max(14px, env(safe-area-inset-top)) 16px 14px; }
  .brand { min-width: 0; }
  .brand-logo { height: 24px; }
  .brand-product { min-width: 0; overflow: hidden; font-size: 14px; text-overflow: ellipsis; }
  .mobile-menu-toggle { width: 44px; min-width: 44px; display: grid; place-items: center; padding: 10px; }
  .topbar.menu-open .menu-icon span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .topbar.menu-open .menu-icon span:nth-child(2) { opacity: 0; }
  .topbar.menu-open .menu-icon span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
  .connection { width: 100%; display: none; grid-column: 1 / -1; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding-top: 4px; border-top: 1px solid var(--border); }
  .topbar.menu-open .connection { display: grid; }
  .status { width: 100%; }
  .connection .status, .connection .role-badge { grid-column: 1 / -1; justify-self: start; }
  .connection .compact-select { width: 100%; }
  .connection .icon-button { width: 44px; min-width: 44px; }
  #settings-button, #connect-wallet { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  main { width: 100%; padding: 28px 16px calc(48px + env(safe-area-inset-bottom)); }
  .access-panel { padding: 20px 0 30px; }
  h1 { font-size: clamp(27px, 8vw, 32px); }
  .operator-grid { grid-template-columns: 1fr; }
  .inspect-dao { grid-column: auto; }
  .surface { padding: 18px 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .token-selector { width: 100%; }
  .token-selector button { flex: 1 0 auto; min-width: 0; padding-inline: 10px; }
  .dao-list-item { grid-template-columns: 1fr; gap: 4px; }
  .detail-fields { grid-template-columns: 1fr; gap: 3px; }
  .detail-fields dd { margin-bottom: 8px; }
  .list-heading { align-items: center; }
  .command-row > * { flex: 1; }
  .activity { right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); width: calc(100% - 24px); }
  .modal { align-items: end; padding: 0; }
  .modal-dialog, .settings-dialog { width: 100%; max-height: calc(100dvh - max(16px, env(safe-area-inset-top))); padding: 22px 16px calc(22px + env(safe-area-inset-bottom)); border-right: 0; border-bottom: 0; border-left: 0; border-radius: 12px 12px 0 0; }
  .operation-events { max-height: 28dvh; }
}

@media (max-width: 460px) {
  .brand-divider { display: none; }
  .connection { grid-template-columns: minmax(0, 1fr) 44px; }
  #settings-button, #connect-wallet, #logout-wallet { grid-column: 1 / -1; width: 100%; }
  .workspace-nav button { flex: 1; white-space: nowrap; }
  .token-selector { display: grid; grid-template-columns: 1fr; }
  .token-selector button { width: 100%; border-right: 0; border-bottom: 1px solid var(--border); }
  .token-selector button:last-child { border-bottom: 0; }
  .command-row, .inline-form { grid-template-columns: 1fr; flex-direction: column; }
  .command-row > *, .inline-form button { width: 100%; }
  .list-heading { align-items: stretch; flex-direction: column; }
  .list-heading button { width: 100%; }
}

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