/* CRM Mini App — style.css */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #999999);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --sec: var(--tg-theme-secondary-bg-color, #f0f0f0);
  --danger: #e53935;
  --orange: #fb8c00;
  --green: #43a047;
  --gray: #9e9e9e;
  --radius: 12px;
}

* { 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, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.4;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Header */
#header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--sec);
}
#header-title { font-size: 17px; font-weight: 700; }
.icon-btn {
  background: none; border: none; font-size: 18px;
  min-width: 44px; min-height: 44px; cursor: pointer; color: var(--text);
}

/* Main */
#main {
  flex: 1;
  padding: 12px 12px 88px;
  overflow-x: hidden;
}

/* Tabbar */
#tabbar {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  background: var(--sec);
  border-top: 1px solid var(--hint);
  z-index: 20;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  min-height: 56px;
  text-decoration: none;
  color: var(--hint);
  font-size: 11px;
}
.tab .tab-ico { font-size: 20px; }
.tab.active { color: var(--btn); }

/* FAB */
.fab {
  position: fixed;
  right: max(16px, calc(50% - 240px + 16px));
  bottom: 80px;
  width: 56px; height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--btn);
  color: var(--btn-text);
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
  cursor: pointer;
  z-index: 15;
}

/* Search */
.search-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--hint);
  background: var(--sec);
  color: var(--text);
  font-size: 15px;
  outline: none;
}

/* Filter chips */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 2px 6px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--hint);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  min-height: 36px;
  display: flex; align-items: center; gap: 6px;
}
.chip.active { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }
.chip .badge {
  background: var(--danger); color: #fff;
  border-radius: 10px; padding: 1px 7px; font-size: 11px;
}

/* Cards */
.card {
  background: var(--sec);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}
.card.tappable { cursor: pointer; }
.card .name { font-weight: 700; font-size: 16px; }
.card .person { color: var(--hint); font-size: 13px; }
.card .sub {
  color: var(--hint); font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card .meta {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  margin-top: 6px; font-size: 12px;
}
.card.removing { opacity: 0; transform: translateX(100%); transition: all .3s ease; }

/* Status badges */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
}
.status-active { background: rgba(67,160,71,.2); color: var(--green); }
.status-follow_up { background: rgba(251,140,0,.2); color: var(--orange); }
.status-closed { background: rgba(158,158,158,.25); color: var(--gray); }

.red { color: var(--danger); }
.orange { color: var(--orange); }
.gray { color: var(--hint); }

/* Segment control */
.segments {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.segments::-webkit-scrollbar { display: none; }
.segment {
  flex: 1 0 auto;
  padding: 10px 12px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--hint);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  white-space: nowrap;
}
.segment.active { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }
.segment .badge {
  background: var(--danger); color: #fff;
  border-radius: 10px; padding: 1px 7px; font-size: 11px;
}

/* Contact detail */
.detail-header {
  display: flex; align-items: flex-start; gap: 8px;
}
.detail-header .titles { flex: 1; }
.detail-header h2 { margin: 0; font-size: 20px; }
.section { margin-top: 14px; }
.section h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.row {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--sec);
}
.row:last-child { border-bottom: none; }
.row .date { font-weight: 700; white-space: nowrap; }
.row .desc { color: var(--hint); font-size: 13px; flex: 1; }
.icon-actions { display: flex; gap: 4px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 16px;
  min-height: 44px;
  border-radius: var(--radius);
  border: none;
  background: var(--btn);
  color: var(--btn-text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn.secondary {
  background: var(--sec);
  color: var(--text);
  border: 1px solid var(--hint);
}
.btn.danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; margin-top: 8px; }
.btn-row { display: flex; gap: 8px; margin-top: 8px; }
.btn-row .btn { flex: 1; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 10px; padding-top: 12px; }
.field label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px;
  min-height: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--hint);
  background: var(--sec);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--btn); }
select { appearance: none; }

/* Dashboard */
.counters-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.counter-card {
  background: var(--sec);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
}
.counter-card .num { font-size: 28px; font-weight: 800; line-height: 1.1; }
.counter-card .lbl { font-size: 12px; color: var(--hint); margin-top: 4px; }

/* Empty states / errors */
.empty {
  text-align: center;
  color: var(--hint);
  padding: 40px 16px;
  font-size: 15px;
}
.error-screen {
  text-align: center;
  padding: 60px 20px;
}
.error-screen .big { font-size: 40px; margin-bottom: 12px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 100px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.8);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 100;
  max-width: 90vw;
}
