:root {
  color-scheme: light;
  --ink: #203932;
  --muted: #4e685d;
  --green: #166047;
  --soft: #e7f3eb;
  --line: #d4dfd8;
  --warn: #775019;
  font: 16px/1.62 "Microsoft YaHei","Segoe UI",sans-serif;
  color: var(--ink);
  background: #f4f6f1;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

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

button,a,summary {
  touch-action: manipulation;
}

button,select,input,textarea {
  border: 1px solid #adc1b3;
  border-radius: .5rem;
}

button {
  min-height: 42px;
  padding: .42rem .9rem;
  background: white;
  color: var(--green);
  cursor: pointer;
}

button:hover:not(:disabled),summary:hover {
  background: var(--soft);
}

button:disabled {
  color: #67766d;
  background: #f2f4ef;
  cursor: not-allowed;
}

button.primary,button[type=submit] {
  color: white;
  background: var(--green);
  border-color: var(--green);
}

button[type=submit]:disabled,.primary:disabled {
  background: #d9e1db;
  color: #526358;
  border-color: #cdd7ce;
}

button:focus-visible,a:focus-visible,summary:focus-visible,input:focus-visible,select:focus-visible,textarea:focus-visible {
  outline: 3px solid #b67413;
  outline-offset: 2px;
}

h1,h2,h3,h4,p {
  margin: 0 0 .65rem;
}

h1 {
  font-size: clamp(1.55rem,3vw,2.15rem);
  line-height: 1.25;
  letter-spacing: -.03em;
}

h2 {
  font-size: 1.24rem;
}

h3 {
  font-size: 1.08rem;
}

h4 {
  font-size: 1rem;
}

label {
  display: block;
  margin: .65rem 0;
  color: var(--muted);
}

input,select,textarea {
  display: block;
  width: 100%;
  min-width: 0;
  padding: .55rem .7rem;
  color: var(--ink);
  background: white;
}

label input,label select,label textarea {
  margin-top: .25rem;
}

textarea {
  resize: vertical;
  min-height: 5rem;
}

.check {
  display: flex;
  gap: .5rem;
  align-items: center;
}

.check input {
  width: auto;
}

.topbar {
  min-height: 70px;
  background: #173e32;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem max(1.2rem,calc((100vw - 1210px)/2));
}

.brand {
  text-decoration: none;
  white-space: nowrap;
  font-size: 1.48rem;
  letter-spacing: .09em;
  font-weight: 800;
  color: white;
}

.brand span {
  font-weight: 400;
}

.identity-switch {
  display: flex;
  align-items: center;
  gap: .55rem;
  min-width: 0;
}

.identity-switch label {
  color: #dce9df;
  white-space: nowrap;
  font-size: .8rem;
}

.identity-switch select {
  max-width: min(32rem, 58vw);
  width: auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.identity-switch button {
  white-space: nowrap;
}

.workspace {
  max-width: 1250px;
  margin: auto;
  padding: 1rem 1.25rem 2rem;
}

#notice {
  background: #e5f0e8;
  padding: .6rem 1rem;
  border-radius: .5rem;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

#notice.error,#notice.pending,.pending-box {
  background: #fff3dc;
  color: var(--warn);
}

#session-summary,footer,.metadata,.small {
  color: var(--muted);
  font-size: .8rem;
  overflow-wrap: anywhere;
}

#session-summary {
  margin: .65rem 0;
}

nav {
  display: flex;
  align-items: center;
  gap: .15rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1.1rem;
}

nav button,nav a {
  font-size: .9rem;
  text-decoration: none;
  color: var(--muted);
  padding: .5rem .75rem;
  background: transparent;
  border: 0;
}

nav .active {
  color: var(--green);
  font-weight: 700;
  border-radius: 0;
  border-bottom: 3px solid var(--green);
}

nav #refresh {
  margin-left: auto;
}

[hidden],.hidden {
  display: none!important;
}

#tab-matters {
  display: grid;
  grid-template-columns: minmax(220px,26%) minmax(0,1fr);
  gap: 1.4rem;
}

aside {
  min-width: 0;
  align-self: start;
}

aside h2 {
  padding: .35rem 0;
}

aside>details,.card {
  padding: 1rem 1.15rem;
  background: white;
  border: 1px solid var(--line);
  border-radius: .8rem;
  margin: 0 0 .85rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

aside>details {
  padding: .65rem .85rem;
}

summary {
  cursor: pointer;
  color: var(--green);
  font-weight: 600;
}

.matter-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: .4rem;
  padding: .65rem .75rem;
  margin-top: .25rem;
  overflow-wrap: anywhere;
}

.matter-item.selected {
  background: var(--soft);
  box-shadow: inset 3px 0 var(--green);
}

.matter-item strong,.matter-item small {
  display: block;
}

.matter-item small,.mode-note {
  font-size: .82rem;
  color: var(--muted);
}

#matter-list {
  max-height: 57vh;
  overflow: auto;
}

.matter-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: .65rem;
}

.status,.kind {
  border-radius: .35rem;
  background: var(--soft);
  color: var(--green);
  padding: .16rem .48rem;
  font-size: .8rem;
}

.status {
  flex-shrink: 0;
}

.kind {
  display: inline-block;
  margin-right: .5rem;
}

.pending-kind {
  color: var(--warn);
  background: #fff0cf;
}

.matter-hero {
  border: 0;
  border-top: 4px solid var(--green);
}

.matter-hero .metadata {
  margin: 0 0 .25rem;
}

.progress-line {
  margin-top: .6rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: .3rem 1rem;
}

.full {
  grid-column: 1/-1;
}

.actions,.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: .5rem;
}

.inline-form label {
  flex: 1;
}

.pending-box {
  margin-top: .7rem;
  border-left: 3px solid #bd8e36;
  padding: .8rem;
}

.proposal {
  border-color: #9bbca7;
  background: #f2f8ed;
}

.proposal h3,.chat h3,.receipt h3 {
  margin-bottom: .5rem;
}

.receipt {
  border-left: 3px solid var(--green);
}

.detail {
  margin-top: .55rem;
}

.detail summary,.metadata {
  font-size: .82rem;
}

.chat-log {
  max-height: 26rem;
  overflow: auto;
}

.bubble {
  border-radius: .65rem;
  padding: .7rem .9rem;
  margin: 0 2rem .65rem 0;
  background: #f1f4ef;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble.user {
  margin: 0 0 .65rem 2rem;
  background: #e2f1e5;
}

.bubble .metadata {
  font-weight: bold;
}

.chat .actions {
  justify-content: flex-end;
}

.chat form label {
  color: var(--ink);
}

dl.values {
  display: grid;
  grid-template-columns: max-content minmax(0,1fr);
  gap: .35rem .85rem;
  margin: .55rem 0;
}

dl.values dt {
  color: var(--muted);
}

dl.values dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.insight-row {
  margin: .5rem 0;
}

.insight-row strong {
  margin-right: .65rem;
}

.issue-row,.knowledge-row {
  padding: .75rem 0;
  border-bottom: 1px solid var(--line);
}

.empty {
  padding: 2rem 1rem;
  color: var(--muted);
}

pre {
  max-width: 100%;
  overflow: auto;
  max-height: 26rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 13px/1.6 Consolas,monospace;
  background: #f1f5f0;
  padding: .7rem;
  border-radius: .4rem;
}

dialog {
  max-width: min(34rem,94vw);
  width: 100%;
  max-height: 90dvh;
  border: 1px solid var(--line);
  border-radius: .9rem;
  padding: 1.25rem;
  color: var(--ink);
  overflow-wrap: anywhere;
}

dialog::backdrop {
  background: #123d3266;
}

dialog .actions {
  justify-content: end;
  margin-top: 1rem;
}

footer {
  padding: 1rem;
  text-align: center;
}

@media(max-width:760px) {
  .topbar {
    padding: .6rem .85rem;
    gap: .65rem;
    flex-wrap: wrap;
  }

  .brand {
    font-size: 1.22rem;
  }

  .identity-switch {
    max-width: 100%;
    flex: 1 1 70%;
    justify-content: flex-end;
  }

  .identity-switch label {
    display: none;
  }

  .identity-switch select {
    width: 100%;
    min-width: 0;
    max-width: 17rem;
    font-size: .83rem;
  }

  .identity-switch button {
    font-size: .8rem;
    padding-inline: .6rem;
  }

  .workspace {
    padding: .55rem .7rem 1rem;
  }

  #session-summary {
    font-size: .75rem;
    margin: .35rem 0;
  }

  nav {
    gap: 0;
    margin-bottom: .55rem;
  }

  nav button,nav a {
    padding: .35rem .55rem;
    font-size: .82rem;
  }

  #tab-matters {
    grid-template-columns: minmax(0,1fr);
    gap: .3rem;
  }

  aside {
    display: flex;
    align-items: start;
    flex-wrap: wrap;
    gap: .25rem .55rem;
  }

  aside h2 {
    margin: 0;
    font-size: 1.08rem;
    flex: 1 1 auto;
  }

  aside>details {
    margin: 0 0 .45rem;
    padding: .32rem .55rem;
    font-size: .85rem;
  }

  aside>details[open] {
    flex: 1 1 100%;
  }

  #matter-list {
    max-height: 43vh;
  }

  .card {
    padding: .8rem .9rem;
    margin-bottom: .58rem;
  }

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

  #notice {
    font-size: .85rem;
    padding: .45rem .65rem;
  }

  .bubble {
    margin-right: .8rem;
  }

  .bubble.user {
    margin-left: .8rem;
  }

  .inline-form {
    display: block;
  }

  .matter-head {
    flex-wrap: wrap;
  }

  .progress-line {
    margin: .3rem 0;
  }

  .status {
    font-size: .75rem;
  }

}
