/* ============================================================================
   iPhone PWA CRM — «НАШЕ АГЕНТСТВО» (Black & Gold Luxury iOS Theme)
   ============================================================================ */

:root {
  --bg: #07090E;
  --surface: #111622;
  --elevated: #171E2E;
  --border: #2B3447;
  --gold: #F4C453;
  --gold-light: #FFE8A3;
  --gold-dark: #C7861B;
  --gold-soft: rgba(244, 196, 83, 0.14);
  --text: #F6F3EC;
  --text-sec: #C6BFB2;
  --text-muted: #8E887C;
  --green: #34D399;
  --blue: #60A5FA;
  --amber: #FBBF24;
  --coral: #FF6B6B;
  --purple: #C084FC;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: none;
  min-height: 100dvh;
}

.hidden { display: none !important; }

/* ---- Top App Bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: rgba(7, 9, 14, 0.88);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(244, 196, 83, 0.14);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.topbar-title-wrap {
  min-width: 0;
}

.topbar-brand {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 700;
}

.topbar-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--gold-light);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  cursor: pointer;
}

.icon-btn:active { transform: scale(0.94); }

.icon-btn.primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  color: #130E04;
  border-color: transparent;
  font-weight: 700;
}

/* ---- Main Content ---- */
.main-content {
  padding: 14px 14px calc(92px + var(--safe-bottom));
  max-width: 680px;
  margin: 0 auto;
}

/* ---- Install Banner (Safari -> Home Screen) ---- */
.ios-install-banner {
  background: linear-gradient(135deg, rgba(244, 196, 83, 0.16), rgba(17, 22, 34, 0.96));
  border: 1px solid rgba(244, 196, 83, 0.4);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.ios-install-banner strong {
  color: var(--gold-light);
  display: block;
  margin-bottom: 3px;
}

.ios-install-banner p {
  margin: 0;
  font-size: 13px;
  color: var(--text-sec);
}

/* ---- Cards & Funnel ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.card-gold {
  background: linear-gradient(150deg, #1A160C 0%, #111622 65%);
  border-color: rgba(244, 196, 83, 0.35);
}

.funnel-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.funnel-box {
  background: rgba(7, 9, 14, 0.55);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 6px;
  text-align: center;
}

.funnel-num {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
}

.funnel-lbl {
  font-size: 11px;
  color: var(--text-sec);
  margin-top: 2px;
}

/* ---- Inputs & Chips ---- */
.input, .textarea, .select {
  width: 100%;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 11px 13px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
}

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

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

.chips-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 10px;
  scrollbar-width: none;
}
.chips-row::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-sec);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.chip.active {
  background: var(--gold-soft);
  border-color: var(--gold);
  color: var(--gold-light);
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--elevated);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}

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

.btn-gold {
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  color: #130E04;
  border-color: transparent;
  font-weight: 700;
}

.btn-soft-gold {
  background: var(--gold-soft);
  border-color: rgba(244, 196, 83, 0.4);
  color: var(--gold-light);
}

.btn-danger {
  background: rgba(255, 107, 107, 0.14);
  border-color: rgba(255, 107, 107, 0.4);
  color: #FF9494;
}

.btn-sm {
  padding: 7px 10px;
  font-size: 13px;
  border-radius: 10px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

/* ---- Client Card ---- */
.client-card {
  cursor: pointer;
  transition: border-color 0.15s;
}

.client-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.client-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.client-meta {
  font-size: 13px;
  color: var(--text-sec);
  margin-top: 2px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  background: var(--elevated);
  color: var(--text-sec);
  border: 1px solid var(--border);
}

.badge-warn {
  background: rgba(255, 107, 107, 0.16);
  border-color: rgba(255, 107, 107, 0.5);
  color: #FF8B8B;
}

.badge-ok {
  background: rgba(52, 211, 153, 0.14);
  border-color: rgba(52, 211, 153, 0.4);
  color: var(--green);
}

.client-req {
  font-size: 13px;
  color: var(--text-sec);
  margin: 8px 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.progress-bar {
  height: 6px;
  background: var(--elevated);
  border-radius: 99px;
  overflow: hidden;
  margin: 8px 0;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold-dark), var(--gold));
  border-radius: 99px;
}

/* ---- Mortgage Calculator ---- */
.calc-result-big {
  font-size: 30px;
  font-weight: 800;
  color: var(--gold-light);
  letter-spacing: -0.02em;
}

.calc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(43, 52, 71, 0.5);
  font-size: 14px;
}

.calc-row:last-child { border-bottom: none; }

.range-wrap {
  margin: 12px 0;
}

.range-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-sec);
  margin-bottom: 6px;
}

.range-head strong {
  color: var(--gold-light);
  font-size: 15px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--gold);
  height: 6px;
}

/* ---- Bottom Navigation (iOS Tab Bar) ---- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: rgba(11, 14, 22, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(244, 196, 83, 0.16);
  padding: 8px 6px calc(8px + var(--safe-bottom));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  position: relative;
}

.tab-btn .tab-ico {
  font-size: 20px;
  line-height: 1;
}

.tab-btn.active {
  color: var(--gold);
}

.tab-badge {
  position: absolute;
  top: 0;
  right: calc(50% - 20px);
  background: var(--coral);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  min-width: 17px;
  height: 17px;
  border-radius: 99px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ---- Bottom Sheet Modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-sheet {
  width: 100%;
  max-width: 680px;
  max-height: 92dvh;
  background: var(--bg);
  border-top: 1px solid rgba(244, 196, 83, 0.35);
  border-radius: 22px 22px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-header h3 {
  margin: 0;
  font-size: 17px;
  color: var(--gold-light);
}

.modal-body {
  padding: 14px 16px calc(24px + var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sec);
  margin: 10px 0 5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.checklist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  background: var(--elevated);
  border-radius: 10px;
  margin-bottom: 6px;
  font-size: 14px;
  cursor: pointer;
}

.checklist-item input {
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
}

.history-item {
  border-left: 2px solid var(--gold-dark);
  padding: 4px 0 4px 10px;
  margin-bottom: 8px;
  font-size: 13px;
}

.history-time {
  font-size: 11px;
  color: var(--text-muted);
}

/* ---- PIN Lock Screen ---- */
.pin-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.pin-dots {
  display: flex;
  gap: 14px;
  margin: 20px 0 28px;
}

.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: transparent;
}

.pin-dot.filled {
  background: var(--gold);
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  gap: 14px;
}

.pin-key {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 24px;
  font-weight: 600;
  cursor: pointer;
}

.pin-key:active {
  background: var(--gold-soft);
  border-color: var(--gold);
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(82px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 90;
  background: var(--gold);
  color: #130E04;
  font-weight: 700;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  max-width: 90vw;
  text-align: center;
}

/* ---- Print / PDF Export (Black & Gold Calculation Sheet) ---- */
#pdfPrintArea { display: none; }

@media print {
  body { background: #07090E !important; color: #F6F3EC !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .topbar, .main-content, .tabbar, .modal-backdrop, .toast, .pin-overlay { display: none !important; }
  #pdfPrintArea {
    display: block !important;
    padding: 28px;
    background: #07090E;
    color: #F6F3EC;
    min-height: 100vh;
  }
}
