:root {
  --ink: #1C1D18;
  --ink-soft: #5B5A50;
  --paper: #FAF8F3;
  --sand: #EDE7DA;
  --line: #DAD3C3;
  --green: #2F6B4F;
  --green-deep: #234F3B;
  --green-light: #DCE9E1;
  --dusk: #3A2E22;
  --accent: #C8A96A;
  --danger: #B3261E;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ============ HUB ============ */
body.hub { min-height: 100vh; }

.hub-shell {
  max-width: 1040px;
  margin: 0 auto;
  padding: 56px 28px 40px;
}

.hub-header { margin-bottom: 40px; }

.hub-brand { display: flex; align-items: baseline; gap: 10px; }

.hub-logo {
  font-weight: 800;
  font-size: 30px;
  letter-spacing: 0.02em;
  color: var(--green-deep);
}

.hub-logo-sub {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.18em;
  color: var(--accent);
  text-transform: uppercase;
}

.hub-tagline { color: var(--ink-soft); margin: 10px 0 0; font-size: 15px; }

.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.tool-card {
  display: block;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
  cursor: pointer;
}

.tool-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 28px rgba(28,29,24,.08);
  border-color: var(--green);
}

.tool-card-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  margin-bottom: 16px;
  color: #fff;
}

.tool-card-title { font-size: 18px; font-weight: 700; margin: 0 0 6px; }

.tool-card-desc { font-size: 14px; color: var(--ink-soft); line-height: 1.5; margin: 0 0 16px; }

.tool-card-brand {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--green);
  text-transform: uppercase;
}

.hub-footer {
  margin-top: 48px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 13px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.hub-footer .dot { color: var(--accent); }

/* ============ INVOICE TOOL ============ */
body.invoice-tool { background: var(--paper); }

.tool-header {
  background: var(--green-deep);
  color: #fff;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.tool-header-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 16px; }
.tool-header-brand .back { opacity: .85; font-weight: 600; font-size: 14px; }
.tool-header-brand .sep { opacity: .4; }

.tool-header-actions { display: flex; gap: 10px; }

.tool-layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 0;
  min-height: calc(100vh - 57px);
}

/* --- Form panel --- */
.form-panel {
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 28px;
  overflow-y: auto;
}

.form-panel h2 { font-size: 20px; margin: 0 0 4px; }
.form-panel .panel-sub { color: var(--ink-soft); font-size: 13px; margin: 0 0 24px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-light);
}
.field textarea { resize: vertical; min-height: 64px; }

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

.section-label {
  margin: 26px 0 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--green);
}

/* Line items */
.items-head { display: grid; grid-template-columns: 1fr 64px 110px 30px; gap: 8px; font-size: 11px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.items-head .c-amt { text-align: right; }

.item-row { display: grid; grid-template-columns: 1fr 64px 110px 30px; gap: 8px; margin-bottom: 8px; align-items: center; }
.item-row input { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; font-family: inherit; font-size: 14px; }
.item-row input:focus { outline: none; border-color: var(--green); }
.item-row .amt { text-align: right; }
.item-remove { border: none; background: transparent; color: var(--danger); font-size: 18px; cursor: pointer; padding: 4px; border-radius: 6px; line-height: 1; }
.item-remove:hover { background: #FBEAE8; }

.add-item-btn {
  width: 100%;
  padding: 10px;
  border: 1px dashed var(--line);
  background: transparent;
  border-radius: 10px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--green);
  cursor: pointer;
}
.add-item-btn:hover { background: var(--green-light); border-color: var(--green); }

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

.btn {
  flex: 1;
  padding: 12px 16px;
  border-radius: 10px;
  border: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: filter .15s ease;
}
.btn:hover { filter: brightness(1.05); }

.btn-primary { background: var(--green-deep); color: #fff; }
.btn-secondary { background: var(--sand); color: var(--ink); }
.btn-accent { background: var(--accent); color: #1C1D18; }

/* --- Preview panel --- */
.preview-panel {
  padding: 32px;
  overflow: auto;
  background: #e9e6de;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 10px;
}
.preview-toolbar h3 { margin: 0; font-size: 15px; color: var(--ink-soft); font-weight: 600; }

/* ============ INVOICE DOCUMENT ============ */
.invoice-doc {
  background: #fff;
  width: 760px;
  min-width: 760px;
  margin: 0 auto;
  padding: 44px 48px;
  border-radius: 4px;
  box-shadow: 0 8px 32px rgba(28,29,24,.1);
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  color: #1C1D18;
}

.inv-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }

.inv-brand .inv-logo-img {
  display: block;
  height: 64px;
  width: auto;
  margin-bottom: 10px;
}
.inv-brand .inv-logo {
  font-weight: 800;
  font-size: 26px;
  color: #234F3B;
  letter-spacing: 0.01em;
}
.inv-brand .inv-logo span { color: #C8A96A; }
.inv-brand .inv-subbrand { font-size: 11px; font-weight: 700; letter-spacing: .22em; color: #5B5A50; text-transform: uppercase; margin-top: 2px; }
.inv-brand .inv-address { font-size: 11.5px; color: #5B5A50; line-height: 1.5; margin-top: 12px; }
.inv-brand .inv-contact { font-size: 11.5px; color: #5B5A50; line-height: 1.6; margin-top: 4px; }

.inv-title { text-align: right; }
.inv-title .inv-word { font-size: 30px; font-weight: 800; letter-spacing: .04em; color: #234F3B; }
.inv-title .inv-num { font-size: 13px; font-weight: 600; color: #5B5A50; margin-top: 4px; }

.inv-meta {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-top: 36px;
  padding: 18px 0;
  border-top: 1px solid #DAD3C3;
  border-bottom: 1px solid #DAD3C3;
}
.inv-meta h4 { margin: 0 0 8px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: #C8A96A; }
.inv-meta .inv-billto { font-size: 14px; line-height: 1.5; }
.inv-meta .inv-billto .name { font-weight: 700; font-size: 15px; }
.inv-meta .inv-dates { text-align: right; }
.inv-meta .inv-dates div { font-size: 13px; line-height: 1.7; color: #5B5A50; }
.inv-meta .inv-dates .lbl { font-weight: 700; color: #1C1D18; }

.inv-items { width: 100%; border-collapse: collapse; margin-top: 24px; }
.inv-items thead th {
  text-align: left;
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #5B5A50;
  padding: 10px 8px;
  border-bottom: 2px solid #234F3B;
}
.inv-items thead th.num, .inv-items tbody td.num { text-align: right; white-space: nowrap; }
.inv-items tbody td { padding: 12px 8px; font-size: 14px; border-bottom: 1px solid #EDE7DA; vertical-align: top; }
.inv-items tbody td.desc { font-weight: 500; }
.inv-items tbody td.qty { color: #5B5A50; }

.inv-totals { margin-top: 20px; margin-left: auto; width: 300px; }
.inv-totals .row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.inv-totals .row.sub { color: #5B5A50; }
.inv-totals .row.grand {
  font-size: 18px;
  font-weight: 800;
  border-top: 2px solid #234F3B;
  margin-top: 8px;
  padding-top: 12px;
  color: #234F3B;
}

.inv-notes { margin-top: 28px; }
.inv-notes h4 { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: #C8A96A; margin: 0 0 8px; }
.inv-notes p { font-size: 13px; color: #5B5A50; line-height: 1.6; white-space: pre-wrap; margin: 0; }

.inv-payment { margin-top: 28px; }
.inv-payment h4 { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: #C8A96A; margin: 0 0 10px; }
.inv-payment-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 0;
  font-size: 13.5px;
  border-bottom: 1px solid #EDE7DA;
}
.inv-payment-row span:first-child { color: #5B5A50; }
.inv-payment-row span:last-child { font-weight: 700; color: #1C1D18; text-align: right; }

.inv-footer {
  margin-top: 36px;
  padding-top: 16px;
  border-top: 1px solid #DAD3C3;
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: #5B5A50;
}

/* ============ HISTORY ============ */
.history-section { margin-top: 32px; }
.history-section h3 { font-size: 15px; margin: 0 0 12px; }

.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.history-item .hi-main { min-width: 0; }
.history-item .hi-num { font-weight: 700; font-size: 14px; }
.history-item .hi-sub { font-size: 12px; color: var(--ink-soft); }
.history-item .hi-actions { display: flex; gap: 6px; flex-shrink: 0; }
.history-item .hi-btn {
  border: 1px solid var(--line);
  background: #fff;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.history-item .hi-btn:hover { border-color: var(--green); color: var(--green); }
.history-item .hi-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.empty-note { color: var(--ink-soft); font-size: 13px; text-align: center; padding: 24px; border: 1px dashed var(--line); border-radius: 10px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--green-deep);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(28,29,24,.2);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* Responsive */
@media (max-width: 900px) {
  .tool-layout { grid-template-columns: 1fr; }
  .form-panel { border-right: none; border-bottom: 1px solid var(--line); }
  .inv-doc { padding: 28px 20px; }
  .field-row { grid-template-columns: 1fr; }
  .inv-top { flex-direction: column; }
  .inv-title { text-align: left; }
  .inv-meta { flex-direction: column; }
  .inv-meta .inv-dates { text-align: left; }
}
