:root {
  --bg: #f5f2ec;
  --paper: #fffdf8;
  --ink: #1f2528;
  --muted: #667174;
  --line: #d9d2c5;
  --green: #246c5f;
  --green-dark: #174c43;
  --blue: #345c8c;
  --gold: #b9872b;
  --rose: #a64f5b;
  --shadow: 0 18px 45px rgba(31, 37, 40, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(36, 108, 95, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(52, 92, 140, 0.12), transparent 38%),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  width: min(1440px, calc(100% - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
}

.workspace,
.history-panel {
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.65rem, 2.8vw, 2.45rem);
  line-height: 1;
}

h2 {
  font-size: 1rem;
  line-height: 1.25;
}

.status-pill {
  min-width: 96px;
  padding: 8px 10px;
  border: 1px solid rgba(36, 108, 95, 0.24);
  border-radius: 999px;
  color: var(--green-dark);
  background: rgba(36, 108, 95, 0.08);
  font-size: 0.88rem;
  font-weight: 700;
  text-align: center;
}

.translator-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(360px, 1.05fr);
  gap: 20px;
  padding: 22px;
  min-height: 0;
}

.input-panel,
.output-panel {
  min-width: 0;
}

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

label,
legend {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  outline: none;
}

textarea {
  min-height: 286px;
  padding: 14px;
  line-height: 1.55;
  resize: vertical;
}

input,
select {
  height: 44px;
  padding: 0 12px;
}

textarea:focus,
input:focus,
select:focus {
  border-color: rgba(36, 108, 95, 0.72);
  box-shadow: 0 0 0 3px rgba(36, 108, 95, 0.14);
}

.controls-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 14px;
  margin-top: 14px;
}

.preserve-box {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
  margin: 16px 0 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.preserve-box legend {
  padding: 0 6px;
}

.preserve-box label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 650;
  text-transform: none;
}

.preserve-box input {
  width: 17px;
  height: 17px;
  accent-color: var(--green);
}

.action-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.action-row.compact {
  margin-top: 12px;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  color: #fff;
  background: var(--green);
}

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

.secondary-button {
  color: #fff;
  background: var(--blue);
}

.ghost-button {
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
}

.icon-button {
  width: 34px;
  min-height: 34px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  font-size: 1.35rem;
  line-height: 1;
}

.output-panel {
  display: flex;
  flex-direction: column;
  min-height: 480px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.output-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
  background: #f7f5ef;
}

.tab-button {
  min-height: 46px;
  border-radius: 0;
  color: var(--muted);
  background: transparent;
}

.tab-button.active {
  color: var(--green-dark);
  background: #fff;
  box-shadow: inset 0 -3px 0 var(--green);
}

.output-view {
  display: none;
  flex: 1;
  min-height: 0;
  padding: 18px;
}

.output-view.active {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.result-block,
.command-block {
  flex: 1;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fbfaf6;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow: auto;
}

.command-block {
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.9rem;
}

.history-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

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

.history-list {
  display: grid;
  gap: 10px;
  padding: 14px;
  overflow: auto;
}

.history-item {
  display: grid;
  gap: 8px;
  width: 100%;
  min-height: 88px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: inherit;
  background: #fff;
  text-align: left;
}

.history-item:hover {
  border-color: rgba(36, 108, 95, 0.5);
}

.history-mode {
  color: var(--green);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.history-text {
  display: -webkit-box;
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.35;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.empty-history {
  padding: 18px 8px;
  color: var(--muted);
  line-height: 1.4;
}

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

  .history-panel {
    min-height: 220px;
  }
}

@media (max-width: 780px) {
  .app-shell {
    width: min(100% - 20px, 1440px);
    margin: 10px auto;
  }

  .topbar,
  .translator-grid {
    padding: 16px;
  }

  .topbar,
  .translator-grid,
  .controls-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .translator-grid {
    display: grid;
  }

  .preserve-box {
    grid-template-columns: 1fr;
  }

  .output-tabs {
    grid-template-columns: 1fr;
  }

  .tab-button {
    min-height: 40px;
  }
}
