/* =========================================================
   Editor chrome — the working tool around the invoice.
   Neutral near-black surface, flat cards, a single emerald
   accent spent on interactive elements only. One typeface
   (Inter) throughout, IBM Plex Mono for figures — matches
   the minimal system used on the invoice itself.
   ========================================================= */

:root {
  --bg: #111214;
  --panel: #18191c;
  --panel-alt: #1c1d21;
  --panel-line: #27292e;
  --text: #e7e8ea;
  --muted: #8b8d94;
  --accent: #4fae93;
  --accent-strong: #6bc4ab;
  --on-accent: #08211a;
  --danger: #d97878;
}

:root[data-theme="light"] {
  --bg: #f6f6f5;
  --panel: #ffffff;
  --panel-alt: #f1f1ef;
  --panel-line: #e2e2df;
  --text: #16171a;
  --muted: #6b6d76;
  --accent: #1e5245;
  --accent-strong: #163f35;
  --on-accent: #f6f6f5;
  --danger: #b3413f;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", sans-serif;
}

.chrome-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--panel-line);
  background: var(--panel);
}

.chrome-bar__brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
  flex: 1 1 auto;
}

.chrome-bar__mark {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
  color: var(--text);
}

.chrome-bar__title {
  font-size: 12.5px;
  color: var(--muted);
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Theme toggle ---------- */

.theme-toggle {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: 1px solid var(--panel-line);
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.theme-toggle__icon {
  width: 16px;
  height: 16px;
}

.theme-toggle__icon--moon {
  display: none;
}

:root[data-theme="light"] .theme-toggle__icon--sun {
  display: none;
}

:root[data-theme="light"] .theme-toggle__icon--moon {
  display: block;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(440px, 30vw) 1fr;
  min-height: calc(100vh - 49px);
}

/* ---------- Editor panel ---------- */

.editor {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--panel-line);
  overflow-y: auto;
  max-height: calc(100vh - 49px);
}

.editor__body {
  flex: 1;
  padding: 28px 28px 8px;
}

.editor__intro {
  margin-bottom: 22px;
}

.editor__intro h1 {
  margin: 0 0 4px;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.editor__intro p {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}

.editor__group {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 20px 20px 18px;
  margin-bottom: 16px;
}

.editor__group h2 {
  margin: 0 0 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.editor__group-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.editor__group-heading h2 {
  margin: 0;
}

.editor__footer {
  position: sticky;
  bottom: 0;
  padding: 16px 28px 24px;
  background: linear-gradient(to top, var(--bg) 65%, transparent);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 12.5px;
  color: var(--muted);
}

.field:last-child {
  margin-bottom: 0;
}

.field span {
  font-size: 11.5px;
}

input[type="text"],
input[type="date"],
input[type="number"],
textarea {
  background: var(--panel-alt);
  border: 1px solid var(--panel-line);
  border-radius: 7px;
  color: var(--text);
  padding: 10px 12px;
  font-family: "Inter", sans-serif;
  font-size: 14px;
  width: 100%;
}

textarea {
  resize: vertical;
  font-family: "Inter", sans-serif;
}

input:disabled,
textarea:disabled {
  opacity: 0.45;
}

input:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

.checkbox input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

/* ---------- Line item rows ---------- */

.line-items {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.line-item {
  background: var(--panel-alt);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  padding: 16px 16px 14px;
  position: relative;
}

.line-item__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.line-item__row:last-child {
  margin-bottom: 0;
}

.line-item__row--three {
  grid-template-columns: 1fr 1fr 1fr;
}

.line-item label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}

.line-item__desc {
  margin-bottom: 10px;
}

.line-item .readonly {
  opacity: 0.6;
}

.line-item__remove {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--danger);
  font-size: 11.5px;
  cursor: pointer;
  padding: 2px 4px;
}

.line-item__remove:hover {
  text-decoration: underline;
}

.line-item__total {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--panel-line);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  color: var(--muted);
}

.line-item__total strong {
  color: var(--accent-strong);
  font-family: "IBM Plex Mono", monospace;
  font-size: 14px;
}

/* ---------- Buttons ---------- */

.btn-ghost {
  background: none;
  border: 1px solid var(--panel-line);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 12px;
  cursor: pointer;
}

.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 8px;
  padding: 15px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
}

.btn-primary:hover {
  background: var(--accent-strong);
}

/* ---------- Preview panel ---------- */

.preview {
  padding: 40px 32px;
  overflow-y: auto;
  max-height: calc(100vh - 49px);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: var(--bg);
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .editor,
  .preview {
    max-height: none;
  }

  .editor {
    border-right: none;
    border-bottom: 1px solid var(--panel-line);
  }

  .preview {
    padding: 24px 16px 48px;
  }

  /* iOS Safari auto-zooms the page on focus of any input under
     16px — keep form fields at 16px here to avoid that jump. */
  input[type="text"],
  input[type="date"],
  input[type="number"],
  textarea {
    font-size: 16px;
  }
}

@media (max-width: 640px) {
  .chrome-bar {
    padding: 12px 16px;
  }

  .chrome-bar__title {
    font-size: 11.5px;
  }

  .editor__body {
    padding: 20px 16px 4px;
  }

  .editor__footer {
    padding: 14px 16px 20px;
  }

  .editor__intro h1 {
    font-size: 18px;
  }

  .editor__group {
    padding: 16px 16px 14px;
  }

  .field-row,
  .line-item__row--three {
    grid-template-columns: 1fr 1fr;
  }

  .line-item__row--three label:last-child {
    grid-column: 1 / -1;
  }

  .editor__group-heading {
    flex-wrap: wrap;
    row-gap: 8px;
  }
}
