:root {
  --brand: #E11D2E;
  --text: #1F2937;
  --muted: #6B7280;
  --border: #E5E7EB;
  --bg: #F9FAFB;
  --card-bg: #FFFFFF;
  --shadow: 0 1px 3px rgba(0,0,0,.05), 0 1px 2px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}

.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr 380px;
  min-height: 100vh;
}
.app-shell.no-chat { grid-template-columns: 220px 1fr; }

.sidebar {
  background: white;
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar.hidden { display: none; }
.sidebar.hidden + .main { grid-column: 1 / -1; }
.brand { display: block; padding: 4px 8px; }
.brand-logo { height: 28px; width: auto; display: block; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}
.nav-link:hover { background: #F3F4F6; }
.nav-link.active { background: rgba(225,29,46,.1); color: var(--brand); }

.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.small { font-size: 12px; }

.main {
  padding: 32px 40px;
  min-width: 0;
}
.page-header { margin-bottom: 16px; }

/* ---- Chat panel ---- */

.chat-panel {
  background: white;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  min-height: 0;
}
.chat-panel.hidden { display: none; }

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.chat-title { font-weight: 600; font-size: 14px; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 13px;
}

.chat-msg {
  border-radius: 10px;
  padding: 8px 12px;
  max-width: 88%;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-msg.user { background: var(--brand); color: white; align-self: flex-end; }
.chat-msg.assistant { background: #F3F4F6; color: var(--text); align-self: flex-start; }
.chat-msg.system { background: transparent; color: var(--muted); font-size: 12px; align-self: center; }

.chat-tool {
  font-size: 11px;
  color: var(--muted);
  background: #F9FAFB;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  align-self: flex-start;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.chat-tool.error { color: var(--brand); border-color: rgba(225,29,46,.3); background: rgba(225,29,46,.05); }
.chat-tool details summary { cursor: pointer; outline: none; }
.chat-tool pre { margin: 6px 0 0; white-space: pre-wrap; }

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}
.chat-input-row textarea {
  flex: 1;
  resize: none;
  font: inherit;
  font-size: 13px;
}
.chat-send { align-self: stretch; }

.chat-show {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--brand);
  color: white;
  border: none;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.18);
  z-index: 100;
}
.chat-show.hidden { display: none; }

.toasts {
  position: fixed;
  right: 24px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10000;
  pointer-events: none;
}
.toast {
  background: #1F2937;
  color: white;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 6px 16px rgba(0,0,0,.18);
  animation: toast-in .15s ease-out, toast-out .25s ease-in 2.6s forwards;
  pointer-events: auto;
}
.toast.success { background: #065F46; }
.toast.error { background: var(--brand); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.filter-bar .btn { padding: 4px 12px; font-size: 13px; }
.filter-bar .btn.active { background: var(--brand); color: white; border-color: var(--brand); }

.hidden { display: none !important; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin-top: 16px;
}

h2 { margin: 0 0 4px; font-size: 22px; }
h3 { margin: 24px 0 8px; font-size: 14px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}
.grid-2 .span-2 { grid-column: 1 / -1; }

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

input, select, textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(225, 29, 46, .1);
}

.btn {
  font: inherit;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: white;
  color: var(--text);
  cursor: pointer;
}
.btn:hover { background: #F3F4F6; }
.btn-primary { background: var(--brand); color: white; border-color: var(--brand); }
.btn-primary:hover { background: #C0152A; }
.btn-link { background: transparent; border: none; color: var(--brand); padding: 4px 8px; cursor: pointer; }
.btn-link:hover { background: rgba(225,29,46,.08); }

.muted { color: var(--muted); }
.error { color: var(--brand); margin-top: 12px; min-height: 20px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
tr:last-child td { border-bottom: none; }
.right { text-align: right; }

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.status-draft { background: #F3F4F6; color: #4B5563; }
.status-sent { background: #DBEAFE; color: #1E40AF; }
.status-paid { background: #D1FAE5; color: #065F46; }

#invoice-list table tbody tr,
#project-list table tbody tr { cursor: pointer; }
#invoice-list table tbody tr:hover,
#project-list table tbody tr:hover { background: #F9FAFB; }

.row-actions { white-space: nowrap; }
.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px;
  margin: 0 1px;
  border-radius: 6px;
  color: #6B7280;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
}
.icon-btn svg {
  width: 18px;
  height: 18px;
  display: block;
}
.icon-btn:hover { background: #F3F4F6; color: var(--text); }
.icon-btn.icon-danger:hover { background: rgba(225,29,46,.1); color: var(--brand); }

/* Login screen */
.login-screen { display: flex; align-items: center; justify-content: center; min-height: 80vh; }
.login-card { max-width: 360px; text-align: center; padding: 32px; }
.login-logo { height: 40px; margin-bottom: 16px; }
.login-card h2 { text-align: center; margin: 0 0 8px; font-size: 18px; }
.login-card p { margin: 0 0 16px; }
.login-card #g-signin { display: flex; justify-content: center; }

/* ---- Invoice document styling (form rendered as the invoice itself) ---- */

.invoice-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar-left { display: flex; gap: 12px; flex-wrap: wrap; }
.toolbar-right { display: flex; gap: 8px; align-items: center; }
.form-icons { display: inline-flex; gap: 2px; align-items: center; margin-right: 8px; }
.form-icons.hidden { display: none; }
.t-field { min-width: 120px; }

.invoice-doc {
  background: white;
  max-width: 760px;
  margin: 0 auto;
  padding: 56px 64px;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-family: Helvetica, Arial, sans-serif;
  color: #222;
  font-size: 11px;
  line-height: 1.5;
}

.inv-header { display: flex; flex-direction: column; gap: 14px; margin-bottom: 16px; }
.inv-logo { height: 32px; width: auto; align-self: flex-start; }
.inv-contact { color: #6B7280; font-size: 10px; }
.inv-dates { text-align: right; font-size: 11px; color: #222; margin-bottom: 12px; }
.inv-dates > div { margin-bottom: 2px; }

.inv-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 32px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.inv-to {
  margin-bottom: 32px;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.inv-to-label { font-weight: 700; margin-bottom: 4px; }

.inv-thanks { margin: 0 0 8px; font-size: 12px; }

.inv-items {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 16px;
  font-size: 11px;
}
.inv-items th {
  text-align: left;
  font-weight: normal;
  padding: 6px 8px;
  border-top: 1px solid #D1D5DB;
  border-bottom: 1px solid #D1D5DB;
  color: #222;
  text-transform: none;
  letter-spacing: 0;
}
.inv-items th.col-qty, .inv-items th.col-unit, .inv-items th.col-total { text-align: right; }
.inv-items td {
  padding: 8px;
  border-bottom: 1px solid #E5E7EB;
  vertical-align: middle;
}
.inv-items td.r { text-align: right; }
.inv-items tbody td { position: relative; }
.inv-items tfoot td { border-bottom: none; padding: 4px 8px; }
.inv-items tfoot tr.add-row td { padding: 6px 8px 12px; border-bottom: 1px solid #E5E7EB; }
.inv-items tfoot tr.total-row td { padding-top: 8px; font-size: 12px; }
.col-desc { width: auto; }
.col-qty { width: 80px; }
.col-unit { width: 110px; }
.col-total { width: 110px; }

.line-item-row td:last-child { padding-right: 28px; }
.line-item-row .remove-line {
  position: absolute;
  right: -4px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: #9CA3AF;
  cursor: pointer;
  font-size: 16px;
  padding: 4px 8px;
  opacity: 0;
  transition: opacity .15s;
}
.line-item-row:hover .remove-line { opacity: 1; }
.line-item-row .remove-line:hover { color: var(--brand); }

.inv-vat { color: #222; margin: 16px 0; }
.inv-bank { color: #222; }
.inv-bank > div { line-height: 1.6; }
.inv-notes-wrap { margin-top: 24px; }

.inline-add { font-size: 11px; padding: 0; }

/* Inputs styled to look like static invoice text */
.inv-input {
  font: inherit;
  color: inherit;
  background: transparent;
  border: none;
  outline: none;
  padding: 2px 4px;
  margin: -2px -4px;
  border-radius: 3px;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
}
.inv-input:hover:not(:focus):not(:disabled) {
  background: rgba(0, 0, 0, 0.03);
}
.inv-input:focus {
  background: rgba(225, 29, 46, 0.06);
  box-shadow: inset 0 0 0 1px rgba(225, 29, 46, 0.25);
}
.inv-input::placeholder { color: #9CA3AF; }

.inv-input-date {
  width: auto;
  min-width: 105px;
  text-align: right;
  font: inherit;
}
.inv-input-title {
  font-size: 24px;
  font-weight: 700;
  width: auto;
  min-width: 160px;
  padding: 0 4px;
  margin: 0;
}
.inv-input-pct {
  width: 50px;
  text-align: right;
  -moz-appearance: textfield;
}
.inv-input-pct::-webkit-outer-spin-button,
.inv-input-pct::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.inv-input-notes {
  resize: vertical;
  font-family: inherit;
  font-size: 11px;
  color: #6B7280;
  width: 100%;
}
.inv-input-address {
  resize: vertical;
  font-family: inherit;
  font-size: 11px;
  width: 100%;
}

.inv-items input[type=number] {
  -moz-appearance: textfield;
  text-align: right;
}
.inv-items input[type=number]::-webkit-outer-spin-button,
.inv-items input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.unit-cell { display: table-cell; }
.unit-cell .currency-prefix { color: #222; margin-right: 2px; }
.unit-cell .inv-input { display: inline-block; width: auto; max-width: 80px; text-align: right; }
