:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #627086;
  --line: #dce3ee;
  --accent: #315fdc;
  --accent-soft: #edf2ff;
  --green: #12805c;
  --green-soft: #e9f7f1;
  --red: #b42318;
  --red-soft: #fff0ee;
  --amber: #b7791f;
  --shadow: 0 6px 18px rgba(21, 37, 68, .08);
}

* { box-sizing: border-box; }
html { overflow-x: hidden; }
body {
  margin: 0;
  min-width: 0;
  overflow-x: hidden;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button, select { font: inherit; }
button {
  min-height: 40px;
  max-width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: #fff;
  color: #193064;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
}
button.primary { background: #70e0b5; color: #102a25; }
button.secondary { background: rgba(255,255,255,.16); color: #fff; outline: 1px solid rgba(255,255,255,.32); }
button:disabled { opacity: .55; cursor: not-allowed; }
select {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: white;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 18px 24px;
  background: linear-gradient(135deg, #172033, #27468f);
  color: white;
}
.topbar > div:first-child { min-width: 0; max-width: 100%; }
.topbar h1 {
  margin: 4px 0 6px;
  font-size: 27px;
  line-height: 1.15;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}
.topbar p {
  margin: 0;
  color: #dce6ff;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
  max-width: 380px;
}
.actions button { flex: 0 1 auto; }
.run-status {
  flex: 1 0 100%;
  min-height: 18px;
  color: #dce6ff;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
  text-align: right;
  overflow-wrap: anywhere;
}
.run-status strong { color: #fff; }
.run-status.error { color: #ffd7d2; }

.layout {
  display: grid;
  grid-template-columns: minmax(190px, .72fr) minmax(280px, .95fr) minmax(420px, 2fr);
  align-items: start;
  gap: 14px;
  width: 100%;
  max-width: 1920px;
  margin: 0 auto;
  padding: 14px;
}
.panel {
  min-width: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.folders,
.inbox,
.detail {
  min-width: 0;
  min-height: min(640px, calc(100vh - 130px));
  max-height: calc(100vh - 130px);
  overflow: auto;
}
.folders { padding: 14px; }
.panel h2 {
  margin: 0 0 8px;
  font-size: 19px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.panel h3 {
  margin: 18px 0 8px;
  font-size: 15px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.mailbox {
  margin: 8px 0;
  padding: 8px;
  background: #f0f4ff;
  border: 1px solid #d7e1ff;
  border-radius: 8px;
  font-weight: 800;
  font-size: 14px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.mailbox span { color: var(--accent); }
.folder-lang {
  margin: 6px 0;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}
.folder-lang h4 { margin: 0 0 4px; font-size: 14px; line-height: 1.2; }
.folder-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 6px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
}
.folder-row span { min-width: 0; overflow-wrap: anywhere; }
.folder-row strong { flex: 0 0 auto; color: var(--ink); }
.dot {
  width: 9px;
  height: 9px;
  display: inline-block;
  flex: 0 0 auto;
  border-radius: 999px;
  margin-right: 8px;
}
.dot.new { background: var(--accent); }
.dot.ans { background: var(--green); }
.dot.unresolved { background: var(--red); }
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 14px 6px;
}
.section-head > div { min-width: 0; }
.section-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.section-head select { flex: 0 0 auto; }
.email-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px 10px 14px;
}
.email-card {
  min-width: 0;
  padding: 11px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: .12s ease;
}
.email-card:hover,
.email-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(49,95,220,.10);
}
.email-card.didactic-focus,
.email-body.didactic-focus,
.analysis-block.didactic-focus,
.score-row.didactic-focus,
.cards.didactic-focus,
pre.didactic-focus {
  outline: 3px solid rgba(49,95,220,.22);
  outline-offset: 3px;
}
.email-card h4 {
  margin: 0;
  font-size: 13px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.email-card .sub {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 5px 8px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}
.email-card .sub span { min-width: 0; overflow-wrap: anywhere; }
.badge {
  display: inline-flex;
  flex: 0 0 auto;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
}
.badge.New { background: var(--accent-soft); color: var(--accent); }
.badge.Answered { background: var(--green-soft); color: var(--green); }
.badge.NotResolved,
.badge.Not.Resolved { background: var(--red-soft); color: var(--red); }

.detail { padding: 16px; }
#detailView { min-width: 0; }
.empty-state {
  display: grid;
  place-content: center;
  min-height: 100%;
  padding: 40px;
  color: var(--muted);
  text-align: center;
}
.empty-state p { max-width: 42rem; line-height: 1.45; overflow-wrap: anywhere; }
.hidden { display: none !important; }
.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.detail-header > div { min-width: 0; }
.detail-header h2 {
  margin: 4px 0;
  font-size: 21px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.detail-header p {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.status-badge {
  display: inline-flex;
  max-width: 100%;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  line-height: 1.2;
}
.email-body {
  max-width: 100%;
  margin: 12px 0;
  padding: 14px;
  white-space: pre-wrap;
  background: #fafbfe;
  border: 1px solid var(--line);
  border-radius: 8px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.analysis-block {
  min-width: 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.score-row > div:first-child { min-width: 0; }
.score-row p {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.score-ring {
  display: grid;
  flex: 0 0 auto;
  place-content: center;
  width: 78px;
  height: 78px;
  border-radius: 999px;
  background: conic-gradient(var(--accent) 0deg, var(--accent) 250deg, #e8edf7 250deg);
  font-size: 18px;
  font-weight: 900;
}
.score-ring span {
  display: grid;
  place-content: center;
  width: 58px;
  height: 58px;
  background: white;
  border-radius: 999px;
}
.bar {
  height: 14px;
  margin: 12px 0;
  position: relative;
  overflow: hidden;
  background: #e8edf7;
  border-radius: 999px;
}
.bar span {
  display: block;
  width: 0%;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .35s ease;
}
.bar i {
  position: absolute;
  top: -4px;
  bottom: -4px;
  left: 82%;
  width: 3px;
  background: #1d2738;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  max-width: 100%;
  padding: 5px 8px;
  background: #f1f4f9;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr));
  gap: 10px;
}
.integration-card {
  min-width: 0;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.integration-card strong {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.integration-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.integration-status {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 2px 7px;
  background: #f1f4f9;
  font-size: 11px;
  font-weight: 900;
  line-height: 1.25;
}
pre {
  max-width: 100%;
  padding: 14px;
  overflow-x: hidden;
  white-space: pre-wrap;
  background: #0f172a;
  color: #eaf0ff;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.teaching-popover {
  position: fixed;
  z-index: 50;
  width: min(380px, calc(100vw - 28px));
  max-width: calc(100vw - 28px);
  padding: 18px 48px 18px 20px;
  background: #102033;
  color: #f8fbff;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 8px;
  box-shadow: 0 18px 44px rgba(12, 24, 44, .26);
  line-height: 1.45;
  overflow-wrap: anywhere;
  transition: opacity .16s ease, transform .16s ease;
}
.teaching-popover strong {
  display: block;
  margin-bottom: 8px;
  font-size: 16px;
  line-height: 1.3;
}
.teaching-popover p {
  margin: 0;
  color: #dce6ff;
  font-size: 15px;
}
.teaching-close {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-content: center;
  width: 32px;
  min-height: 32px;
  height: 32px;
  padding: 0;
  color: #f8fbff;
  background: rgba(255,255,255,.12);
  border-radius: 999px;
  box-shadow: none;
}

@media (min-width: 1101px) {
  html,
  body { height: 100%; }
  body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .topbar { flex: 0 0 auto; }
  .layout {
    flex: 1 1 auto;
    grid-template-rows: minmax(0, 1fr);
    align-items: stretch;
    min-height: 0;
    overflow: hidden;
  }
  .folders,
  .inbox,
  .detail {
    height: auto;
    min-height: 0;
    max-height: none;
  }
}

@media (max-width: 1280px) {
  .topbar { padding: 16px 20px; }
  .topbar h1 { font-size: 26px; }
  .layout {
    grid-template-columns: minmax(176px, .75fr) minmax(260px, 1fr) minmax(360px, 1.55fr);
  }
}

@media (max-width: 1100px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 16px;
  }
  .actions {
    width: 100%;
    max-width: none;
    justify-content: flex-start;
  }
  .run-status { text-align: left; }
  .layout {
    grid-template-columns: minmax(220px, .8fr) minmax(0, 1.2fr);
  }
  .folders {
    min-height: 0;
    max-height: none;
    overflow: visible;
  }
  .inbox {
    min-height: 420px;
    max-height: 560px;
    overflow: auto;
  }
  .detail {
    grid-column: 1 / -1;
    min-height: 520px;
    max-height: 72vh;
    overflow: auto;
  }
}

@media (max-width: 760px) {
  .topbar { padding: 20px 18px; }
  .topbar h1 { font-size: 26px; }
  .actions button { flex: 1 1 170px; }
  .layout {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }
  .folders,
  .inbox,
  .detail {
    min-height: 0;
    max-height: none;
  }
  .folders { overflow: visible; }
  #folderTree {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px 14px;
  }
  .folder-lang { margin: 0; }
  .inbox {
    height: clamp(360px, 52dvh, 500px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .inbox .section-head {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
  }
  .detail {
    height: clamp(460px, 72dvh, 680px);
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-padding-block: 16px 180px;
  }
  body.teaching-active .detail { padding-bottom: 176px; }
  .folders,
  .detail { padding: 16px; }
  .section-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 16px 16px 8px;
  }
  .section-head select { width: 100%; }
  .detail-header {
    flex-direction: column;
    align-items: stretch;
  }
  .score-row { align-items: flex-start; }
  .teaching-popover {
    left: 12px !important;
    right: 12px !important;
    bottom: 12px !important;
    top: auto !important;
    width: auto;
  }
}

@media (max-width: 480px) {
  button { width: 100%; }
  .topbar { padding: 18px 12px; }
  .topbar h1 { font-size: 24px; }
  .layout { padding: 10px; gap: 10px; }
  .panel { border-radius: 8px; }
  .folders,
  .detail { padding: 14px; }
  .mailbox,
  .email-body,
  pre,
  .integration-card { padding: 12px; }
  .mailbox { font-size: 14px; }
  #folderTree { gap: 2px 10px; }
  .folder-row { padding-inline: 2px; font-size: 12px; }
  .email-list { padding: 8px 10px 14px; }
  .email-card .sub { display: grid; grid-template-columns: 1fr; }
  .score-row {
    flex-direction: column;
    gap: 12px;
  }
  .score-ring {
    width: 78px;
    height: 78px;
    font-size: 18px;
  }
  .score-ring span {
    width: 58px;
    height: 58px;
  }
  .integration-card strong {
    flex-direction: column;
    gap: 4px;
  }
}
