/* ═══════════════════════════════════════
   FIELD SQUARE — components.css
   Buttons, fields, cards, badges, toggles
═══════════════════════════════════════ */

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
  flex-shrink: 0;
}

.btn svg { flex-shrink: 0; }

.btn-primary {
  background: var(--ink);
  color: var(--gold);
  padding: 9px 16px;
  border: 1px solid var(--ink);
}
.btn-primary:hover { background: var(--ink2); }
.btn-primary:active { transform: scale(0.98); }

.btn-gold {
  background: var(--gold);
  color: var(--ink);
  padding: 9px 16px;
  font-weight: 600;
}
.btn-gold:hover { background: var(--gold-l); }

.btn-outline {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border2);
  padding: 8px 14px;
}
.btn-outline:hover { background: var(--surface2); color: var(--text); }

.btn-ghost {
  background: none;
  color: var(--muted);
  padding: 7px 10px;
  border: 1px solid transparent;
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }

.btn-danger {
  background: none;
  color: var(--red);
  border: 1px solid var(--red-b);
  padding: 7px 12px;
}
.btn-danger:hover { background: var(--red-p); }

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius);
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--muted);
}
.btn-icon:hover { background: var(--surface2); color: var(--text); }
.btn-icon.active { background: var(--ink); color: var(--gold); border-color: var(--ink); }

.btn-sm {
  font-size: 11px;
  padding: 5px 10px;
  gap: 4px;
}
.btn-sm.btn-icon { width: 26px; height: 26px; }

.btn-full { width: 100%; }

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── TOOL BUTTONS ── */
.tool-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: var(--radius);
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
}

.tool-btn:hover { background: var(--surface3); color: var(--text); }
.tool-btn.active { background: var(--ink); color: var(--gold); border-color: var(--ink); }
.tool-btn.danger { color: var(--red); border-color: var(--red-b); }
.tool-btn.danger:hover { background: var(--red-p); }

/* ── ROOM TABS ── */
.rtab {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--t-fast);
  flex-shrink: 0;
}

.rtab:hover { background: var(--surface3); color: var(--text); }

.rtab.active {
  background: var(--ink);
  color: var(--gold);
  border-color: var(--ink);
}

.rtab.active .rdot { background: var(--gold); }

.rtab-add {
  border-style: dashed;
  color: var(--muted2);
}
.rtab-add:hover { color: var(--text); border-color: var(--border3); background: var(--surface2); }

.rdot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── FORM FIELDS ── */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

.field label .req {
  color: var(--red);
  margin-left: 2px;
}

.field input,
.field select,
.field textarea {
  padding: 7px 10px;
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  width: 100%;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-p);
}

.field input.err,
.field select.err,
.field textarea.err {
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-p);
}

.field input::placeholder { color: var(--muted3); }

.field textarea { resize: vertical; min-height: 70px; }

.field-err {
  font-size: 11px;
  font-weight: 500;
  color: var(--red);
  display: none;
}

.field-err.show { display: block; }

.field-hint {
  font-size: 11px;
  color: var(--muted2);
}

/* ── FORM GRID ── */
.fgrid { display: grid; gap: 8px; margin-bottom: 8px; }
.fgrid.c2 { grid-template-columns: 1fr 1fr; }
.fgrid.c3 { grid-template-columns: 1fr 1fr 1fr; }

/* ── RANGE SLIDER ── */
.range-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.range-row input[type="range"] {
  flex: 1;
  height: 4px;
  accent-color: var(--gold);
  cursor: pointer;
  padding: 0;
  border: none;
  background: none;
  box-shadow: none;
}

.range-row input[type="range"]:focus {
  box-shadow: none;
  border: none;
}

.range-val {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  min-width: 36px;
  text-align: right;
  color: var(--text);
}

/* ── RECT DIMENSION INPUTS ── */
.rect-dims {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 6px;
  margin-bottom: 8px;
}

.rect-dims .x-sep {
  font-size: 20px;
  color: var(--muted2);
  font-weight: 300;
  text-align: center;
  padding-bottom: 8px;
  line-height: 1;
}

/* ── AREA CARD ── */
.area-card {
  background: var(--gold-p);
  border: 1px solid var(--gold-b);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.area-num {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1;
}

.area-label {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

.area-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 10px;
  background: var(--gold);
  color: var(--ink);
  white-space: nowrap;
}

/* ── TOGGLE ── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.toggle-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-slider {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background: var(--surface3);
  border: 1px solid var(--border2);
  transition: var(--t-fast);
  cursor: pointer;
}

.toggle input:checked + .toggle-slider {
  background: var(--gold);
  border-color: var(--gold);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background: white;
  transition: var(--t-fast);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

/* ── COST LINES ── */
.cost-lines { display: flex; flex-direction: column; gap: 5px; margin-bottom: 6px; }

.cost-line {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 5px 7px;
}

.cost-line input,
.cost-line select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 7px;
  font-size: 12px;
  color: var(--text);
  transition: border-color var(--t-fast);
  min-width: 0;
}

.cost-line input:focus,
.cost-line select:focus {
  border-color: var(--gold);
  outline: none;
  box-shadow: 0 0 0 2px var(--gold-p);
}

.cost-line input.desc { flex: 2; }
.cost-line input.amount { width: 80px; flex-shrink: 0; }
.cost-line input.days { width: 52px; flex-shrink: 0; }
.cost-line select.type { width: 68px; flex-shrink: 0; font-size: 11px; }

.cost-rm {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--red);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--t-fast);
  line-height: 1;
}

.cost-rm:hover { background: var(--red-p); border-color: var(--red-b); }

.add-line-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted2);
  border: 1px dashed var(--border2);
  border-radius: var(--radius);
  padding: 6px 10px;
  background: none;
  width: 100%;
  cursor: pointer;
  transition: all var(--t-fast);
  font-family: var(--font);
}

.add-line-btn:hover {
  color: var(--text);
  border-color: var(--border3);
  background: var(--surface2);
}

/* ── METRIC CARDS ── */
.metrics-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-bottom: 12px;
}

.metric-card {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 10px;
  text-align: center;
}

.metric-val {
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1;
}

.metric-lbl {
  font-size: 10px;
  color: var(--muted);
  margin-top: 3px;
}

/* ── SUMMARY TABLE ── */
.sum-table {
  width: 100%;
  border-collapse: collapse;
}

.sum-table td {
  padding: 5px 0;
  font-size: 13px;
}

.sum-table td:last-child {
  text-align: right;
  font-family: var(--mono);
  font-size: 12px;
}

.sum-table .sum-cat td {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--muted);
  padding-top: 12px;
  padding-bottom: 3px;
}

.sum-table .sum-muted td { color: var(--muted); }

.sum-table .sum-divider td {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.sum-table .sum-total td {
  border-top: 1.5px solid var(--border3);
  padding-top: 10px;
  font-weight: 600;
  font-size: 14px;
}

.sum-table .sum-total td:last-child {
  font-size: 15px;
}

/* ── ROOM SUMMARY LIST ── */
.room-sum-list { display: flex; flex-direction: column; gap: 4px; }

.room-sum-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 9px;
  border-radius: var(--radius);
  background: var(--surface2);
  font-size: 12px;
  cursor: pointer;
  transition: background var(--t-fast);
}

.room-sum-item:hover { background: var(--surface3); }
.room-sum-item.active { background: var(--gold-p); border: 1px solid var(--gold-b); }

.room-sum-left {
  display: flex;
  align-items: center;
  gap: 7px;
}

.room-sum-name { font-weight: 500; color: var(--text); }
.room-sum-mat  { font-size: 11px; color: var(--muted); }
.room-sum-area { font-family: var(--mono); font-size: 12px; color: var(--muted); }

/* ── BADGES ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 10px;
  white-space: nowrap;
}

.badge-green { background: var(--green-p); color: var(--green); }
.badge-red   { background: var(--red-p);   color: var(--red);   }
.badge-amber { background: var(--amber-p); color: var(--amber); }
.badge-blue  { background: var(--blue-p);  color: var(--blue);  }
.badge-gold  { background: var(--gold-p);  color: var(--gold);  border: 1px solid var(--gold-b); }

/* ── TOAST NOTIFICATION ── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--ink);
  color: white;
  padding: 9px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100vw - 40px);
}

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

.toast.success { background: var(--green); }
.toast.error   { background: var(--red);   }

/* ── DIVIDER ── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

/* ── LOADING SPINNER ── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border2);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── MODAL HEADER CLOSE ── */
.modal-close {
  width: 30px;
  height: 30px;
  border-radius: var(--radius);
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--muted);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
  transition: all var(--t-fast);
}

.modal-close:hover { background: var(--surface3); color: var(--text); }

.modal-close.light {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.6);
}

.modal-close.light:hover {
  background: rgba(255, 255, 255, 0.14);
  color: white;
}

/* ── PROJECT SAVE STATUS ── */
.save-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted2);
  transition: color var(--t-fast);
}

.save-indicator.saving { color: var(--amber); }
.save-indicator.saved  { color: var(--green); }
.save-indicator.error  { color: var(--red);   }

/* ── VAT ROW ── */
.vat-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.vat-row input[type="number"] {
  width: 70px;
  padding: 5px 8px;
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--mono);
  background: var(--surface);
  color: var(--text);
}

.vat-row input[type="number"]:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-p);
  outline: none;
}

/* ── ESTIMATE VIEW TOGGLE ── */
.est-view-toggle {
  display: flex;
  background: var(--surface3);
  border-radius: var(--radius);
  padding: 3px;
  margin-bottom: 12px;
}

.est-view-btn {
  flex: 1;
  padding: 6px;
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--t-fast);
}

.est-view-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ── ESTIMATE DOCUMENT STYLES ── */
.est-co-name {
  font-size: 17px;
  font-weight: 600;
  color: white;
}

.est-co-sub {
  font-size: 12px;
  color: rgba(255,255,255,0.4);
  margin-top: 2px;
}

.est-title-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-top: 14px;
}

.est-doc-title {
  font-size: 24px;
  font-weight: 300;
  color: white;
  letter-spacing: -0.3px;
}

.est-doc-num {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--gold);
}

.est-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
}

.est-table th {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 7px 0;
  border-bottom: 1.5px solid var(--border);
  text-align: left;
}

.est-table th:last-child,
.est-table td:last-child { text-align: right; }

.est-table td {
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.est-table .cat-row td {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--muted);
  padding-top: 12px;
  border-bottom: none;
}

.est-table .sub-row td {
  font-size: 12px;
  color: var(--muted);
  padding: 3px 0 3px 12px;
  border-bottom: none;
}

.est-table .sum-row td {
  border-bottom: none;
  padding: 4px 0;
  font-size: 12px;
  color: var(--muted);
}

.est-table .total-row td {
  border-top: 2px solid var(--ink);
  border-bottom: none;
  padding-top: 10px;
  font-weight: 600;
  font-size: 15px;
}

.est-disclaimer {
  font-size: 11px;
  color: var(--muted2);
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  line-height: 1.6;
}
