:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --border: #d8e1ec;
  --text: #1b2430;
  --muted: #5a6b81;
  --primary: #1f6feb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

body.rtl {
  direction: rtl;
}

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

h1 {
  margin: 0;
}

p {
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
  padding: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

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

button {
  background: var(--primary);
  border: 0;
  border-radius: 8px;
  color: #fff;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
}

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

input,
select,
textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
}

textarea {
  min-height: 110px;
  resize: vertical;
}

.entry-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

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

th,
td {
  border-top: 1px solid var(--border);
  padding: 0.5rem;
  text-align: start;
  vertical-align: top;
}

.grid.two {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.6rem;
}

.grid.two label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.invoice-preview {
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 1rem;
  min-height: 260px;
}

.invoice-preview h3,
.invoice-preview h4 {
  margin: 0.3rem 0;
}

.invoice-lines {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.75rem;
}

.invoice-lines td,
.invoice-lines th {
  border-top: 1px solid var(--border);
  padding: 0.4rem;
}

.invoice-totals {
  margin-top: 0.7rem;
}

.invoice-totals div {
  display: flex;
  justify-content: space-between;
  margin-top: 0.35rem;
}

.pro {
  margin: 0 1rem 1rem;
}

.mapping {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem;
  margin: 0.7rem 0;
}

.mapping-grid {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 0.4rem;
  align-items: center;
}

.hidden {
  display: none;
}

footer {
  padding: 0.8rem 1.25rem 1.2rem;
  color: var(--muted);
}

footer a {
  color: var(--primary);
}

@media print {
  .topbar,
  .panel:not(.preview-panel),
  .pro,
  footer {
    display: none;
  }

  .layout {
    display: block;
  }

  #invoicePreview {
    border: 0;
    min-height: auto;
  }
}
