: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: 8px 10px;
  margin-bottom: 8px;
  position: relative;
  background: #fffdf9;
}
.line-item-header {
  display: grid;
  grid-template-columns: 44px 1fr 74px 64px 22px;
  gap: 6px;
  padding: 0 10px;
  margin-bottom: 4px;
}
.line-item-header span {
  font-size: 0.68rem;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.line-item-row {
  display: grid;
  grid-template-columns: 44px 1fr 74px 64px 22px;
  gap: 6px;
  align-items: center;
}
.line-item-row select, .line-item-row input {
  padding: 8px 6px;
  font-size: 0.85rem;
  border-radius: 8px;
  min-width: 0;
}
.line-item .remove {
  background: none; border: none; color: var(--danger); font-size: 1.1rem; cursor: pointer; padding: 0;
}
.line-item .custom-row {
  margin-top: 6px;
}
.line-total {
  text-align: right;
  font-weight: 600;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
}
.line-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.invoice-doc .head-logo img { height: 64px; }
.invoice-doc .head h2 { margin: 0; }
.invoice-doc .parties { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.invoice-doc .party-box {
  flex: 1;
  min-width: 200px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.invoice-doc .party-box .label { font-size: 0.7rem; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.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; }
}

/* ---- print button progress / messages ---- */
.print-status {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 0.98rem;
  line-height: 1.4;
  border: 2px solid var(--border);
  background: #fff;
}
.print-status.ok   { border-color: #2f7d32; background: #eef7ee; color: #1f5a22; font-weight: 600; }
.print-status.warn { border-color: #b7791f; background: #fff7e6; color: #7a4f10; }
.print-status.err  { border-color: var(--danger); background: #fdeeee; color: #8a2020; font-weight: 600; }

.pc-state { margin-top: 10px; font-size: 0.85rem; color: var(--muted); text-align: center; }
.pc-state.on  { color: #2f7d32; }
.pc-state.off { color: var(--danger); }

.spinner {
  display: inline-block;
  width: 0.9em; height: 0.9em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -0.1em;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
