:root {
  color-scheme: light;
  --bg: #f4f6fa;
  --panel: #ffffff;
  --line: #e5e8ef;
  --text: #162033;
  --muted: #6a7280;
  --primary: #1f73ff;
  --primary-dark: #155bd4;
  --danger: #d92d20;
  --warning: #c77700;
  --success: #16803c;
  --sidebar: #101828;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  width: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  display: grid;
  gap: 12px;
}

.login-brand {
  padding: 0 0 10px;
  color: var(--text);
}

.login-brand span {
  color: var(--muted);
}

.login-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
}

.sidebar {
  width: 236px;
  background: var(--sidebar);
  color: white;
  min-height: 100vh;
  padding: 18px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 6px 22px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 700;
}

.brand span {
  display: block;
  margin-top: 4px;
  color: #b7c0d1;
  font-size: 12px;
}

.nav {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #d8dfec;
  text-align: left;
  padding: 12px 14px;
  margin: 2px 0;
  cursor: pointer;
  font-size: 14px;
}

.nav.active,
.nav:hover {
  background: var(--primary);
  color: white;
}

.main {
  flex: 1;
  min-width: 0;
}

.topbar {
  height: 86px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

h1 {
  margin: 0;
  font-size: 22px;
}

p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

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

#currentUserText {
  color: var(--text);
}

select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 9px 10px;
  color: var(--text);
  font: inherit;
}

textarea {
  min-height: 130px;
  width: 100%;
  resize: vertical;
}

textarea.reply-draft {
  min-width: 100%;
  min-height: 180px;
  line-height: 1.55;
}

.toolbar {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  padding: 9px 14px;
  cursor: pointer;
  font: inherit;
}

button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

button.primary:hover {
  background: var(--primary-dark);
}

.content {
  padding: 18px 24px 40px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 16px;
  overflow: hidden;
}

.card-header {
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h2 {
  margin: 0;
  font-size: 16px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 600;
  background: #fafbfe;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #edf2ff;
  color: var(--primary-dark);
}

.badge.danger {
  background: #fff1f0;
  color: var(--danger);
}

.badge.warning {
  background: #fff7e6;
  color: var(--warning);
}

.badge.success {
  background: #ecfdf3;
  color: var(--success);
}

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

.review-summary {
  display: grid;
  grid-template-columns: 180px repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.review-stat,
.review-hint {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
}

.review-stat strong {
  display: block;
  font-size: 28px;
  line-height: 1;
  margin-bottom: 8px;
}

.review-stat span,
.review-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.review-hint b {
  display: block;
  color: var(--text);
  margin-bottom: 4px;
}

.manual-draft summary {
  cursor: pointer;
  padding: 15px 16px;
  font-weight: 700;
  border-bottom: 1px solid var(--line);
}

.review-list {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.review-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.review-card.done {
  opacity: 0.78;
}

.review-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: #fafbfe;
  border-bottom: 1px solid var(--line);
}

.review-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.review-time,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.review-body {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 0;
}

.source-message,
.draft-message {
  padding: 14px;
}

.source-message {
  background: #fbfcff;
  border-right: 1px solid var(--line);
}

.source-message h3,
.draft-message h3 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.source-sender {
  font-weight: 700;
  margin-bottom: 6px;
}

.source-message p {
  margin: 0;
  color: var(--text);
  line-height: 1.6;
  white-space: pre-wrap;
}

.review-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}

.review-actions button {
  padding: 7px 10px;
}

.form {
  padding: 16px;
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 12px 16px;
  align-items: center;
}

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

.filters {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filters input {
  min-width: 220px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.check input {
  width: 16px;
  height: 16px;
}

.empty {
  padding: 26px;
  color: var(--muted);
  text-align: center;
}

.empty.small {
  padding: 12px;
  font-size: 13px;
}

.pre {
  white-space: pre-wrap;
  line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 180px;
}

.row-actions button {
  padding: 7px 10px;
}

.context-box {
  margin-top: 10px;
  max-height: 300px;
  overflow: auto;
}

.context-title {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.context-item {
  border-top: 1px solid var(--line);
  padding: 8px 0;
  font-size: 13px;
}

.context-item.highlight {
  background: #f6f9ff;
}

.context-item span {
  color: var(--muted);
  margin-right: 8px;
}

.context-item p {
  margin: 4px 0 0;
  color: var(--text);
  line-height: 1.5;
}

#statusText {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1100px) {
  .review-summary,
  .review-body {
    grid-template-columns: 1fr;
  }

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