:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #20242c;
  --muted: #667085;
  --line: #d9dee7;
  --primary: #176b87;
  --primary-dark: #0f4f63;
  --accent: #5f7a38;
  --warn: #a15c00;
  --danger: #a33a3a;
  --soft: #eef6f8;
  --radius: 8px;
  --shadow: 0 12px 28px rgba(16, 24, 40, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 15px;
}

button,
input,
select,
textarea {
  font: inherit;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 270px;
  background: #132833;
  color: #fff;
  padding: 18px 14px;
  overflow-y: auto;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 8px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, .16);
  margin-bottom: 12px;
}

.brand span {
  display: block;
  margin-top: 3px;
  color: #b8c7cf;
  font-size: 13px;
}

.mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: #e7f3f6;
  color: #12313d;
  border-radius: 8px;
  font-weight: 800;
}

nav {
  display: grid;
  gap: 4px;
}

.nav-btn {
  width: 100%;
  border: 0;
  background: transparent;
  color: #d8e4e9;
  text-align: left;
  padding: 11px 12px;
  border-radius: 7px;
  cursor: pointer;
}

.nav-btn:hover,
.nav-btn.active {
  background: rgba(255, 255, 255, .12);
  color: #fff;
}

.shell {
  margin-left: 270px;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  min-height: 86px;
  background: rgba(246, 247, 249, .95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 26px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 27px;
  letter-spacing: 0;
}

h2 {
  font-size: 19px;
  margin-bottom: 12px;
}

h3 {
  font-size: 16px;
  margin-bottom: 8px;
}

.eyebrow {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 13px;
}

.phase-pill,
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  border-radius: 999px;
  background: #fff7e8;
  color: var(--warn);
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

.env-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  background: #e7eef8;
  color: #12436b;
}

.env-badge.staging {
  background: #fff0d6;
  color: #8a5300;
}

.env-badge.production {
  background: #fde8e8;
  color: #9d2f2f;
}

.content {
  padding: 24px 26px 42px;
}

.login-panel {
  min-height: calc(100vh - 150px);
  display: grid;
  place-items: center;
}

.login-panel .panel {
  width: min(420px, 100%);
}

.comparison-four {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.comparison-four > div {
  min-width: 0;
}

.comparison-four .preview-box,
.comparison-four textarea {
  width: 100%;
  min-height: 320px;
  max-height: 520px;
  overflow: auto;
  white-space: pre-wrap;
}

.manual-comparison-panel {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.manual-filter-bar {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 8px;
}

@media (max-width: 1200px) {
  .comparison-four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .manual-filter-bar { grid-template-columns: repeat(3, minmax(140px, 1fr)); }
}

@media (max-width: 700px) {
  .comparison-four, .manual-filter-bar { grid-template-columns: 1fr; }
}

.logout-btn {
  min-height: 30px;
  padding: 4px 9px;
  margin-left: 8px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two {
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, .9fr);
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.panel,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.card {
  padding: 16px;
}

.metric {
  min-height: 108px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 27px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.btn {
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--primary);
  color: #fff;
  min-height: 38px;
  padding: 8px 13px;
  cursor: pointer;
  font-weight: 650;
}

.btn:hover {
  background: var(--primary-dark);
}

.btn.secondary {
  background: #fff;
  color: var(--primary);
  border-color: #aac3cb;
}

.btn.secondary:hover {
  background: var(--soft);
}

.btn.warning {
  background: var(--warn);
}

.btn.danger {
  background: var(--danger);
}

.btn.ghost {
  background: transparent;
  color: var(--primary);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.control-panel {
  margin-bottom: 16px;
}

.op-status.running {
  background: #edf8ed;
  color: var(--accent);
}

.op-status.stopped {
  background: #fff7e8;
  color: var(--warn);
}

.op-status.maintenance {
  background: #eef2ff;
  color: #344054;
}

.control-actions {
  margin-top: 14px;
}

.operation-result {
  display: grid;
  gap: 6px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fbfcfd;
}

.operation-result.ok {
  border-color: #b8d6b8;
  background: #f3faf3;
}

.operation-result.warning {
  border-color: #e1c28f;
  background: #fffaf0;
}

.readiness-list {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.readiness-item {
  display: grid;
  gap: 2px;
  border-left: 4px solid var(--line);
  padding: 7px 8px;
  background: #fff;
}

.readiness-item.ready {
  border-left-color: var(--accent);
}

.readiness-item.blocked {
  border-left-color: var(--warn);
}

.readiness-item span {
  color: var(--muted);
  font-size: 13px;
}

.icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  width: 34px;
  height: 34px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

label {
  color: #344054;
  font-weight: 650;
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cbd3df;
  border-radius: 7px;
  background: #fff;
  min-height: 38px;
  padding: 9px 10px;
  color: var(--ink);
}

textarea {
  min-height: 120px;
  resize: vertical;
}

.search {
  min-width: 260px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f1f4f7;
  color: #475467;
  font-size: 12px;
  text-transform: uppercase;
}

td {
  color: #29313d;
}

tr:last-child td {
  border-bottom: 0;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag,
.status.pending_review,
.status.approved_for_learning,
.status.rejected,
.status.deleted {
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
}

.tag {
  background: #edf2f7;
  color: #344054;
}

.status.pending_review {
  background: #fff7e8;
  color: var(--warn);
}

.status.approved_for_learning {
  background: #edf8ed;
  color: var(--accent);
}

.status.rejected,
.status.deleted {
  background: #fff0f0;
  color: var(--danger);
}

.empty {
  padding: 26px;
  text-align: center;
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(16, 24, 40, .42);
  padding: 20px;
}

.modal {
  width: min(850px, 100%);
  max-height: 88vh;
  overflow: hidden;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .22);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 16px 18px;
}

.modal-head h2 {
  margin: 0;
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  max-height: calc(88vh - 68px);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 14px;
}

.field.full {
  grid-column: 1 / -1;
}

.notice {
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid #b9d3db;
  background: var(--soft);
  color: #244b58;
  margin-bottom: 14px;
}

.edit-surface {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 14px 0;
  margin: 14px 0;
}

.draft-review-panel {
  max-width: 1240px;
  margin: 0 auto;
}

.draft-review-workspace {
  display: grid;
  gap: 14px;
}

.draft-source-label {
  padding: 9px 12px;
  border-left: 3px solid var(--primary);
  background: #f4f8fa;
  color: #344054;
}

.draft-review-header {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
}

.draft-review-header div {
  min-width: 0;
}

.draft-review-header span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.draft-review-header strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.review-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 0;
}

.review-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 700;
  color: #344054;
}

.original-email-compact {
  flex: 1;
  min-width: 220px;
  overflow: hidden;
  color: var(--muted);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.review-panel[open] {
  padding-bottom: 14px;
}

.review-panel[open] > :not(summary) {
  margin-left: 14px;
  margin-right: 14px;
}

.original-email-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  color: #344054;
  margin-bottom: 12px;
}

.email-preview {
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
  padding: 12px;
  color: #29313d;
}

.ai-draft-primary {
  display: grid;
  gap: 10px;
  min-height: min(76vh, 760px);
}

.draft-title {
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--primary-dark);
}

.ai-draft-primary textarea {
  min-height: min(72vh, 700px);
  line-height: 1.55;
  font-size: 16px;
  padding: 16px;
}

.draft-empty-primary {
  min-height: min(62vh, 620px);
  grid-template-rows: auto 1fr auto;
}

.draft-empty-message {
  display: grid;
  align-content: center;
  justify-items: center;
  min-height: 360px;
  padding: 32px 20px;
  border: 1px dashed #aac3cb;
  background: #fbfcfd;
  text-align: center;
}

.draft-empty-message h3 {
  margin: 0 0 8px;
  font-size: 22px;
}

.draft-empty-message p {
  max-width: 620px;
  margin: 0;
  color: var(--muted);
}

.draft-empty-actions {
  justify-content: center;
  margin-top: 20px;
}

.recent-drafts-panel {
  padding: 14px;
  border: 1px solid var(--line);
  background: #fff;
}

.recent-draft-list {
  display: grid;
  gap: 8px;
}

.recent-draft-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.recent-draft-row:last-child {
  border-bottom: 0;
}

.recent-draft-row strong,
.recent-draft-row span {
  display: block;
}

.recent-draft-row span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.quick-improvements {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.improvement-groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.improvement-groups h4 {
  margin: 0 0 8px;
  color: #344054;
}

.draft-instruction-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-top: 12px;
}

.draft-instruction-row textarea {
  min-height: 110px;
}

.draft-instruction-row > .actions {
  max-width: 360px;
  justify-content: flex-end;
}

.instruction-empty,
.instruction-result,
.instruction-history {
  margin-top: 14px;
}

.instruction-result h4,
.instruction-history h4 {
  margin: 0 0 10px;
}

.instruction-chain {
  display: grid;
  gap: 8px;
}

.instruction-step {
  display: grid;
  gap: 6px;
}

.instruction-step > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.instruction-step .preview-box {
  max-height: 260px;
  overflow: auto;
}

.instruction-command {
  border-left: 4px solid var(--accent);
  background: #f4f8f9;
  padding: 12px;
}

.instruction-arrow {
  color: var(--primary);
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
}

.instruction-history > section {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 14px;
}

.approve-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.secondary-review-panels {
  display: grid;
  gap: 10px;
}

.quick-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px;
  margin: 4px 0 12px;
  background: #fbfcfd;
}

.check-row input {
  width: auto;
  min-height: auto;
}

.proposal-panel {
  border-color: #9ec4cf;
  background: #fbfeff;
}

.recommendation-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(180px, .7fr) minmax(220px, .8fr);
  gap: 12px;
}

.success-note {
  border-color: #bad9bd;
  background: #f1faf1;
  color: #345f35;
}

.version-arrow {
  text-align: center;
  font-weight: 700;
  color: var(--primary);
  padding: 12px;
}

.version-list {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.version-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fbfcfd;
}

.version-item .muted {
  display: block;
  margin-top: 2px;
}

.knowledge-group {
  margin: 14px 0;
}

.knowledge-group h4 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.muted {
  color: var(--muted);
}

.split-preview {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.preview-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fbfcfd;
  min-height: 160px;
  white-space: pre-wrap;
}

.knowledge-preview {
  max-height: 420px;
  overflow-y: auto;
  line-height: 1.55;
}

.metadata-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.metadata-grid > div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
  padding: 10px;
}

mark {
  background: #fff2a8;
  padding: 1px 2px;
  border-radius: 3px;
}

@media (max-width: 980px) {
  .sidebar {
    position: static;
    width: auto;
  }

  .shell {
    margin-left: 0;
  }

  nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid.two,
  .grid.three,
  .grid.four,
  .draft-review-header,
  .improvement-groups,
  .draft-instruction-row,
  .recommendation-grid,
  .split-preview,
  .metadata-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .ai-draft-primary,
  .ai-draft-primary textarea {
    min-height: 60vh;
  }

  .recent-draft-row {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    align-items: flex-start;
    gap: 12px;
    flex-direction: column;
  }
}
.operational-backup-panel {
  margin-bottom: 16px;
}

.backup-result {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-subtle, #f7f8fa);
}

.backup-result code {
  overflow-wrap: anywhere;
}

.btn.disabled {
  pointer-events: none;
  opacity: 0.5;
}
