:root {
  --accent: #2f7d5f;
  --accent-dark: #226048;
  --accent-light: #e7f4ee;
  --bg: #faf9f7;
  --card: #ffffff;
  --ink: #1a1a1a;
  --ink-soft: #6b6b6b;
  --ink-faint: #a3a3a3;
  --border: #e6e5e0;
  --danger: #e5484d;
  --danger-light: #fdeceb;
  --success: #2fa86f;
  --success-light: #e7f7ee;
  --warn: #f5a623;
  --warn-light: #fff6e6;
  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

button, input, textarea, select {
  font-family: inherit;
  font-size: 15px;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.center-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 800;
}

.brand-name {
  font-size: 22px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 420px;
}

.card-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px;
}

.card-sub {
  font-size: 13.5px;
  color: var(--ink-soft);
  margin: 0 0 20px;
  line-height: 1.5;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--accent);
  background: #fff;
}

.field .hint {
  font-size: 12px;
  color: var(--ink-faint);
  margin-top: 4px;
}

.field-row {
  display: flex;
  gap: 10px;
}
.field-row .field { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 20px;
  border-radius: 999px;
  border: none;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }

.btn-outline { background: transparent; color: var(--ink); border: 1.5px solid var(--border); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger { background: var(--danger-light); color: var(--danger); }

.btn-sm { padding: 8px 16px; font-size: 13px; width: auto; }
.btn-icon { width: auto; padding: 10px 14px; }

.link-row {
  text-align: center;
  margin-top: 16px;
  font-size: 13.5px;
  color: var(--ink-soft);
}

.link-row a { color: var(--accent); font-weight: 700; }

.error-msg {
  background: var(--danger-light);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}

.error-msg.visible { display: block; }

.notice {
  background: var(--warn-light);
  color: #8a5a00;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  margin-bottom: 14px;
  line-height: 1.5;
}

.notice-success {
  background: var(--success-light);
  color: #1b6b46;
}

/* App shell */
.app-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: 90px;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index: 20;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0;
  color: var(--ink-faint);
  cursor: pointer;
  position: relative;
}

.tab-btn.active { color: var(--accent); }
.tab-btn .tab-icon { font-size: 20px; }
.tab-btn .tab-label { font-size: 10.5px; font-weight: 600; }

.tab-badge {
  position: absolute;
  top: 0;
  right: 22%;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Avatar (business logo) */
.avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 20px;
  flex-shrink: 0;
  overflow: hidden;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; }

.avatar-sm { width: 40px; height: 40px; font-size: 15px; }
.avatar-lg { width: 96px; height: 96px; font-size: 32px; }

/* List items */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
}

.list-item-info { flex: 1; min-width: 0; }
.list-item-name { font-weight: 700; font-size: 14.5px; }
.list-item-sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-amount { font-weight: 800; font-size: 15px; text-align: right; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-faint);
}

.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state .empty-title { font-weight: 700; color: var(--ink-soft); margin-bottom: 4px; }
.empty-state .empty-desc { font-size: 13px; }

/* Status badges */
.status-badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.status-draft { background: var(--border); color: var(--ink-soft); }
.status-sent { background: var(--accent-light); color: var(--accent-dark); }
.status-paid { background: var(--success-light); color: #1b6b46; }
.status-overdue { background: var(--danger-light); color: var(--danger); }
.status-approved { background: var(--success-light); color: #1b6b46; }
.status-declined { background: var(--danger-light); color: var(--danger); }

/* Line items table */
.line-items { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 16px; }
.line-item-row {
  display: grid;
  grid-template-columns: 1fr 60px 90px 90px 32px;
  gap: 8px;
  padding: 10px 12px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}
.line-item-row:last-child { border-bottom: none; }
.line-item-row.header { background: var(--bg); font-size: 11.5px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; }
.line-item-row input { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; background: #fff; }
.line-item-remove { background: none; border: none; color: var(--ink-faint); cursor: pointer; font-size: 16px; padding: 4px; }
.line-item-remove:hover { color: var(--danger); }

.totals-box { padding: 4px 12px 0; }
.totals-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.totals-row.grand { font-weight: 800; font-size: 17px; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 12px; }

.loading-center { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--ink-faint); font-size: 14px; }

/* Public invoice/estimate view */
.doc-view {
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 20px;
}
.doc-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.doc-title { font-size: 26px; font-weight: 800; margin: 0; }
.doc-meta { font-size: 13px; color: var(--ink-soft); margin-top: 4px; }
.doc-parties { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 24px; flex-wrap: wrap; }
.doc-party-label { font-size: 11px; font-weight: 700; color: var(--ink-faint); text-transform: uppercase; margin-bottom: 4px; }
.doc-party-name { font-weight: 700; }

@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
}

/* Install / notification banners */
.install-banner {
  background: var(--accent-light);
  color: var(--accent-dark);
  padding: 12px 40px 12px 16px;
  font-size: 13px;
  line-height: 1.5;
  position: relative;
}

.install-banner strong { display: block; margin-bottom: 2px; }

.install-banner-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  font-size: 20px;
  color: var(--accent-dark);
  cursor: pointer;
  padding: 6px;
  line-height: 1;
}

.install-banner-btn {
  display: inline-block;
  margin-top: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
