@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --ink: #0F3A45;
  --paper: #F6F9F8;
  --paper-raised: #FFFFFF;
  --blue: #1E7FB8;
  --blue-dark: #145E8A;
  --amber: #1FA37E;
  --slate: #5B7580;
  --line: #DCE6E4;
  --danger: #B3261E;
  --green: #1E9E6B;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
}
h1, h2, h3, .display {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  margin: 0;
}
a { color: inherit; }
button { font-family: inherit; cursor: pointer; }

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes popIn {
  0% { opacity: 0; transform: scale(0.85); }
  60% { opacity: 1; transform: scale(1.05); }
  100% { transform: scale(1); }
}
@keyframes gentlePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(47,125,90,0.35); }
  50% { box-shadow: 0 0 0 8px rgba(47,125,90,0); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
input, select, textarea {
  font-family: inherit;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 16px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(44,95,138,0.2);
}
label.field { display: block; margin-bottom: 14px; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 44px; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; padding: 7px; border-radius: 6px;
  color: var(--slate); display: flex; align-items: center; justify-content: center;
}
.pw-toggle:hover { color: var(--ink); background: rgba(0,0,0,0.04); }
label.field .label-text {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--slate);
  margin-bottom: 5px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  transition: opacity 0.15s, transform 0.15s, box-shadow 0.15s;
}
.btn:hover { opacity: 0.85; transform: translateY(-1px); }
.btn:active { opacity: 0.7; transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-accent { background: var(--blue); color: #fff; box-shadow: 0 2px 8px rgba(44,95,138,0.25); }
.btn-accent:hover { box-shadow: 0 4px 14px rgba(44,95,138,0.35); }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-draft { background: #EEECE6; color: var(--slate); }
.badge-sent, .badge-accepted { background: #E4EEF5; color: var(--blue-dark); }
.badge-declined, .badge-overdue { background: #F5E6E5; color: var(--danger); }
.badge-paid { background: #E5EFE9; color: var(--green); }

.card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  gap: 12px;
  flex-wrap: wrap;
  transition: background 0.15s;
  animation: fadeSlideUp 0.35s ease backwards;
}
.list-row:hover { background: rgba(44,95,138,0.035); }
.list-row[data-action] { cursor: pointer; }
.list-row:nth-child(1) { animation-delay: 0ms; }
.list-row:nth-child(2) { animation-delay: 40ms; }
.list-row:nth-child(3) { animation-delay: 80ms; }
.list-row:nth-child(4) { animation-delay: 120ms; }
.list-row:nth-child(5) { animation-delay: 160ms; }
.list-row:nth-child(6) { animation-delay: 200ms; }
.list-row:nth-child(7) { animation-delay: 240ms; }
.list-row:nth-child(8) { animation-delay: 280ms; }
.list-row:nth-child(n+9) { animation-delay: 300ms; }
.list-row:last-child { border-bottom: none; }
.row-link { cursor: pointer; transition: color 0.12s; }
.row-link:hover, .row-link:hover * { color: var(--blue) !important; }

.tear-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0;
}
.tear-divider .tear-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--slate);
  white-space: nowrap;
}
.tear-divider .tear-line {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tear-divider .tear-line::before {
  content: "";
  flex: 1;
  border-top: 1px dashed var(--line);
}
.tear-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--line); }

.stat-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  transition: transform 0.18s, box-shadow 0.18s;
  animation: fadeSlideUp 0.4s ease backwards;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(20,33,61,0.08); }
.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--slate); margin-bottom: 4px; }
.stat-value { font-size: 26px; font-weight: 700; font-family: 'Barlow Condensed', sans-serif; }
.stat-icon { padding: 10px; border-radius: 10px; }

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 50px 24px;
  text-align: center;
  color: var(--slate);
  font-size: 14px;
}

.grid-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
@media (min-width: 720px) {
  .grid-stats { grid-template-columns: repeat(4, 1fr); }
}

/* ---- App shell ---- */
#app { display: flex; flex-direction: column; min-height: 100vh; }
.app-body { display: flex; flex: 1; min-height: 0; }
.trial-banner {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  background: var(--amber); color: var(--ink);
  padding: 8px 16px; font-size: 13px; font-weight: 600;
}
.trial-banner button {
  background: var(--ink); color: var(--paper); border: none;
  padding: 5px 12px; border-radius: 6px; font-size: 12px; font-weight: 700;
}
#trial-help-banner-btn {
  width: 24px; padding: 5px 0; border-radius: 50%;
  background: transparent; color: var(--ink); border: 1px solid var(--ink);
}

/* Help & Support: FAQ accordion + assistant tip */
.faq details { border-bottom: 1px solid var(--line); }
.faq details:last-child { border-bottom: none; }
.faq summary {
  cursor: pointer; font-weight: 600; font-size: 14px; padding: 13px 2px;
  list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--slate); font-size: 20px; font-weight: 400; line-height: 1; }
.faq details[open] summary::after { content: "\2013"; }
.faq details p { margin: 0 0 14px; font-size: 13.5px; color: var(--slate); line-height: 1.55; }
.support-tip {
  background: linear-gradient(135deg, rgba(30,127,184,0.08), rgba(15,58,69,0.05));
  border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin: 0 0 4px;
}
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--paper-raised);
  border-right: 1px solid var(--line);
  padding: 24px 16px;
  display: none;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; margin-bottom: 32px; }
.sidebar-brand .mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--ink); color: var(--paper);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-family: 'Barlow Condensed', sans-serif;
}
.sidebar-brand .name { font-size: 14px; font-weight: 700; font-family: 'Barlow Condensed', sans-serif; line-height: 1.2; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px; margin-bottom: 4px;
  border-radius: 8px; border: none; background: transparent;
  font-size: 14px; font-weight: 600; color: var(--slate); text-align: left;
  position: relative;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover:not(.active) { background: rgba(44,95,138,0.06); color: var(--ink); }
.nav-item.active { background: var(--ink); color: var(--paper); }
.nav-item.active::before {
  content: "";
  position: absolute; left: -16px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 60%;
  background: var(--amber);
  border-radius: 0 3px 3px 0;
}
.nav-item svg { flex-shrink: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: var(--paper-raised);
}
.mobile-nav {
  display: none;
  flex-wrap: wrap; gap: 6px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: var(--paper-raised);
}
.mobile-nav.open { display: flex; }
.mobile-nav button {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 8px; border: none;
  font-size: 12px; font-weight: 600; background: var(--paper); color: var(--slate);
}
.mobile-nav button.active { background: var(--ink); color: var(--paper); }

main.content { flex: 1; padding: 24px 16px; max-width: 900px; }
@media (min-width: 640px) {
  .sidebar { display: block; }
  .topbar, .mobile-nav { display: none !important; }
  main.content { padding: 32px; }
}

.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.subtle { color: var(--slate); font-size: 14px; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20,33,61,0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 16px; overflow-y: auto;
}
.modal {
  width: 100%; max-width: 560px;
  background: var(--paper-raised);
  border-radius: 14px;
  margin: 24px 0;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal.wide { max-width: 720px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px; border-bottom: 1px solid var(--line);
}
.modal-body { padding: 24px; }
.modal-close { background: none; border: none; padding: 6px; border-radius: 6px; }
.modal-close:hover { background: rgba(0,0,0,0.05); }

/* ---- Items editor ---- */
.items-head, .item-row {
  display: grid;
  grid-template-columns: 1fr 70px 100px 100px 32px;
  gap: 8px;
  align-items: center;
}
.items-head span { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--slate); }
.item-row { margin-bottom: 8px; }
.item-total { font-size: 14px; font-weight: 600; }
.remove-item { background: none; border: none; padding: 6px; border-radius: 6px; }
.remove-item:hover { background: rgba(0,0,0,0.05); }
.items-total-row { display: flex; justify-content: flex-end; padding-top: 16px; margin-top: 8px; border-top: 1px solid var(--line); }

/* Line-item description: auto-growing textarea (replaces the old single-line input) */
textarea.item-desc {
  resize: none;
  overflow: hidden;
  min-height: 42px;
  line-height: 1.35;
  font-size: 16px;
}
.mini-field { display: block; margin: 0; }
.mini-field .item-qty, .mini-field .item-rate { width: 100%; }
.mini-label { display: none; }

/* Inline "generate" send button attached to the AI description input */
.ai-send-inline {
  background: var(--blue);
  color: #fff;
  border: 1px solid var(--blue);
  border-radius: 8px;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  align-self: flex-start;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(44,95,138,0.25);
}
.ai-send-inline:hover { opacity: 0.9; }
.ai-send-inline:disabled { opacity: 0.5; cursor: not-allowed; }

/* Narrow screens: stack each line item into a compact card so nothing overflows
   and the description gets full width. Mini-labels replace the hidden header row. */
@media (max-width: 640px) {
  .items-head { display: none; }
  .item-row {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "desc  desc"
      "qty   rate"
      "total remove";
    gap: 8px 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 10px;
    align-items: end;
  }
  .item-desc { grid-area: desc; }
  .mini-qty { grid-area: qty; }
  .mini-rate { grid-area: rate; }
  .item-total { grid-area: total; align-self: center; font-size: 15px; }
  .remove-item[data-remove-item] { grid-area: remove; justify-self: end; }
  .mini-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--slate);
    margin-bottom: 4px;
  }
}

/* ---- Auth screen ---- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(rgba(20,33,61,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20,33,61,0.03) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px, 28px 28px, auto;
}
.auth-wrap::before {
  content: "";
  position: absolute;
  width: 480px; height: 480px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(44,95,138,0.10), transparent 70%);
  top: -120px; left: -120px;
}
.auth-wrap::after {
  content: "";
  position: absolute;
  width: 420px; height: 420px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(30,158,107,0.10), transparent 70%);
  bottom: -140px; right: -100px;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px;
  position: relative;
  z-index: 1;
  box-shadow: 0 20px 50px rgba(20,33,61,0.10);
  animation: fadeSlideUp 0.4s ease;
}
.auth-tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.auth-tab { flex: 1; padding: 9px; border-radius: 8px; border: 1px solid var(--line); background: transparent; font-size: 13px; font-weight: 600; color: var(--slate); }
.auth-tab.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.auth-msg { font-size: 13px; padding: 10px 12px; border-radius: 8px; margin-top: 12px; }
.auth-msg.error { background: #F5E6E5; color: var(--danger); }
.auth-msg.success { background: #E5EFE9; color: var(--green); }

.table-preview { width: 100%; font-size: 12px; border-collapse: collapse; }
.table-preview th { text-align: left; padding: 6px 10px; background: var(--paper); font-weight: 600; color: var(--slate); white-space: nowrap; }
.table-preview td { padding: 6px 10px; border-top: 1px solid var(--line); white-space: nowrap; }

.print-only { display: none; }

.assist-fab {
  position: fixed; bottom: 22px; right: 22px; z-index: 60;
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--ink));
  color: var(--paper);
  display: flex; align-items: center; justify-content: center;
  border: none; box-shadow: 0 10px 26px rgba(20,33,61,0.35);
  transition: transform 0.15s;
  font-size: 22px;
}
.assist-fab:hover { transform: scale(1.06); }
.assist-fab-label {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.04em;
}

.assist-panel {
  position: fixed; bottom: 90px; right: 22px; z-index: 60;
  width: 300px; max-width: calc(100vw - 32px);
  height: 400px; max-height: calc(100vh - 140px);
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(20,33,61,0.25);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: popIn 0.2s ease;
}
.assist-head {
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.assist-tabs { display: flex; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.assist-tab {
  flex: 1; padding: 7px; border-radius: 7px; border: 1px solid var(--line);
  background: transparent; font-size: 12px; font-weight: 600; color: var(--slate);
}
.assist-tab.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.assist-messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.assist-msg { font-size: 13px; line-height: 1.45; padding: 9px 12px; border-radius: 10px; max-width: 85%; white-space: pre-wrap; }
.assist-msg.user { align-self: flex-end; background: var(--blue); color: #fff; }
.assist-msg.assistant { align-self: flex-start; background: var(--paper); color: var(--ink); border: 1px solid var(--line); }
.assist-msg.system { align-self: center; color: var(--slate); font-size: 11px; font-style: italic; }
.assist-submode {
  padding: 8px 14px 2px; font-size: 11px; color: var(--slate); line-height: 1.4;
}
.assist-input-row { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); align-items: flex-end; }
.assist-input-row textarea {
  flex: 1; resize: none; font-size: 16px; padding: 9px 10px; border-radius: 8px;
  border: 1px solid var(--line); font-family: inherit;
  min-height: 40px; max-height: 110px; line-height: 1.35;
}
.assist-send {
  background: var(--ink); color: var(--paper); border: none; border-radius: 8px;
  padding: 0 16px; font-weight: 600; font-size: 13px;
  height: 40px; flex-shrink: 0;
}
.assist-send:disabled { opacity: 0.4; }
.assist-input-row .assist-mic { height: 40px; }

.assist-mic {
  background: var(--paper); color: var(--slate); border: 1px solid var(--line);
  border-radius: 8px; width: 38px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.assist-mic:hover { background: var(--line); }
.assist-mic.listening {
  background: var(--danger); color: #fff; border-color: var(--danger);
  animation: micPulse 1.2s ease infinite;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(179,38,30,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(179,38,30,0); }
}

.paid-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 14px 22px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 12px 30px rgba(20,33,61,0.3);
  z-index: 100;
  animation: popIn 0.35s ease;
}
.paid-toast .coin {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--amber);
  color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  animation: gentlePulse 1.4s ease 2;
}
@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { position: absolute; top: 0; left: 0; width: 100%; }
}
