/* MyCallerID — стили PWA */

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

:root {
  --blue: #007AFF;
  --blue-pressed: #0a66cc;
  --blue-light: #e8f0fe;
  --green: #34C759;
  --red: #FF3B30;
  --orange: #FF9500;
  --gray: #8E8E93;
  --gray-light: #f2f2f7;
  --bg: #ffffff;
  --text: #000000;
  --text-secondary: #6C6C70;
  --border: #C6C6C8;
  --card-bg: #ffffff;
  --surface: rgba(255,255,255,0.92);
  --shadow-soft: 0 8px 30px rgba(0,0,0,0.08);
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --tabbar-height: 64px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--gray-light);
  background: var(--gray-light);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
}

html.modal-open,
body.modal-open {
  overflow: hidden;
}

/* ── Layout ── */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  width: 100%;
  max-width: 768px;
  margin: 0 auto;
  padding-bottom: calc(var(--tabbar-height) + var(--safe-bottom));
}

/* ── Header ── */

.header {
  background: var(--blue);
  color: white;
  padding: 16px 16px 12px;
  padding-top: calc(16px + var(--safe-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.header-icon {
  font-size: 20px;
}

.btn-settings {
  background: none;
  border: none;
  color: white;
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

/* ── Status Bar ── */

.status-bar {
  background: var(--card-bg);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gray);
  flex-shrink: 0;
}

.status-dot.green { background: var(--green); }
.status-dot.red   { background: var(--red); }
.status-dot.orange { background: var(--orange); }

/* ── Content ── */

.content {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tab-view {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tab-view[hidden] {
  display: none !important;
}

/* ── Section ── */

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.btn-refresh-calls {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-secondary);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn-refresh-calls:active {
  opacity: 0.7;
}

.btn-refresh-calls:disabled {
  opacity: 0.6;
  cursor: default;
}

/* ── Call Card ── */

.call-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.swipe-row {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
}

.swipe-actions {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  pointer-events: none;
}

.swipe-action-side {
  width: 36%;
  min-width: 112px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: white;
  opacity: 0;
  transform: scale(0.98);
  transition: opacity 0.14s ease, transform 0.2s ease;
}

.swipe-row.swiping .swipe-action-side,
.swipe-row.show-left-hint .swipe-action-left,
.swipe-row.show-right-hint .swipe-action-right {
  opacity: 1;
  transform: scale(1);
}

.swipe-action-left {
  background: linear-gradient(135deg, #30d158, #34c759);
}

.swipe-action-right {
  background: linear-gradient(135deg, #0a84ff, #007aff);
}

.swipe-card-wrap {
  position: relative;
  z-index: 1;
  transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

.swipe-row.swiping .swipe-card-wrap {
  transition: none !important;
}

.call-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.06);
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: flex-start;
  column-gap: 12px;
  row-gap: 0;
}

.call-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--blue-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  grid-column: 1;
  grid-row: 1;
}

.call-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  grid-column: 2;
  grid-row: 1;
}

.call-header-row {
  display: flex;
  align-items: flex-start;
}

.call-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.call-phone {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.call-lead,
.call-lead-summary {
  font-size: 13px;
  color: var(--blue);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.call-lead-summary {
  color: #2c2c2e;
  font-weight: 500;
}

.call-expanded {
  grid-column: 1 / -1;
  margin-top: 8px;
  border-top: 1px solid rgba(60,60,67,0.12);
  padding-top: 8px;
}

.call-section-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
}

.call-expanded .call-section-label:first-child {
  margin-top: 0;
}

.call-deals {
  margin: 4px 0 0;
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.call-deal-chip-list {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.call-deal-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.call-deal-item {
  font-size: 13px;
  color: var(--text);
  line-height: 1.3;
}

.call-deal-name {
  color: var(--text);
}

.call-deal-stage {
  color: var(--text-secondary);
}

.call-responsible {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.call-amocrm-link {
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--blue);
  text-decoration: none;
}

.call-amocrm-link:active {
  opacity: 0.7;
}

.call-actions {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.call-actions-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  align-items: stretch;
  width: 100%;
}

.call-actions-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  align-items: stretch;
  width: 100%;
}

.call-actions-desktop {
  display: none;
}

.call-mini-btn {
  border: 1px solid rgba(0,122,255,0.22);
  background: rgba(0,122,255,0.08);
  color: var(--blue);
  border-radius: 999px;
  padding: 7px 8px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.15;
  width: 100%;
}

.call-card {
  cursor: pointer;
}

.call-mini-btn:active {
  opacity: 0.75;
}

.call-mini-link {
  text-decoration: none;
}

.call-mini-btn.is-disabled,
.call-mini-btn:disabled {
  opacity: 0.45;
  cursor: default;
  color: var(--text-secondary);
  border-color: rgba(60,60,67,0.14);
  background: rgba(60,60,67,0.06);
}

.call-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  flex-shrink: 0;
  min-width: 78px;
  grid-column: 3;
  grid-row: 1;
}

.call-time {
  font-size: 13px;
  color: var(--text-secondary);
}

.call-date {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.call-meta-responsible {
  margin-top: auto;
  padding-top: 10px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  max-width: 92px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.call-price {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-top: 2px;
}

.call-notes-block {
  margin-top: 8px;
}

.call-notes-list {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.call-note-item {
  border-radius: 12px;
  background: rgba(142,142,147,0.08);
  padding: 8px 10px;
}

.call-note-text {
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.call-note-meta {
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--text-secondary);
}

.call-note-pill {
  border-radius: 999px;
  background: rgba(142,142,147,0.12);
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
}

.call-note-pill.ok {
  background: rgba(52,199,89,0.14);
  color: #1f8f47;
}

.call-note-pill.error {
  background: rgba(255,59,48,0.14);
  color: #cc2f27;
}

.call-note-empty {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── Empty State ── */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state .emoji {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 15px;
}

/* ── Reminders ── */

.reminder-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reminder-block + .reminder-block {
  margin-top: 8px;
}

.reminder-block-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 0 2px;
}

.reminder-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reminder-card {
  background: rgba(255,255,255,0.96);
  border-radius: 16px;
  border: 1px solid rgba(60,60,67,0.1);
  box-shadow: 0 4px 16px rgba(0,0,0,0.05);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reminder-card.completed {
  opacity: 0.52;
  filter: saturate(0.7);
}

.reminder-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.reminder-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.reminder-sub {
  font-size: 13px;
  color: var(--text-secondary);
}

.reminder-time {
  font-size: 12px;
  font-weight: 700;
  color: var(--blue);
  white-space: nowrap;
}

.reminder-time.overdue {
  color: var(--red);
}

.reminder-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.reminder-pill {
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--gray-light);
  color: var(--text-secondary);
}

.reminder-pill.ok {
  background: rgba(52,199,89,0.12);
  color: #1f8f47;
}

.reminder-pill.error {
  background: rgba(255,59,48,0.12);
  color: #cc2f27;
}

.reminder-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.reminder-btn {
  border: 1px solid var(--border);
  background: white;
  color: var(--text-secondary);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.reminder-btn.primary {
  border-color: rgba(0,122,255,0.22);
  background: rgba(0,122,255,0.08);
  color: var(--blue);
}

/* ── Buttons ── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 12px;
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  width: 100%;
}

.btn:active {
  opacity: 0.7;
}

.btn-primary {
  background: var(--blue);
  color: white;
}

.btn-secondary {
  background: var(--gray-light);
  color: var(--blue);
}

.btn-danger {
  background: #fff0f0;
  color: var(--red);
}

/* ── Settings Panel ── */

.panel {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--gray-light);
  z-index: 100;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  padding-bottom: var(--safe-bottom);
}

.panel.open {
  transform: translateX(0);
}

.panel-header {
  background: var(--blue);
  color: white;
  padding: 16px;
  padding-top: calc(16px + var(--safe-top));
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
}

.panel-back {
  background: none;
  border: none;
  color: white;
  font-size: 16px;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.panel-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.panel-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Settings Group ── */

.settings-group {
  background: var(--card-bg);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.settings-group-title {
  font-size: 13px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  padding: 8px 16px 4px;
}

.settings-row {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-row:first-of-type {
  border-top: none;
}

.settings-row-stack {
  align-items: stretch;
  justify-content: flex-start;
}

.settings-label {
  font-size: 15px;
  font-weight: 500;
}

.settings-value {
  font-size: 14px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.diag-result {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f6f7fb;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.35;
  padding: 10px 12px;
  white-space: pre-line;
  word-break: break-word;
}

.diag-result.ok {
  background: #eefaf2;
  border-color: #c6e9d1;
  color: #1d6f38;
}

.diag-result.error {
  background: #fff3f3;
  border-color: #f2d0d0;
  color: #a43a3a;
}

/* ── Login Page ── */

.login-page {
  min-height: 100vh;
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--gray-light);
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.login-logo {
  font-size: 56px;
  margin-bottom: 8px;
}

.login-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

.login-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 40px;
}

.login-form {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-input {
  padding: 14px 16px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: white;
  font-size: 16px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.form-input:focus {
  border-color: var(--blue);
}

.login-error {
  background: #fff0f0;
  color: var(--red);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
  display: none;
}

.login-error.show {
  display: block;
}

/* ── Toast ── */

.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom) + var(--tabbar-height));
  left: 16px;
  right: 16px;
  background: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 200;
  text-align: center;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ── Loading ── */

.loading {
  text-align: center;
  padding: 32px;
  color: var(--text-secondary);
  font-size: 15px;
}

/* ── iOS-like Bottom Tab Bar ── */

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  width: min(100%, 768px);
  bottom: 0;
  height: calc(var(--tabbar-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  align-items: stretch;
  background: rgba(248,248,248,0.94);
  border-top: 1px solid rgba(60,60,67,0.18);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  z-index: 40;
}

.panel {
  width: min(100%, 768px);
  left: 50%;
  right: auto;
  transform: translateX(100%);
}

.panel.open {
  transform: translateX(-50%);
}

.tabbar-item {
  flex: 1;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--gray);
  cursor: pointer;
  padding: 6px 8px 4px;
}

.tabbar-item.active {
  color: var(--blue);
}

.tabbar-icon {
  font-size: 18px;
  line-height: 1;
}

.tabbar-label {
  font-size: 10px;
  font-weight: 600;
  line-height: 1.2;
}

/* ── Overlay / Sheet / Dialog ── */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  overscroll-behavior: contain;
}

.overlay[hidden] {
  display: none !important;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  transition: opacity 220ms ease;
}

.sheet {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--safe-bottom));
  background: rgba(248,248,248,0.96);
  border-radius: 18px;
  box-shadow: var(--shadow-soft);
  padding: 8px 10px 10px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  margin: 2px auto 10px;
  background: rgba(60,60,67,0.25);
}

.sheet-handle,
.sheet-title,
.sheet-subtitle,
.dialog-handle,
.dialog-title,
.dialog-subtitle {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.sheet-title {
  font-size: 16px;
  font-weight: 700;
  text-align: center;
}

.sheet-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 4px;
  margin-bottom: 10px;
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet-action,
.sheet-cancel {
  width: 100%;
  border: none;
  border-radius: 14px;
  background: white;
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 600;
  color: var(--blue);
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.sheet-cancel {
  margin-top: 10px;
}

.dialog {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.98);
  border-radius: 18px;
  box-shadow: var(--shadow-soft);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.dialog-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  margin: -2px auto 2px;
  background: rgba(60,60,67,0.25);
}

.dialog-title {
  font-size: 17px;
  font-weight: 700;
  text-align: center;
}

.dialog-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

.dialog-input {
  width: 100%;
}

.dialog-textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  color: var(--text);
  resize: vertical;
  min-height: 110px;
}

.dialog-note-history {
  border: 1px solid rgba(60,60,67,0.12);
  border-radius: 12px;
  background: rgba(142,142,147,0.04);
  padding: 8px;
  max-height: 220px;
  overflow: auto;
}

.dialog-note-history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dialog-note-history-empty {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 18px 8px;
}

.dialog-textarea:focus {
  outline: none;
  border-color: var(--blue);
}

.dialog-actions {
  display: flex;
  gap: 8px;
}

.dialog-btn {
  width: auto;
  flex: 1;
  padding: 12px 14px;
}

@media (hover: hover) and (pointer: fine), (min-width: 769px) {
  .call-actions-desktop {
    display: grid;
  }
}

@media (prefers-reduced-motion: reduce) {
  .swipe-card-wrap,
  .toast,
  .panel,
  .sheet,
  .dialog,
  .sheet-backdrop {
    transition: none;
  }
}
