:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  --text: #1a1a1a;
  --text-secondary: #6b7280;
  --bg: #ffffff;
  --bg-subtle: #f9fafb;
  --border: #e5e7eb;
  --accent: #2563eb;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 6px;
  --size: 14px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  font-size: var(--size);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-subtle);
}

/* Navigation */
nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 48px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 900px;
  height: 100%;
  margin: 0 auto;
  padding: 0 24px;
}

.nav-brand {
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 20px;
}

.nav-links a {
  color: var(--text-secondary);
  text-decoration: none;
}

.nav-links a:hover {
  color: var(--text);
}

/* Main content */
main {
  max-width: 900px;
  margin: 32px auto;
  padding: 0 24px;
}

/* Login */
.login-container {
  max-width: 320px;
  margin: 120px auto;
  text-align: center;
}

.login-container h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 24px;
}

.login-container form {
  display: flex;
  flex-direction: column;
  text-align: left;
  gap: 8px;
}

.login-container label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.login-container input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: var(--size);
}

.login-container input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-container button {
  margin-top: 12px;
}

.login-container button:hover {
  background: #374151;
}

.error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
}

/* Headings */
h1 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}

h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
}

/* Cards */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 20px;
  margin-bottom: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group.full {
  grid-column: 1 / -1;
}

label {
  font-size: 13px;
  color: var(--text-secondary);
}

input, select, textarea {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: var(--size);
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea {
  height: auto;
  padding: 8px 12px;
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

input:hover:not(:focus), select:hover:not(:focus), textarea:hover:not(:focus) {
  border-color: #d1d5db;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: var(--size);
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  height: auto;
  padding: 0;
}

button {
  height: 36px;
  padding: 0 16px;
  background: var(--text);
  color: var(--bg);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: var(--size);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

button:hover {
  background: #374151;
}

button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Page header with action */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.page-header h1 {
  margin-bottom: 0;
}

/* Links styled as buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 16px;
  background: var(--text);
  color: var(--bg);
  text-decoration: none;
  border-radius: var(--radius);
  font-size: var(--size);
  transition: background-color 0.15s;
}

.btn:hover {
  background: #374151;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 16px;
  background: var(--bg);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--size);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.btn-secondary:hover {
  background: var(--bg-subtle);
  color: var(--text);
  border-color: #d1d5db;
}

.btn-danger {
  background: var(--bg);
  color: var(--danger);
  border: 1px solid var(--border);
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.btn-danger:hover {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--danger);
}

/* Form actions */
.form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.inline-form {
  display: inline;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 12px 8px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tr:last-child td {
  border-bottom: none;
}

td a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

th:first-child,
td:first-child { padding-left: 0; }
th:last-child,
td:last-child { padding-right: 0; }

td a:hover {
  color: var(--accent);
}

.empty {
  color: var(--text-secondary);
  padding: 32px 0;
  text-align: center;
}

/* Notices */
.notice {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
}

.notice a {
  margin-left: 8px;
  color: inherit;
  font-weight: 500;
}

.notice-success {
  background: #f0fdf4;
  color: var(--success);
  border: 1px solid #bbf7d0;
}

.notice-error {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}

/* Utilities */
.text-right { text-align: right; }
.text-secondary { color: var(--text-secondary); }

.pre-wrap { white-space: pre-wrap; font-family: inherit; font-size: var(--size); }

/* Status badges */
.status {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 99px;
  white-space: nowrap;
}

.status-draft { background: #e5e7eb; color: #4b5563; }
.status-sent { background: #fef3c7; color: #b45309; }
.status-viewed { background: #dbeafe; color: #1d4ed8; }
.status-paid { background: #dcfce7; color: #15803d; }
.status-partially_paid { background: #fef3c7; color: #b45309; }
.status-overdue { background: #fee2e2; color: #b91c1c; }
.status-cancelled { background: #e5e7eb; color: #9ca3af; text-decoration: line-through; }
.status-accepted { background: #dcfce7; color: #15803d; }
.status-rejected { background: #fee2e2; color: #b91c1c; }
.status-expired { background: #e5e7eb; color: #9ca3af; }
.status-converted { background: #dbeafe; color: #1d4ed8; }

/* Filters */
.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.filter-tag {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 12px;
  border-radius: 99px;
  font-size: 13px;
  text-decoration: none;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.filter-tag:hover {
  color: var(--text);
  background: var(--bg-subtle);
  border-color: #d1d5db;
}

.filter-tag.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

/* Invoice form — line items */
.line-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.line-item:last-child { border-bottom: none; }

.line-item-fields {
  display: flex;
  gap: 8px;
  align-items: end;
}

.line-desc { flex: 1; min-width: 0; }
.line-qty { flex: 0 0 64px; }
.line-unit { flex: 0 0 64px; }
.line-price { flex: 0 0 90px; }
.line-total-display {
  flex: 0 0 72px;
  text-align: right;
}

.line-total-value {
  line-height: 36px;
}

.line-detail {
  margin-top: 6px;
}

.line-detail textarea {
  width: 100%;
  min-height: 60px;
}

.line-detail-text {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 2px;
  max-width: 400px;
}

.remove-line {
  flex: 0 0 36px;
  height: 36px;
  padding: 0;
  background: var(--bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.remove-line:hover {
  color: var(--danger);
  border-color: #fecaca;
  background: #fef2f2;
}

#add-line {
  margin: 12px 0 24px;
  background: var(--bg);
  color: var(--text-secondary);
  border: 1px dashed var(--border);
}

#add-line:hover {
  color: var(--text);
  border-color: #d1d5db;
  background: var(--bg-subtle);
}

/* Invoice summary block */
.invoice-summary {
  max-width: 280px;
  margin-left: auto;
  margin-top: 20px;
  margin-bottom: 20px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
}

.summary-row.total {
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 8px;
  font-weight: 600;
}

/* Client details (2-column layout on show page) */
.client-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 32px;
  margin-bottom: 20px;
}

/* Invoice meta (show page) */
.invoice-meta {
  margin-bottom: 20px;
}

.meta-row {
  display: flex;
  gap: 16px;
  padding: 4px 0;
  font-size: 13px;
}

.meta-label {
  color: var(--text-secondary);
  min-width: 80px;
}

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

/* Inline form fix for actions row */
.form-actions .inline-form {
  margin-left: 0;
}

/* Payment form */
.payment-form-toggle {
  margin-top: 12px;
}

.payment-form-toggle summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
}

.payment-form-toggle summary:hover {
  color: var(--text);
}

.payment-form {
  margin-top: 12px;
}

.btn-small {
  height: 28px;
  padding: 0 8px;
  font-size: 13px;
}

/* Dashboard */
.section-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.overdue-label {
  color: var(--danger);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
}

.stat-row span:first-child {
  color: var(--text-secondary);
}

.stat-currency-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text);
  margin-top: 8px;
  margin-bottom: 2px;
}

.stat-currency-label:first-child {
  margin-top: 0;
}

.outstanding-total {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 2px;
}

.outstanding-rate-date {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* ============================================================
   Public invoice document
   ============================================================ */
.public-invoice-page {
  background: #e5e5e5;
  min-height: 100vh;
}

.invoice-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 800px;
  margin: 0 auto;
  padding: 16px 24px;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-secondary);
}

.invoice-toolbar a {
  color: var(--text-secondary);
  text-decoration: none;
}

.invoice-toolbar a:hover {
  color: var(--text);
}

.invoice-document {
  --col-qty: 80px;
  --col-rate: 80px;
  --col-amount: 80px;
  --right-col: calc(var(--col-qty) + var(--col-rate) + var(--col-amount));
  max-width: 800px;
  min-height: 1060px;
  margin: 0 auto 40px;
  padding: 60px;
  background: #fff;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
}

.inv-lines-section { flex: 1; }

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

.inv-from {
  font-size: 13px;
  line-height: 1.7;
}

.inv-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 24px;
  letter-spacing: 0.05em;
}

.inv-parties {
  display: flex;
  justify-content: space-between;
  margin-bottom: 32px;
}

.inv-to {
  line-height: 1.7;
}

.inv-label {
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.inv-dates {
  text-align: right;
  min-width: var(--right-col);
}

.inv-date-row {
  display: flex;
  justify-content: space-between;
  gap: 24px;
}

.inv-date-row span:first-child {
  color: var(--text-secondary);
  text-align: left;
}

.inv-date-row span:last-child {
  text-align: right;
}

.inv-separator {
  border-top: 1px solid var(--text);
  margin: 8px 0;
}

.inv-separator-short {
  border-top: 1px solid var(--text);
  margin: 4px 0;
}

.inv-line-header {
  display: flex;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 4px 0;
}

.inv-col-desc { flex: 1; }
.inv-col-qty { flex: 0 0 var(--col-qty); text-align: right; }
.inv-col-rate { flex: 0 0 var(--col-rate); text-align: right; }
.inv-col-amount { flex: 0 0 var(--col-amount); text-align: right; }

.inv-line {
  padding: 8px 0;
}

.inv-line-main {
  display: flex;
  align-items: baseline;
}

.inv-line-detail {
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.4;
  margin-top: 2px;
  padding-left: 0;
  max-width: calc(100% - var(--right-col));
}

.inv-totals {
  margin-top: 16px;
  margin-left: auto;
  width: var(--right-col);
}

.inv-total-row {
  display: flex;
  padding: 2px 0;
}

.inv-total-row span:first-child {
  white-space: nowrap;
  padding-right: 16px;
}

.inv-total-row span:last-child {
  flex: 1;
  text-align: right;
}

.inv-grand-total {
  font-weight: 700;
  padding-top: 4px;
}

.inv-vat-note {
  font-size: 11px;
  color: var(--text-secondary);
  margin: 2px 0;
}

.inv-section {
  margin-top: 32px;
}

.inv-pre {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 13px;
  margin: 4px 0;
}

.inv-footer {
  margin-top: 40px;
  font-size: 11px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

/* Estimate acceptance */
.estimate-acceptance {
  padding: 24px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.estimate-acceptance .terms-text {
  text-align: left;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 16px;
  padding: 16px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.accept-btn {
  padding: 12px 32px;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.accept-btn:hover {
  opacity: 0.85;
}

.accept-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.estimate-status-banner {
  padding: 16px;
  border-radius: var(--radius);
  text-align: center;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
}

.estimate-status-banner.accepted {
  background: #f0fdf4;
  color: var(--success);
  border: 1px solid #bbf7d0;
}

.estimate-status-banner.rejected {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.estimate-status-banner.expired {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

/* Batch actions bar */
.batch-bar {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-bottom: 12px;
}

/* Watermark overlay on public invoice */
.invoice-document { position: relative; overflow: hidden; }
.inv-watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-35deg);
  font-size: 100px;
  font-weight: 900;
  opacity: 0.08;
  pointer-events: none;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  z-index: 1;
}
.inv-watermark-paid { color: #16a34a; }
.inv-watermark-cancelled { color: #dc2626; }

/* Sortable table headers */
.inv-amount-due {
  font-size: 16px;
  font-weight: 700;
}

th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { text-decoration: underline; }
th[data-sort]::after { content: ''; margin-left: 4px; }
th.sort-asc::after { content: ' \25B2'; }
th.sort-desc::after { content: ' \25BC'; }

/* ============================================================
   Dashboard
   ============================================================ */
.dash-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}

.dash-header h1 {
  margin-bottom: 0;
  font-size: 24px;
}

.dash-header-right {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.dash-date {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.dash-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.dash-big-number {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 4px;
}

.dash-earned { color: var(--success); }

.dash-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
}

.dash-outstanding-breakdown {
  display: flex;
  gap: 16px;
  font-size: 13px;
  margin-top: 4px;
}

.dash-pending { color: var(--warning); font-weight: 500; }
.dash-overdue-text { color: var(--danger); font-weight: 500; }

.dash-progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dash-ring-legend {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-secondary);
}

.dash-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dash-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dash-currency-breakdown {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.dash-currency-breakdown span { display: block; }

.dash-rate-date {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.dash-invoices-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.dash-invoices-header .section-label { margin-bottom: 0; }

.dash-tabs {
  display: flex;
  gap: 8px;
}

button.filter-tag {
  background: none;
  cursor: pointer;
  font-family: var(--font);
}

.dash-status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}

.dash-dot-paid { background: var(--success); }
.dash-dot-sent { background: var(--warning); }
.dash-dot-viewed { background: #2563eb; }
.dash-dot-partially_paid { background: var(--warning); }
.dash-dot-overdue { background: var(--danger); }
.dash-dot-draft { background: var(--border); }

@media (max-width: 700px) {
  .dash-stats { grid-template-columns: 1fr; }
  .dash-header { flex-direction: column; gap: 12px; }
  .dash-header-right { align-items: flex-start; }
  .dash-invoices-header { flex-direction: column; align-items: flex-start; gap: 12px; }
}
