:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #17201d;
  --muted: #5a6760;
  --line: #d9dfd8;
  --accent: #116a63;
  --accent-dark: #0b504b;
  --warn: #8a4b08;
  --error-bg: #fff2f0;
  --error-line: #f0b7ad;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
}

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

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.62rem 0.78rem;
  cursor: pointer;
  background: #ffffff;
  color: var(--ink);
}

button:hover {
  border-color: var(--accent);
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 700;
}

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

.secondary-button {
  background: #ffffff;
  color: var(--accent-dark);
  border-color: #a9c6c1;
}

.form-top-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.85rem;
}

.hidden {
  display: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.topbar h1,
.login-panel h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0;
}

.topbar p,
.subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

.topbar form {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.signed-in {
  color: var(--muted);
  font-size: 0.92rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem;
}

.form-panel,
.output-panel,
.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
}

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

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

label,
fieldset {
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
  color: var(--ink);
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c8d0ca;
  border-radius: 6px;
  color: var(--ink);
  background: #ffffff;
  padding: 0.62rem;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

.wide-field {
  margin-top: 0.85rem;
}

.field-help {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 400;
  line-height: 1.35;
}

.decision-panel {
  margin-top: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.8rem;
}

.decision-panel h2 {
  margin: 0 0 0.65rem;
  font-size: 1rem;
}

.decision-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 0.75rem;
}

.radio-group,
.special-handling-group {
  margin-bottom: 0.75rem;
}

.special-handling-group input[type="checkbox"] {
  width: auto;
  margin-top: 0.15rem;
}

.control-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 220px;
  gap: 0.85rem;
  margin-top: 0.85rem;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
  gap: 0.45rem;
}

legend {
  padding: 0 0.35rem;
  color: var(--muted);
  font-size: 0.92rem;
}

fieldset label {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  font-weight: 400;
}

input[type="radio"] {
  width: auto;
}

.special-handling-group label {
  align-items: flex-start;
  line-height: 1.25;
}

.helper-note {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 400;
  line-height: 1.35;
}

.conflict-warning {
  margin-top: 0.85rem;
  border: 1px solid #e3bd72;
  border-radius: 6px;
  background: #fff8e8;
  color: #5e3a05;
  padding: 0.72rem;
  font-size: 0.92rem;
  line-height: 1.4;
}

.conflict-override {
  margin-top: 0.55rem;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  color: #5e3a05;
  font-size: 0.92rem;
  font-weight: 700;
}

.conflict-override input[type="checkbox"] {
  width: auto;
}

.conflict-override.hidden {
  display: none;
}

.is-disabled-section {
  background: #f6f7f4;
  opacity: 0.72;
}

.length-field {
  justify-content: start;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

#status-message {
  color: var(--muted);
}

.risk-panel {
  border-bottom: 1px solid var(--line);
  padding-bottom: 1rem;
}

.risk-panel h2,
.email-subject-section h2,
.response-section h2,
.internal-notes-section h2 {
  font-size: 1rem;
  margin: 0 0 0.7rem;
}

.risk-panel dl {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0;
}

.risk-panel div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.62rem;
  min-height: 4.3rem;
}

.risk-panel dt {
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.risk-panel dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.risk-panel dd.routing-info {
  color: #245b45;
}

.response-section,
.email-subject-section,
.internal-notes-section {
  margin-top: 1rem;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.modifier-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.modifier-row button {
  padding: 0.5rem 0.62rem;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-shell {
  width: min(440px, 100%);
}

.login-form {
  margin-top: 1rem;
  display: grid;
  gap: 0.85rem;
}

.error-message {
  margin-top: 1rem;
  padding: 0.72rem;
  border: 1px solid var(--error-line);
  border-radius: 6px;
  background: var(--error-bg);
  color: #7c1e13;
}

@media (max-width: 980px) {
  .field-grid,
  .control-row,
  .risk-panel dl,
  .decision-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .topbar,
  .section-title-row {
    align-items: stretch;
    flex-direction: column;
  }

  .field-grid,
  .control-row,
  .risk-panel dl,
  .decision-grid {
    grid-template-columns: 1fr;
  }

  .topbar form,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }
}
