:root {
  --bg: #f7faf9;
  --surface: #ffffff;
  --surface-2: #f2f6f5;
  --text: #1d2730;
  --muted: #65717d;
  --line: #dce4e1;
  --teal: #00897b;
  --teal-dark: #006b61;
  --blue: #2f7eea;
  --amber: #f4a100;
  --red: #e85d5d;
  --green: #3fb86b;
  --shadow: 0 16px 38px rgba(29, 39, 48, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 56px 1fr;
  grid-template-rows: 72px 1fr;
}

.rail {
  grid-row: 1 / -1;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 78px 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rail-button,
.square-button {
  width: 40px;
  height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
}

.rail-button.active,
.rail-button:hover,
.square-button:hover {
  background: #e5f5f2;
  border-color: #b9dfd8;
  color: var(--teal-dark);
}

svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.topbar {
  grid-column: 2;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 18px;
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(10px);
}

.brand {
  width: 236px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 24px;
  font-weight: 800;
  white-space: nowrap;
}

.brand strong {
  color: var(--teal-dark);
}

.mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 18px;
}

.search {
  min-width: 260px;
  flex: 1;
  max-width: 560px;
  height: 46px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.search input {
  border: 0;
  outline: 0;
  width: 100%;
  color: var(--text);
  background: transparent;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.language-switch {
  height: 42px;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.lang-button {
  min-width: 48px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.lang-button.active {
  background: var(--surface);
  color: var(--teal-dark);
  box-shadow: 0 1px 4px rgba(29, 39, 48, 0.12);
}

.toolbar label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}

select {
  height: 42px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 0 34px 0 12px;
}

.export-button,
.upload-button,
.icon-text-button,
.text-button {
  height: 42px;
  border-radius: 8px;
  border: 1px solid #b9dfd8;
  background: #e7f6f3;
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
}

.export-button.secondary {
  border-color: #bdd4f5;
  background: #edf4ff;
  color: #1e5fb8;
}

.upload-button {
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}

.upload-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.export-button.neutral {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.export-menu {
  position: relative;
}

.field-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(420px, calc(100vw - 32px));
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  z-index: 20;
}

.field-menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.field-menu-head strong {
  color: var(--teal-dark);
  font-size: 13px;
  text-transform: uppercase;
}

.selected-order {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.selected-order strong {
  color: var(--teal-dark);
  font-size: 11px;
  text-transform: uppercase;
}

.workspace {
  grid-column: 2;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 340px;
  min-height: calc(100vh - 72px);
}

.sidebar,
.detail {
  background: var(--surface);
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 18px;
}

.panel {
  border-bottom: 1px solid var(--line);
  padding: 0 0 18px;
  margin-bottom: 18px;
}

.panel:last-child {
  border-bottom: 0;
}

.panel-title {
  text-transform: uppercase;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 14px;
}

.summary-list {
  margin: 0;
  display: grid;
  gap: 11px;
}

.summary-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.summary-list dt {
  color: var(--muted);
}

.summary-list dd {
  margin: 0;
  font-weight: 700;
}

.range-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
  margin: 10px 0 18px;
}

.filter-group {
  display: grid;
  gap: 8px;
}

.filter-group span {
  color: var(--muted);
  font-size: 12px;
}

.text-button {
  width: 100%;
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.text-button:hover {
  border-color: var(--teal);
  color: var(--teal-dark);
}

.export-field-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.mini-button {
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 0 10px;
}

.mini-button:hover {
  border-color: var(--teal);
  color: var(--teal-dark);
}

.field-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.field-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  padding: 5px 8px;
}

.field-tag:has(input:checked) {
  border-color: #9ed8cf;
  background: #e5f5f2;
  color: var(--teal-dark);
}

.field-tag input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--teal);
}

.field-tag em {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  display: inline-grid;
  place-items: center;
  font-size: 11px;
  font-style: normal;
  line-height: 1;
}

.quality-list {
  padding: 0;
  margin: 0;
  list-style: none;
  display: grid;
  gap: 10px;
  font-size: 13px;
}

.quality-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--muted);
}

.quality-dot {
  width: 8px;
  height: 8px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--teal);
  flex: 0 0 auto;
}

.content {
  min-width: 0;
  padding: 20px;
  display: grid;
  gap: 16px;
  align-content: start;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
}

.stat {
  min-height: 86px;
  padding: 18px;
  border-right: 1px solid var(--line);
  display: grid;
  align-content: center;
  gap: 4px;
}

.stat:last-child {
  border-right: 0;
}

.stat strong {
  font-size: 24px;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
}

.analytics,
.table-panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.section-head {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.section-head.compact {
  min-height: 64px;
}

h2,
p {
  margin: 0;
}

h2 {
  font-size: 15px;
  color: var(--teal-dark);
  text-transform: uppercase;
}

.section-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.chart-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 28px;
  align-items: center;
  padding: 22px;
}

.donut {
  width: 210px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(var(--green) 0 20%, var(--blue) 20% 40%, var(--amber) 40% 60%, #8f74d8 60% 80%, var(--red) 80% 100%);
  position: relative;
  display: grid;
  place-items: center;
}

.donut::after {
  content: attr(data-total) "\A words";
  white-space: pre;
  width: 116px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--surface);
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--text);
  font-weight: 800;
  line-height: 1.3;
  box-shadow: inset 0 0 0 1px var(--line);
}

.bars {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 92px 1fr 64px;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.bar-track {
  height: 11px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
}

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

th,
td {
  height: 45px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: #fbfcfc;
  font-size: 12px;
  font-weight: 800;
}

th button {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font-weight: inherit;
}

tbody tr {
  transition: background 0.15s ease;
}

tbody tr:hover,
tbody tr.selected {
  background: #eef8f6;
}

.lemma-button {
  border: 0;
  background: transparent;
  color: #0867c9;
  font-weight: 750;
  padding: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 24px;
  border-radius: 6px;
  padding: 0 7px;
  font-size: 12px;
  font-weight: 800;
}

.pill.level {
  color: #fff;
  background: var(--blue);
}

.pill.pos {
  color: var(--teal-dark);
  background: #e5f5f2;
}

.stars {
  color: var(--amber);
  white-space: nowrap;
}

.detail {
  border-left: 1px solid var(--line);
  padding: 22px;
  position: sticky;
  top: 72px;
  height: calc(100vh - 72px);
  overflow: auto;
}

.detail-empty {
  color: var(--muted);
  min-height: 220px;
  display: grid;
  place-items: center;
  text-align: center;
}

.detail h1 {
  font-size: 26px;
  margin: 0 0 12px;
  color: var(--teal-dark);
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}

.detail-section {
  border-top: 1px solid var(--line);
  padding-top: 17px;
  margin-top: 17px;
}

.detail-section h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--teal-dark);
  text-transform: uppercase;
}

.sense {
  border-left: 3px solid #b9dfd8;
  padding-left: 12px;
  margin-bottom: 16px;
}

.sense p,
.detail-section p,
.detail-section li {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.sense strong {
  color: var(--text);
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.metric strong {
  font-size: 16px;
}

.loading {
  padding: 28px;
  color: var(--muted);
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 230px minmax(0, 1fr);
  }

  .detail {
    grid-column: 1 / -1;
    position: static;
    height: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .toolbar label span {
    display: none;
  }
}

@media (max-width: 840px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .rail {
    display: none;
  }

  .topbar {
    grid-column: 1;
    flex-wrap: wrap;
    align-items: stretch;
  }

  .brand {
    width: 100%;
  }

  .search {
    max-width: none;
    min-width: 100%;
  }

  .toolbar {
    width: 100%;
    flex-wrap: wrap;
  }

  .toolbar label,
  .toolbar select,
  .export-button,
  .upload-button,
  .language-switch,
  .export-menu {
    flex: 1;
    min-width: 132px;
  }

  .export-menu .export-button {
    width: 100%;
  }

  .field-menu {
    left: 0;
    right: auto;
    width: min(100%, calc(100vw - 24px));
  }

  .field-menu-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .field-tag {
    font-size: 11px;
    min-height: 28px;
    padding: 4px 7px;
  }

  .workspace {
    grid-column: 1;
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .stat-grid {
    grid-template-columns: 1fr 1fr;
  }

  .content,
  .stat-grid,
  .analytics,
  .table-panel {
    min-width: 0;
    width: 100%;
    overflow: hidden;
  }

  .table-wrap {
    max-width: 100%;
  }

  .chart-layout {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .bars {
    width: 100%;
  }
}

/* ===== Desktop responsive width fix (Cloudflare deployment) ===== */
/* Prevent long toolbar/content from forcing the whole page wider than viewport. */
.app-shell {
  grid-template-columns: 56px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  max-width: 100%;
  overflow-x: hidden;
}

.topbar {
  min-width: 0;
}

.brand,
.search,
.toolbar {
  min-width: 0;
}

.workspace {
  min-width: 0;
  max-width: 100%;
  min-height: 0;
}

/* Typical laptop / desktop widths: put filters on a second row instead of
   pushing the page off-screen. */
@media (max-width: 1680px) {
  .topbar {
    flex-wrap: wrap;
    align-items: center;
    row-gap: 10px;
  }

  .brand {
    width: 236px;
    flex: 0 0 236px;
  }

  .search {
    flex: 1 1 360px;
    max-width: none;
  }

  .toolbar {
    flex: 1 0 100%;
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }

  .toolbar label,
  .toolbar select,
  .export-button,
  .upload-button,
  .language-switch,
  .export-menu {
    max-width: 100%;
  }

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

  .detail {
    grid-column: 1 / -1;
    position: static;
    height: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: 210px minmax(0, 1fr);
  }

  .content {
    padding: 14px;
  }

  .stat-grid {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }

  .stat:nth-child(3) {
    border-right: 0;
  }

  .stat:nth-child(-n + 3) {
    border-bottom: 1px solid var(--line);
  }

  .chart-layout {
    grid-template-columns: 200px minmax(0, 1fr);
    gap: 18px;
  }

  .donut {
    width: 180px;
  }
}
