:root {
  --bg: #f5f7fb;
  --ink: #1f2937;
  --muted: #64748b;
  --panel: #ffffff;
  --line: #d8dee9;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --green: #047857;
  --amber: #b45309;
  --red: #b91c1c;
  --teal: #0f766e;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

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

.app-shell {
  min-height: 100vh;
  padding: 32px;
}

.workspace {
  max-width: 1180px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  background: #111827;
  border-radius: 8px;
  color: #fff;
  font-weight: 900;
}

.language-switch {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: #e8edf5;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.language-button {
  min-width: 48px;
  min-height: 34px;
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
}

.language-button.active {
  background: var(--panel);
  color: var(--accent);
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.08);
}

.intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1, h2, h3, p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: 34px;
  line-height: 1.12;
}

h2 {
  margin-bottom: 4px;
  font-size: 18px;
}

h3 {
  margin-bottom: 8px;
  font-size: 15px;
}

.summary,
.panel p,
.review-note p {
  color: var(--muted);
}

.summary {
  max-width: 680px;
  margin-bottom: 0;
  font-size: 16px;
}

.status-pill {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 138px;
  padding: 14px 18px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: 8px;
  color: var(--green);
}

.status-pill span:first-child {
  font-size: 30px;
  font-weight: 800;
}

.tool-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(260px, 0.8fr);
  gap: 18px;
  margin-bottom: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.input-panel,
.settings-panel,
.result-panel {
  padding: 20px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-header p {
  margin-bottom: 0;
  font-size: 14px;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.field-group {
  margin-bottom: 14px;
}

.field-group.flex-1 {
  flex: 1;
}

.field-row {
  display: flex;
  gap: 12px;
}

.text-input {
  width: 100%;
  min-height: 40px;
  padding: 10px 14px;
  color: var(--ink);
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.select-input {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  color: var(--ink);
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  cursor: pointer;
}

.select-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

textarea {
  width: 100%;
  resize: vertical;
  padding: 14px;
  color: var(--ink);
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

textarea.output-field {
  min-height: 160px;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

button {
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

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

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

.secondary-button,
.icon-button {
  background: #eef2f7;
  color: var(--ink);
  border: 1px solid var(--line);
}

.secondary-button:hover,
.icon-button:hover {
  background: #e2e8f0;
}

.full-width {
  width: 100%;
}

/* Settings Panel */
.settings-panel h3 {
  margin-top: 16px;
  margin-bottom: 10px;
}

.key-input-wrap {
  display: flex;
  gap: 6px;
}

.key-input-wrap .text-input {
  flex: 1;
}

.toggle-key-btn {
  min-width: 40px;
  font-size: 16px;
}

.settings-divider {
  height: 1px;
  background: var(--line);
  margin: 16px 0;
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
  color: var(--ink);
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.privacy-note {
  margin-top: 16px;
  padding: 10px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
}

.privacy-note p {
  margin: 0;
  font-size: 12px;
  color: var(--green);
}

.status-message {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  display: none;
}

.status-message.success {
  display: block;
  background: #dcfce7;
  color: var(--green);
  border: 1px solid #86efac;
}

.status-message.error {
  display: block;
  background: #fee2e2;
  color: var(--red);
  border: 1px solid #fca5a5;
}

/* Result Panel */
.result-actions {
  display: flex;
  gap: 8px;
}

.output-content {
  min-height: 120px;
}

.output-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
}

.output-sections {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.output-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fafbfc;
}

.output-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.output-section-header h3 {
  margin: 0;
  font-size: 14px;
}

.output-section-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.char-count {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.char-count.over {
  color: var(--red);
}

.output-field {
  width: 100%;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
}

.output-field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

/* Keywords */
.keyword-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.keyword-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: #e0e7ff;
  color: #3730a3;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

/* Specs Table */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

.spec-table {
  min-width: 400px;
}

th {
  padding: 11px 10px;
  background: #f1f5f9;
  color: #334155;
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
}

td {
  min-width: 120px;
  padding: 10px;
  border-top: 1px solid var(--line);
  color: var(--ink);
  vertical-align: top;
}

td[contenteditable="true"] {
  background: #fff;
  outline: none;
}

td[contenteditable="true"]:focus {
  box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.35);
}

/* Image Gallery */
.image-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.image-thumb {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #f1f5f9;
}

.image-thumb.error {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  padding: 4px;
}

/* AI Notes */
.ai-notes {
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  padding: 10px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 6px;
  margin: 0;
}

/* Loading State */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 48px 20px;
}

.fullscreen-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
}

.fullscreen-overlay[hidden] {
  display: none;
}

.fullscreen-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.fullscreen-title {
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
}

.fullscreen-step {
  color: var(--muted);
  font-size: 14px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-state p {
  color: var(--muted);
  font-size: 14px;
}

/* Error State */
.error-state {
  padding: 16px;
  background: #fee2e2;
  border: 1px solid #fca5a5;
  border-radius: 8px;
  color: var(--red);
  font-size: 14px;
}

.error-state p {
  margin: 0;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(8px);
}

.modal-backdrop[hidden] {
  display: none;
}

.guide-card {
  width: min(560px, 100%);
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.28);
}

.guide-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.modal-language {
  margin-top: 10px;
}

.close-button {
  display: grid;
  min-width: 36px;
  width: 36px;
  height: 36px;
  place-items: center;
  padding: 0;
  background: #eef2f7;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

.guide-card ol {
  margin: 18px 0 0;
  padding-left: 22px;
  color: var(--muted);
}

.guide-card li {
  margin: 10px 0;
}

.guide-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

@media (max-width: 820px) {
  .app-shell {
    padding: 18px;
  }

  .intro,
  .panel-header,
  .actions,
  .guide-actions,
  .result-actions,
  .field-row {
    align-items: stretch;
    flex-direction: column;
  }

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

  h1 {
    font-size: 27px;
  }

  .tool-grid {
    grid-template-columns: 1fr;
  }
}
