:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --border: #e5e7eb;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--primary);
  color: white;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}
.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.btn-primary {
  background: white;
  color: var(--primary-dark);
  border: 0;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}
.btn-primary:active { transform: translateY(1px); }

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 56px;
  z-index: 9;
}
.tab {
  flex: 1;
  background: transparent;
  border: 0;
  padding: 10px 8px;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  border-radius: 8px;
}
.tab.active {
  color: var(--primary-dark);
  background: #ecfdf5;
}
.badge {
  display: inline-block;
  min-width: 22px;
  padding: 2px 6px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--border);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
}
.tab.active .badge {
  background: var(--primary);
  color: white;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 12px;
}

.list {
  display: grid;
  gap: 12px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: grid;
  gap: 10px;
}
.card h3 {
  margin: 0;
  font-size: 1.4rem;
  line-height: 1.2;
  word-break: break-word;
}
.card .contact {
  font-size: 1.05rem;
  color: var(--muted);
}
.card .phone-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 1.1rem;
  color: var(--primary-dark);
  text-decoration: none;
  font-weight: 600;
  word-break: break-all;
}
.card .notes {
  background: #f9fafb;
  padding: 10px 12px;
  border-radius: 10px;
  white-space: pre-wrap;
  font-size: 0.95rem;
  max-height: 140px;
  overflow: auto;
}
.card .notes:empty { display: none; }
.card .meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}
.card-actions .call-btn {
  grid-column: 1 / -1;
  font-size: 1.15rem;
  padding: 16px;
  background: var(--ok);
  color: white;
  border: 0;
  border-radius: 12px;
  font-weight: 700;
  text-decoration: none;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.card-actions button {
  padding: 12px;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  background: white;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
}
.card-actions .done-btn { border-color: var(--ok); color: var(--ok); }
.card-actions .fu-btn { border-color: var(--warn); color: var(--warn); }
.card-actions .note-btn { border-color: var(--primary); color: var(--primary-dark); }
.card-actions .reopen-btn { border-color: var(--primary); color: var(--primary-dark); }
.card-actions .edit-btn { color: var(--muted); }
.card-actions .delete-btn { border-color: var(--danger); color: var(--danger); }

.fu-date-chip {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
}
.hidden { display: none !important; }

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}
.modal-card {
  background: var(--card);
  width: 100%;
  max-width: 560px;
  border-radius: 16px 16px 0 0;
  padding: 16px;
  max-height: 92vh;
  overflow-y: auto;
}
@media (min-width: 640px) {
  .modal { align-items: center; padding: 16px; }
  .modal-card { border-radius: 16px; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.modal-head h2 { margin: 0; font-size: 1.2rem; }
.icon-btn {
  background: transparent;
  border: 0;
  font-size: 1.8rem;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 10px;
  line-height: 1;
}

form label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 500;
}
form input, form textarea {
  font: inherit;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
  color: var(--text);
  width: 100%;
}
form input:focus, form textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

.textarea-wrap { position: relative; }
.textarea-wrap textarea { padding-right: 52px; }
.mic-btn {
  position: absolute;
  right: 6px;
  top: 6px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: white;
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mic-btn.recording {
  background: var(--danger);
  color: white;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,0.5); }
  50% { box-shadow: 0 0 0 10px rgba(220,38,38,0); }
}
.mic-status {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 10px;
  min-height: 1.2em;
}

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 500;
  cursor: pointer;
}

.quick-dates {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.quick-dates button {
  background: #ecfdf5;
  color: var(--primary-dark);
  border: 1px solid #a7f3d0;
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
}

/* Mobile tweaks */
@media (max-width: 480px) {
  .topbar h1 { font-size: 1.1rem; }
  .card h3 { font-size: 1.5rem; }
  .card .phone-link { font-size: 1.2rem; }
  .card-actions .call-btn { font-size: 1.25rem; padding: 18px; }
}
