/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1e40af;
  --primary-light: #3b82f6;
  --primary-dark: #1e3a8a;
  --accent: #f59e0b;
  --accent-light: #fcd34d;
  --success: #10b981;
  --danger: #ef4444;
  --bg: #f0f4ff;
  --bg2: #e8eeff;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 24px rgba(30,64,175,0.08);
  --shadow-lg: 0 8px 40px rgba(30,64,175,0.14);
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Poppins', sans-serif;
  --font-ur: 'Noto Nastaliq Urdu', serif;

  /* Theme colors */
  --theme-primary: #1e40af;
  --theme-secondary: #3b82f6;
  --theme-accent: #f59e0b;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  direction: ltr;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--primary-light); border-radius: 3px; }

/* ===== HEADER ===== */
.main-header {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 60%, var(--primary-light) 100%);
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(30,64,175,0.3);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72px;
  gap: 24px;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-icon {
  width: 46px; height: 46px;
  background: rgba(255,255,255,0.15);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: white;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.2);
}
.logo-icon svg { width: 24px; height: 24px; }

.logo-text { display: flex; flex-direction: column; }
.logo-main { font-size: 1.3rem; font-weight: 800; color: white; letter-spacing: -0.5px; }
.logo-pro { color: var(--accent-light); }
.logo-sub { font-size: 0.7rem; color: rgba(255,255,255,0.7); font-weight: 400; }

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

.nav-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 18px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 10px;
  color: rgba(255,255,255,0.85);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.nav-btn svg { width: 16px; height: 16px; }
.nav-btn:hover, .nav-btn.active {
  background: rgba(255,255,255,0.25);
  color: white;
  border-color: rgba(255,255,255,0.4);
  transform: translateY(-1px);
}

/* ===== MAIN CONTENT ===== */
.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* ===== TAB PANELS ===== */
.tab-panel { display: none; animation: fadeIn 0.3s ease; }
.tab-panel.active { display: block; }

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

/* ===== PAGE TITLE ===== */
.page-title {
  margin-bottom: 28px;
  padding: 24px 28px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  border-radius: var(--radius);
  color: white;
  display: flex;
  align-items: center;
  gap: 20px;
}
.page-title h1 {
  font-size: 1.6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.page-title h1 svg { width: 28px; height: 28px; }
.page-title p {
  font-family: var(--font-ur);
  font-size: 1rem;
  opacity: 0.85;
}

/* ===== CALCULATOR GRID ===== */
.calc-grid {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 24px;
  align-items: start;
}

/* ===== CARDS ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
  border: 1px solid var(--border);
  transition: box-shadow 0.2s;
}
.card:hover { box-shadow: var(--shadow-lg); }

.card-header {
  padding: 16px 22px;
  background: linear-gradient(135deg, #f8faff 0%, #eef2ff 100%);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-header svg { width: 18px; height: 18px; }

/* ===== FORM ELEMENTS ===== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 20px 22px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full-width { grid-column: 1 / -1; }

.form-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--text);
  background: #fafbff;
  transition: all 0.2s;
  outline: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary-light);
  background: white;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

/* ===== FINISHING OPTIONS ===== */
.finishing-options { padding: 16px 22px; display: flex; flex-direction: column; gap: 10px; }

.toggle-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
  border: 1.5px solid transparent;
}
.toggle-item:hover { background: #f0f4ff; border-color: var(--border); }

.toggle-item input[type="checkbox"] { display: none; }

.toggle-box {
  width: 40px; height: 22px;
  background: #cbd5e1;
  border-radius: 11px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-box::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  background: white;
  border-radius: 50%;
  top: 3px; left: 3px;
  transition: transform 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.toggle-item input:checked ~ .toggle-box { background: var(--primary-light); }
.toggle-item input:checked ~ .toggle-box::after { transform: translateX(18px); }

.toggle-item span:not(.toggle-box) {
  flex: 1;
  font-size: 0.88rem;
  font-weight: 500;
}

.inline-cost {
  width: 90px;
  padding: 6px 10px !important;
  border: 1.5px solid var(--border) !important;
  border-radius: 8px !important;
  font-size: 0.82rem !important;
  text-align: center;
}

.inline-select {
  width: 110px;
  padding: 6px 10px !important;
  border: 1.5px solid var(--border) !important;
  border-radius: 8px !important;
  font-size: 0.82rem !important;
  background: white;
  cursor: pointer;
  font-family: var(--font);
  color: var(--text);
  outline: none;
  transition: all 0.2s;
}

.inline-select:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.1);
}

/* ===== CALCULATE BUTTON ===== */
.btn-calculate {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(30,64,175,0.3);
  letter-spacing: 0.5px;
}
.btn-calculate svg { width: 20px; height: 20px; }
.btn-calculate:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(30,64,175,0.4);
}
.btn-calculate:active { transform: translateY(0); }

/* ===== RESULTS PANEL ===== */
.results-sticky { position: sticky; top: 90px; }

.results-card { margin-bottom: 20px; }
.results-header { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%) !important; color: white !important; }
.results-header svg { color: white; }

.cost-breakdown { padding: 16px 22px; }

.cost-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px dashed #f1f5f9;
  font-size: 0.88rem;
}
.cost-row span:first-child {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}
.cost-row span:first-child svg { width: 14px; height: 14px; }
.cost-row span:last-child { font-weight: 600; color: var(--text); }

.cost-divider {
  height: 2px;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 1px;
  margin: 10px 0;
}

.cost-row.subtotal span { font-weight: 700; color: var(--text); font-size: 0.95rem; }
.cost-row.subtotal span:last-child { color: var(--primary); }
.cost-row.profit span:last-child { color: var(--success); }
.cost-row.tax span:last-child { color: var(--accent); }

.cost-row.grand-total {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  margin: 0 -22px;
  padding: 14px 22px;
  border-radius: 0 0 var(--radius) var(--radius);
  border-bottom: none;
}
.cost-row.grand-total span {
  color: white !important;
  font-size: 1.05rem !important;
  font-weight: 800 !important;
}

/* ===== PER UNIT BOX ===== */
.per-unit-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px 22px;
  background: #f8faff;
  border-top: 1px solid var(--border);
}

.per-unit-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  background: white;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  text-align: center;
}
.per-unit-item span { font-size: 0.72rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; }
.per-unit-item strong { font-size: 1rem; color: var(--primary); font-weight: 700; }

/* ===== ACTION BUTTONS ===== */
.action-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px 22px;
  border-top: 1px solid var(--border);
}

.btn-primary {
  padding: 11px 18px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
  box-shadow: 0 3px 10px rgba(30,64,175,0.25);
}
.btn-primary svg { width: 16px; height: 16px; }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 5px 16px rgba(30,64,175,0.35); }

.btn-secondary {
  padding: 11px 18px;
  background: white;
  color: var(--primary);
  border: 1.5px solid var(--primary-light);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
}
.btn-secondary svg { width: 16px; height: 16px; }
.btn-secondary:hover { background: #f0f4ff; transform: translateY(-1px); }

/* ===== CHART BARS ===== */
.chart-card .card-header { background: linear-gradient(135deg, #f8faff, #eef2ff) !important; }
.chart-bars { padding: 16px 22px; display: flex; flex-direction: column; gap: 10px; }

.chart-bar-item { display: flex; flex-direction: column; gap: 4px; }
.chart-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}
.chart-bar-track {
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}
.chart-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s cubic-bezier(0.4,0,0.2,1);
}

/* ===== JOB CARD ===== */
.jobcard-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.jobcard-wrapper {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  max-width: 900px;
  margin: 0 auto;
  border: 1px solid var(--border);
}

/* JC Header */
.jc-header {
  background: linear-gradient(135deg, var(--theme-primary) 0%, var(--theme-secondary) 100%);
  padding: 28px 36px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: white;
}

.jc-company { display: flex; align-items: center; gap: 16px; }

.jc-logo {
  width: 60px; height: 60px;
  background: rgba(255,255,255,0.2);
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid rgba(255,255,255,0.3);
}
.jc-logo svg { width: 30px; height: 30px; color: white; }

.jc-company-info h2 { font-size: 1.4rem; font-weight: 800; margin-bottom: 4px; }
.jc-company-info p { font-size: 0.82rem; opacity: 0.8; }

.jc-title-box { text-align: right; }
.jc-title-box h3 { font-size: 1.8rem; font-weight: 900; letter-spacing: 3px; opacity: 0.95; }
.jc-title-box p { font-family: var(--font-ur); font-size: 1rem; opacity: 0.8; margin-bottom: 8px; }
.jc-number {
  display: inline-block;
  background: rgba(255,255,255,0.2);
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
  border: 1px solid rgba(255,255,255,0.3);
}

/* JC Body */
.jc-body { padding: 28px 36px; }

.jc-section-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.jc-section { margin-bottom: 24px; }

.jc-info-block {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.jc-block-title {
  padding: 10px 16px;
  background: linear-gradient(135deg, #f0f4ff, #e8eeff);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.jc-block-title svg { width: 14px; height: 14px; }

.jc-table { width: 100%; border-collapse: collapse; }
.jc-table td {
  padding: 9px 16px;
  font-size: 0.85rem;
  border-bottom: 1px solid #f1f5f9;
}
.jc-table td:first-child { color: var(--text-muted); font-weight: 500; width: 45%; }
.jc-table td:last-child { font-weight: 600; color: var(--text); }
.jc-table tr:last-child td { border-bottom: none; }

.jc-spec-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.jc-spec-item {
  padding: 14px;
  background: #f8faff;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.jc-spec-item span { font-size: 0.72rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; }
.jc-spec-item strong { font-size: 1rem; color: var(--primary); font-weight: 700; }

.jc-finishing-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.jc-tag {
  padding: 6px 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}
.jc-tag.none-tag { background: #e2e8f0; color: var(--text-muted); }

/* JC Cost Table */
.jc-cost-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.jc-cost-table th {
  padding: 10px 16px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  font-size: 0.82rem;
  font-weight: 700;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.jc-cost-table th:last-child { text-align: right; }
.jc-cost-table td {
  padding: 9px 16px;
  font-size: 0.85rem;
  border-bottom: 1px solid #f1f5f9;
}
.jc-cost-table td:last-child { text-align: right; font-weight: 600; }
.jc-cost-table tbody tr:hover { background: #f8faff; }

.jc-subtotal-row td { font-weight: 700; color: var(--primary); border-top: 2px solid var(--border); }
.jc-grand-row td {
  font-weight: 800;
  font-size: 1rem;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white !important;
}
.jc-perunit-row td { font-weight: 600; color: var(--success); background: #f0fdf4; }

/* JC Notes */
.jc-notes textarea {
  width: 100%;
  min-height: 80px;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.88rem;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}
.jc-notes textarea:focus { border-color: var(--primary-light); }

/* JC Approval */
.jc-approval {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 24px;
  align-items: center;
  margin-top: 28px;
  padding-top: 24px;
  border-top: 2px dashed var(--border);
}

.jc-sign-box { text-align: center; }
.jc-sign-line {
  height: 2px;
  background: var(--border);
  margin-bottom: 8px;
  border-radius: 1px;
}
.jc-sign-box p { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }

.jc-stamp-box { display: flex; justify-content: center; }
.jc-stamp {
  width: 90px; height: 90px;
  border: 3px solid var(--success);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--success);
  font-weight: 900;
  font-size: 0.85rem;
  letter-spacing: 2px;
  opacity: 0.6;
  transform: rotate(-15deg);
}

/* JC Footer */
.jc-footer {
  background: linear-gradient(135deg, var(--theme-primary), var(--theme-secondary));
  padding: 16px 36px;
  text-align: center;
  color: rgba(255,255,255,0.85);
  font-size: 0.82rem;
}
.jc-footer p:first-child { font-weight: 600; margin-bottom: 2px; }

/* ===== SETTINGS ===== */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.settings-grid .card { margin-bottom: 0; }

.theme-options { display: flex; flex-wrap: wrap; gap: 12px; padding: 20px 22px; }
.theme-opt {
  width: 80px; height: 50px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.78rem;
  font-weight: 700;
  border: 3px solid transparent;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.theme-opt:hover { transform: scale(1.05); }
.theme-opt.active { border-color: white; box-shadow: 0 0 0 3px var(--primary-light); }

/* ===== FOOTER ===== */
.main-footer {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 0.82rem;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

/* ===== PRINT STYLES ===== */
@media print {
  .main-header, .main-footer, .jobcard-actions, .page-title,
  .jc-notes textarea, .nav-btn { display: none !important; }
  body { background: white; }
  .main-content { padding: 0; }
  .tab-panel { display: block !important; }
  #tab-calculator, #tab-settings { display: none !important; }
  .jobcard-wrapper { box-shadow: none; border: none; max-width: 100%; }
  .jc-notes textarea { border: 1px solid #ccc; }
  @page { margin: 15mm; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1100px) {
  .calc-grid { grid-template-columns: 1fr; }
  .results-sticky { position: static; }
}

@media (max-width: 768px) {
  .header-inner { flex-direction: column; height: auto; padding: 12px 0; gap: 12px; }
  .main-header { padding: 12px 16px; }
  .header-nav { flex-wrap: wrap; justify-content: center; }
  .form-grid { grid-template-columns: 1fr; }
  .jc-section-grid { grid-template-columns: 1fr; }
  .jc-spec-grid { grid-template-columns: 1fr 1fr; }
  .jc-approval { grid-template-columns: 1fr; }
  .jc-stamp-box { display: none; }
  .settings-grid { grid-template-columns: 1fr; }
  .main-content { padding: 16px; }
  .jc-header { flex-direction: column; gap: 16px; text-align: center; }
  .jc-title-box { text-align: center; }
  .jc-body { padding: 20px; }
}

/* ===== ANIMATIONS ===== */
.cost-row { transition: background 0.15s; }
.cost-row:hover { background: #f8faff; }

.card { transition: box-shadow 0.2s, transform 0.2s; }

/* Number highlight animation */
@keyframes numPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); color: var(--primary-light); }
  100% { transform: scale(1); }
}
.num-updated { animation: numPop 0.4s ease; }