/* ── Grind Blue CRM — Stylesheet ── */

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

:root {
  --steel-blue:    #0E2640;
  --deep-navy:     #0A1B2E;
  --sky-steel:     #1B3A5B;
  --orange:        #FF8A1F;
  --ember:         #E55A00;
  --concrete:      #5A6470;
  --galvanized:    #B8C2CC;
  --bg:            #F4F6F8;
  --text:          #1A1D21;
  --warning:       #F2C200;
  --error:         #C8323C;
  --success:       #3F8E3F;
  --white:         #FFFFFF;
  --radius:        10px;
  --shadow:        0 2px 12px rgba(10,27,46,0.10);
  --shadow-lg:     0 4px 24px rgba(10,27,46,0.16);
  --nav-h:         64px;
  --bottom-h:      68px;
  --accent:        #FF8A1F;   /* alias for --orange, used throughout */
}

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

html, body {
  height: 100%;
  font-family: 'DM Sans', Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

/* ── Top Nav ── */
#top-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--deep-navy);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-logo {
  width: 36px;
  height: 36px;
}

.nav-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--white);
  letter-spacing: 0.01em;
}

.nav-title span {
  color: var(--orange);
}

.nav-page-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--galvanized);
}

/* ── Bottom Nav ── */
#bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-h);
  background: var(--deep-navy);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--sky-steel);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius);
  transition: background 0.15s;
  color: var(--galvanized);
  border: none;
  background: transparent;
  font-family: inherit;
  flex: 1;
}

.nav-item:hover { background: var(--sky-steel); }

.nav-item.active {
  color: var(--orange);
}

.nav-item svg {
  width: 22px;
  height: 22px;
  stroke-width: 1.8;
}

.nav-label {
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}

/* ── Page Layout ── */
#app {
  padding-top: calc(var(--nav-h) + 16px);
  padding-bottom: calc(var(--bottom-h) + 16px);
  padding-left: 16px;
  padding-right: 16px;
  min-height: 100vh;
}

.view { display: none; }
.view.active { display: block; }

/* ── Cards ── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--steel-blue);
}

.card-sub {
  font-size: 0.82rem;
  color: var(--concrete);
  margin-top: 2px;
}

/* ── Section Header ── */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--steel-blue);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, transform 0.1s;
  text-decoration: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--orange);
  color: var(--white);
}
.btn-primary:hover { background: var(--ember); }

.btn-secondary {
  background: var(--steel-blue);
  color: var(--white);
}
.btn-secondary:hover { background: var(--sky-steel); }

.btn-ghost {
  background: transparent;
  color: var(--steel-blue);
  border: 1.5px solid var(--galvanized);
}
.btn-ghost:hover { background: var(--bg); }

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

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-icon {
  padding: 8px;
  border-radius: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--concrete);
  transition: background 0.15s;
  display: inline-flex;
  align-items: center;
}
.btn-icon:hover { background: var(--bg); color: var(--steel-blue); }
.btn-icon svg { width: 18px; height: 18px; }

/* ── Forms ── */
.form-group {
  margin-bottom: 14px;
}

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--concrete);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input, select, textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--galvanized);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--white);
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--orange);
}

textarea { resize: vertical; min-height: 80px; }

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.form-row .form-group {
  flex: 1;
  min-width: 80px;
}

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10,27,46,0.55);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--white);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px 20px 32px;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--steel-blue);
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--concrete);
  font-size: 1.4rem;
  line-height: 1;
  padding: 4px;
}

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

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  text-align: center;
  transition: transform 0.1s, box-shadow 0.1s;
}
.stat-card:active {
  transform: scale(0.97);
  box-shadow: none;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--steel-blue);
}

.stat-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--concrete);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
}

.stat-card.accent .stat-value { color: var(--orange); }

/* ── Status Badges ── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-active   { background: #e8f5e9; color: var(--success); }
.badge-pending  { background: #fff8e1; color: #b8860b; }
.badge-complete { background: #e3f2fd; color: #1565c0; }
.badge-invoiced { background: #f3e5f5; color: #6a1b9a; }

/* ── Estimate Builder ── */
.zone-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}

.zone-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--steel-blue);
  color: var(--white);
  cursor: pointer;
  user-select: none;
}

.zone-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.zone-total {
  font-weight: 700;
  color: var(--orange);
}

.zone-body {
  padding: 16px;
  display: none;
}

.zone-body.open { display: block; }

.zone-subtotal {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--bg);
  font-size: 0.85rem;
  color: var(--concrete);
  text-align: right;
}

.estimate-total-bar {
  background: var(--deep-navy);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  margin-bottom: 12px;
}

.estimate-total-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--galvanized);
}

.estimate-total-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--orange);
}

/* ── Invoice ── */
.invoice-preview {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 24px;
}

.invoice-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--bg);
}

.invoice-brand {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--steel-blue);
}

.invoice-brand span { color: var(--orange); }

.invoice-number {
  font-size: 0.85rem;
  color: var(--concrete);
  text-align: right;
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 0.88rem;
}

.invoice-table th {
  background: var(--bg);
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--concrete);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.invoice-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--bg);
  color: var(--text);
}

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

.invoice-totals {
  text-align: right;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 2px solid var(--steel-blue);
}

.invoice-grand-total {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--steel-blue);
}

/* ── Search ── */
.search-bar {
  position: relative;
  margin-bottom: 16px;
}

.search-bar input {
  padding-left: 40px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--concrete);
  pointer-events: none;
}

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--concrete);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 0.95rem;
  margin-bottom: 16px;
}

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: calc(var(--bottom-h) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--steel-blue);
  color: var(--white);
  padding: 12px 20px;
  border-radius: 30px;
  font-size: 0.88rem;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 300;
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--bg);
  margin: 12px 0;
}

/* ── Confirm dialog ── */
.confirm-btns {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: flex-end;
}

/* ── Price Book ── */
.pb-pills-wrap {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.pb-pills-wrap::-webkit-scrollbar { display: none; }

.pb-pill {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 20px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--galvanized);
  background: transparent;
  color: var(--concrete);
  transition: all 0.15s;
  white-space: nowrap;
}

.pb-pill.active {
  background: var(--steel-blue);
  border-color: var(--steel-blue);
  color: var(--white);
}

.pb-pricing-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--bg);
}

.pb-price-block { flex: 1; }

.pb-price-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--concrete);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.pb-price-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--steel-blue);
}

.pb-unit {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--concrete);
}

.pb-arrow {
  color: var(--galvanized);
  font-size: 1rem;
  flex-shrink: 0;
}

/* ── Site Visit ── */
.sv-subheader {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1.5px solid var(--galvanized);
}

.sv-job-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unit-toggle {
  display: inline-flex;
  background: var(--bg);
  border: 1.5px solid var(--galvanized);
  border-radius: 8px;
  overflow: hidden;
}

.unit-btn {
  padding: 6px 14px;
  background: transparent;
  border: none;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--concrete);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.unit-btn.active {
  background: var(--primary);
  color: #fff;
}

.ftin-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ftin-input {
  width: 58px;
  text-align: center;
}

.ftin-label {
  font-size: 0.82rem;
  color: var(--concrete);
  font-weight: 600;
  flex-shrink: 0;
}

.sv-sqft-preview {
  background: var(--bg);
  border: 1.5px solid var(--galvanized);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
}

.sv-sqft-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  color: var(--concrete);
  padding: 2px 0;
}

.sv-sqft-row.accent strong {
  color: var(--accent);
  font-size: 1rem;
}

.sv-totals-card {
  background: var(--primary);
  color: #fff;
}

.sv-totals-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--galvanized);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

.sv-totals-group { margin-bottom: 12px; }

.sv-totals-group-title {
  font-weight: 600;
  color: #fff;
  font-size: 0.88rem;
  margin-bottom: 4px;
}

.sv-totals-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--galvanized);
  padding: 1px 0;
}

.sv-totals-row span:last-child { color: #fff; }

.sv-totals-row.accent span:last-child {
  color: var(--accent);
  font-weight: 700;
}

.sv-totals-final {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--sky-steel);
  margin-top: 12px;
  padding-top: 12px;
  font-size: 0.88rem;
  color: var(--galvanized);
}

.sv-totals-final span:last-child {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
}

/* ── Estimate Editor / Phase Accordion ── */

.view-fullscreen {
  padding-bottom: calc(var(--bottom-h) + 24px);
}

/* Phase card */
.est-phase {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  overflow: hidden;
  transition: opacity 0.2s;
}

.est-phase.est-phase-disabled {
  opacity: 0.45;
}

.est-phase-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  cursor: pointer;
  user-select: none;
}

.est-phase-toggle {
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: var(--galvanized);
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
  cursor: pointer;
  border: none;
}

.est-phase-toggle.on { background: var(--orange); }

.est-phase-toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

.est-phase-toggle.on::after { transform: translateX(16px); }

.est-phase-left {
  flex: 1;
  min-width: 0;
}

.est-phase-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.est-phase-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.est-phase-total {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--orange);
  min-width: 60px;
  text-align: right;
}

.est-phase-chevron {
  color: var(--galvanized);
  font-size: 0.8rem;
  transition: transform 0.2s;
}

.est-phase.open .est-phase-chevron { transform: rotate(180deg); }

/* Phase body */
.est-phase-body {
  display: none;
  border-top: 1px solid var(--bg);
  padding: 12px 14px;
}

.est-phase-body.open { display: block; }

/* Phase actions (Add Material / Add Labor buttons) */
.est-phase-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.est-phase-actions .btn { flex: 1; }

/* Item rows within a phase */
.est-item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--bg);
}

.est-item-row:last-of-type { border-bottom: none; }

.est-item-info { flex: 1; min-width: 0; }

.est-item-name {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.est-item-meta {
  font-size: 0.75rem;
  color: var(--concrete);
  margin-top: 2px;
}

.est-item-type-badge {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.est-item-type-badge.material {
  background: #E8F0FE;
  color: #1A56A0;
}

.est-item-type-badge.labor {
  background: #FEF0E0;
  color: #B35F00;
}

.est-item-amount {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text);
  min-width: 56px;
  text-align: right;
  flex-shrink: 0;
}

.est-item-del {
  background: none;
  border: none;
  color: var(--concrete);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px;
  border-radius: 4px;
  line-height: 1;
  flex-shrink: 0;
}

.est-item-del:hover { color: var(--error); }

/* Estimate totals bar — sticky above bottom nav */
.est-totals-bar {
  position: sticky;
  bottom: calc(var(--bottom-h) + 8px);
  background: var(--steel-blue);
  color: #fff;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-top: 16px;
  box-shadow: 0 -2px 16px rgba(10,27,46,0.22);
  z-index: 10;
}

.est-totals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
  color: var(--galvanized);
  padding: 3px 0;
}

.est-totals-row span:last-child { color: #fff; }

.est-totals-row.est-totals-total {
  border-top: 1px solid var(--sky-steel);
  margin-top: 8px;
  padding-top: 10px;
  font-size: 1rem;
  font-weight: 700;
}

.est-totals-row.est-totals-total span { color: var(--orange); }

/* Material picker in est-item-modal */
.mat-pick-list {
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--bg);
  border-radius: var(--radius);
  margin-bottom: 14px;
}

.mat-pick-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--bg);
  transition: background 0.15s;
}

.mat-pick-row:last-child { border-bottom: none; }
.mat-pick-row:hover { background: var(--bg); }

.mat-pick-row.mat-selected {
  background: #E8F0FE;
}

.mat-pick-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

.mat-pick-meta {
  font-size: 0.75rem;
  color: var(--concrete);
}

.mat-pick-price {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--orange);
  flex-shrink: 0;
  margin-left: 10px;
}

/* Jobs (work orders) list */
.job-wo-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 10px;
}

.job-wo-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  margin-bottom: 4px;
}

.job-wo-meta {
  font-size: 0.8rem;
  color: var(--concrete);
}

/* ── Responsive ── */
@media (min-width: 480px) {
  #app { padding-left: 24px; padding-right: 24px; }
  .modal { border-radius: 16px; margin: auto; }
  .modal-overlay { align-items: center; }
}
