:root {
  --brand: #2f4a2f;
  --brand-dark: #1f331f;
  --bg: #faf8f3;
  --card: #ffffff;
  --border: #ddd6c8;
  --text: #26261f;
  --muted: #7a7568;
  --danger: #a83232;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 40px;
}

header.top {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 10;
}

header.top img { height: 40px; }
header.top .title { font-weight: 600; font-size: 1.05rem; }
header.top a.back { color: var(--brand); text-decoration: none; font-size: 1.4rem; margin-right: 4px; }

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 18px 16px 60px;
}

.logo-wrap { text-align: center; margin: 24px 0; }
.logo-wrap img { max-width: 240px; width: 70%; }

h1 { font-size: 1.4rem; margin: 0 0 16px; }
h2 { font-size: 1.15rem; margin: 20px 0 10px; }

.btn {
  display: block;
  width: 100%;
  padding: 18px;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: none;
  background: var(--brand);
  color: #fff;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  margin-bottom: 14px;
}
.btn:active { background: var(--brand-dark); }
.btn.secondary { background: #fff; color: var(--brand); border: 2px solid var(--brand); }
.btn.small { padding: 10px 14px; font-size: 0.95rem; width: auto; display: inline-block; }
.btn.danger { background: var(--danger); }
.btn:disabled { opacity: 0.5; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

label { display: block; font-size: 0.85rem; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); }

.line-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  position: relative;
  background: #fffdf9;
}
.line-item .remove {
  position: absolute; top: 8px; right: 10px;
  background: none; border: none; color: var(--danger); font-size: 1.2rem; cursor: pointer;
}
.line-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.line-total {
  text-align: right;
  font-weight: 600;
  margin-top: 6px;
  color: var(--muted);
}

table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td {
  text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 0.9rem;
}
table.list th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }
table.list td.num { text-align: right; white-space: nowrap; }
table.list a.action { color: var(--brand); text-decoration: none; font-weight: 600; margin-right: 10px; font-size: 0.85rem; }

.invoice-doc { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.invoice-doc .head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.invoice-doc .head h2 { margin: 0; }
.invoice-doc .from, .invoice-doc .to { font-size: 0.9rem; line-height: 1.4; }
.invoice-doc table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 0.9rem; }
.invoice-doc table th, .invoice-doc table td { border-bottom: 1px solid var(--border); padding: 8px 4px; text-align: left; }
.invoice-doc table td.num, .invoice-doc table th.num { text-align: right; }
.totals { margin-left: auto; width: 220px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { font-weight: 700; font-size: 1.1rem; border-top: 2px solid var(--text); margin-top: 6px; padding-top: 8px; }

.error { color: var(--danger); font-size: 0.9rem; margin-top: 8px; }
.muted { color: var(--muted); font-size: 0.85rem; }
.row-actions { display: flex; gap: 10px; margin-top: 20px; }
.row-actions .btn { margin-bottom: 0; }

.load-more { text-align: center; margin-top: 16px; }

@media print {
  header.top, .no-print { display: none !important; }
  body { background: #fff; padding: 0; }
  main { max-width: 100%; padding: 0; }
  .invoice-doc { border: none; }
}
