:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #eef2f6;
  --text: #111827;
  --muted: #6b7280;
  --border: #d9dee7;
  --primary: #14213d;
  --primary-2: #1f3a68;
  --accent: #fca311;
  --danger: #b91c1c;
  --success: #166534;
  --shadow: 0 10px 30px rgba(17, 24, 39, .08);
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 650;
}

button:disabled { opacity: .5; cursor: not-allowed; }

.primary { background: var(--primary); color: white; }
.primary:hover { background: var(--primary-2); }
.ghost { background: var(--panel-2); color: var(--primary); }
.danger { background: #fee2e2; color: var(--danger); }
.success { background: #dcfce7; color: var(--success); }
.small { padding: 7px 10px; font-size: .9rem; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: 74px 1fr;
}

.topbar {
  grid-column: 1 / 3;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 3;
}

.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-lockup span { display: block; color: var(--muted); font-size: .86rem; }
.brand-mark {
  width: 44px; height: 44px;
  border-radius: 13px;
  background: var(--primary);
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 1.35rem;
  box-shadow: var(--shadow);
}

.top-actions { display: flex; gap: 10px; align-items: center; }
.mobile-menu { display: none; background: var(--panel-2); }

.sidebar {
  grid-column: 1;
  grid-row: 2;
  border-right: 1px solid var(--border);
  background: var(--panel);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.nav-link {
  width: 100%;
  display: block;
  text-align: left;
  background: transparent;
  color: var(--text);
  margin-bottom: 6px;
}
.nav-link.active, .nav-link:hover {
  background: var(--panel-2);
  color: var(--primary);
}

.sidebar-footer {
  padding: 12px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 14px;
  color: #7c2d12;
}

.main {
  grid-column: 2;
  grid-row: 2;
  padding: 28px;
  max-width: 1380px;
  width: 100%;
}

h1, h2, h3 { margin-top: 0; }
h1 { font-size: clamp(1.7rem, 3vw, 2.4rem); margin-bottom: 8px; }
h2 { font-size: 1.35rem; }
p { color: var(--muted); }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat strong { font-size: 1.85rem; }
.stat span { color: var(--muted); }

.form-row { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 12px; }
.form-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-row.one { grid-template-columns: 1fr; }
label { display: grid; gap: 6px; color: #374151; font-weight: 650; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: white;
  color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; border-bottom: 1px solid var(--border); padding: 10px; vertical-align: middle; }
th { color: #374151; background: #f9fafb; font-size: .9rem; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.status-pill {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 750;
  background: #e5e7eb;
  color: #374151;
}
.status-estimate { background: #dbeafe; color: #1e40af; }
.status-invoice { background: #fef3c7; color: #92400e; }
.status-paid { background: #dcfce7; color: #166534; }
.status-overdue { background: #fee2e2; color: #991b1b; }

.estimate-builder {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
}
.summary-box {
  position: sticky;
  top: 92px;
}
.summary-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.summary-row.total { font-size: 1.25rem; font-weight: 800; border-bottom: none; }

.item-picker {
  display: grid;
  grid-template-columns: 1.2fr 1fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.document-preview {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  max-width: 850px;
  margin: 0 auto;
}
.doc-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 3px solid var(--primary);
  padding-bottom: 18px;
  margin-bottom: 20px;
}
.doc-title { font-size: 2rem; font-weight: 850; color: var(--primary); text-transform: uppercase; letter-spacing: .04em; }
.doc-company { font-size: 1.25rem; font-weight: 800; }
.doc-meta { text-align: right; }
.terms { white-space: pre-wrap; color: #374151; }

.notice {
  border-left: 5px solid var(--accent);
  background: #fffbeb;
  color: #78350f;
  padding: 12px 14px;
  border-radius: 12px;
}

.hidden { display: none !important; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .topbar { grid-column: 1; }
  .main { grid-column: 1; padding: 18px; }
  .mobile-menu { display: inline-block; }
  .sidebar {
    position: fixed;
    top: 74px; bottom: 0; left: 0;
    width: 280px;
    z-index: 5;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .grid-2, .grid-3, .grid-4, .estimate-builder, .form-row, .form-row.three, .item-picker { grid-template-columns: 1fr; }
  .top-actions .ghost { display: none; }
  .summary-box { position: static; }
}

@media print {
  body { background: white; }
  .topbar, .sidebar, .no-print, .actions, button { display: none !important; }
  .app-shell, .main { display: block; padding: 0; margin: 0; }
  .card { border: none; box-shadow: none; padding: 0; }
  .document-preview { border: none; padding: 0; max-width: none; }
  a[href]:after { content: ""; }
}
