*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green:   #25D366;
  --green-d: #1da851;
  --blue:    #3b82f6;
  --blue-d:  #2563eb;
  --red:     #ef4444;
  --gray-50: #f9fafb;
  --gray-100:#f3f4f6;
  --gray-200:#e5e7eb;
  --gray-400:#9ca3af;
  --gray-600:#4b5563;
  --gray-800:#1f2937;
  --sidebar: 220px;
  --radius:  8px;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: var(--gray-800); background: var(--gray-50); }

/* ── Login ─────────────────────────────────────────────── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: white; border-radius: var(--radius); box-shadow: 0 4px 24px rgba(0,0,0,.08); padding: 2.5rem; width: 100%; max-width: 360px; text-align: center; }
.login-logo { display: flex; flex-direction: column; align-items: center; gap: .5rem; margin-bottom: 2rem; }
.login-logo h1 { font-size: 1.4rem; font-weight: 700; }
.login-logo p { color: var(--gray-600); font-size: .875rem; }
.btn-google { display: flex; align-items: center; justify-content: center; gap: .75rem; width: 100%; padding: .75rem 1rem; border: 1px solid var(--gray-200); border-radius: var(--radius); background: white; color: var(--gray-800); font-size: .9rem; font-weight: 500; text-decoration: none; transition: background .15s; cursor: pointer; }
.btn-google:hover { background: var(--gray-50); }
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .875rem; }
.alert-error   { background: #fee2e2; color: #991b1b; }
.alert-success { background: #d1fae5; color: #065f46; }

/* ── App layout ─────────────────────────────────────────── */
.app-page { display: flex; min-height: 100vh; }

.sidebar { width: var(--sidebar); background: #111827; color: white; display: flex; flex-direction: column; flex-shrink: 0; position: fixed; top: 0; left: 0; height: 100vh; }
.sidebar-logo { display: flex; align-items: center; gap: .6rem; padding: 1.25rem 1rem; font-weight: 700; font-size: 1rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-nav { flex: 1; padding: .75rem 0; }
.nav-item { display: flex; align-items: center; gap: .65rem; padding: .65rem 1rem; color: rgba(255,255,255,.65); text-decoration: none; border-left: 3px solid transparent; transition: all .15s; font-size: .875rem; }
.nav-item:hover { color: white; background: rgba(255,255,255,.06); }
.nav-item.active { color: white; background: rgba(37,211,102,.12); border-left-color: var(--green); }
.sidebar-user { padding: 1rem; border-top: 1px solid rgba(255,255,255,.08); font-size: .8rem; color: rgba(255,255,255,.5); }
.sidebar-user span { display: block; margin-bottom: .25rem; font-weight: 500; color: rgba(255,255,255,.8); }
.logout-link { color: rgba(255,255,255,.4); text-decoration: none; }
.logout-link:hover { color: white; }

.main-content { margin-left: var(--sidebar); flex: 1; padding: 2rem; max-width: 960px; }

/* ── Sections ───────────────────────────────────────────── */
.section { display: none; }
.section.active { display: block; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.section-header h2 { font-size: 1.25rem; font-weight: 700; }

/* ── Cards ──────────────────────────────────────────────── */
.card { background: white; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.card-list { display: flex; flex-direction: column; gap: .75rem; }
.reminder-card { background: white; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 1rem 1.25rem; display: flex; align-items: center; gap: 1rem; }
.reminder-card.inactive { opacity: .55; }
.reminder-card-info { flex: 1; min-width: 0; }
.reminder-card-title { font-weight: 600; margin-bottom: .25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reminder-card-meta { color: var(--gray-600); font-size: .8rem; display: flex; gap: .75rem; flex-wrap: wrap; }
.reminder-card-actions { display: flex; gap: .5rem; flex-shrink: 0; }

.badge { display: inline-block; padding: .2rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 500; }
.badge-green { background: #d1fae5; color: #065f46; }
.badge-gray  { background: var(--gray-100); color: var(--gray-600); }
.badge-blue  { background: #dbeafe; color: #1d4ed8; }
.badge-red   { background: #fee2e2; color: #991b1b; }

/* ── Log table ──────────────────────────────────────────── */
.log-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.log-table th { text-align: left; padding: .75rem 1rem; background: var(--gray-50); color: var(--gray-600); font-weight: 600; border-bottom: 1px solid var(--gray-200); }
.log-table td { padding: .65rem 1rem; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.log-table tr:last-child td { border-bottom: none; }
.log-table tr:hover td { background: var(--gray-50); }
.log-contact, .log-detail { font-size: 12px; color: var(--gray-500); }
.log-empty { text-align: center; padding: 2rem; color: var(--gray-400); }

/* ── Log filter bar ─────────────────────────────────────── */
.logs-filter-bar { padding: .85rem 1rem; margin-bottom: .75rem; }
.logs-filter-row { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; }
.logs-custom-wrap { display: flex; align-items: flex-end; gap: .75rem; flex-wrap: wrap; }

/* ── Log pagination ─────────────────────────────────────── */
.logs-pagination { display: flex; align-items: center; justify-content: center; gap: 1rem; padding: .85rem 1rem; border-top: 1px solid var(--gray-100); }
.logs-pag-info { font-size: .8rem; color: var(--gray-600); }

/* ── Buttons ────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem 1rem; border-radius: var(--radius); border: 1px solid transparent; font-size: .875rem; font-weight: 500; cursor: pointer; transition: all .15s; }
.btn-primary { background: var(--green); color: white; border-color: var(--green); }
.btn-primary:hover { background: var(--green-d); border-color: var(--green-d); }
.btn-secondary { background: white; color: var(--gray-800); border-color: var(--gray-200); }
.btn-secondary:hover { background: var(--gray-50); }
.btn-danger { background: var(--red); color: white; border-color: var(--red); }
.btn-danger:hover { background: #dc2626; }
.btn-ghost { background: none; border: none; color: var(--gray-600); padding: .3rem .5rem; }
.btn-ghost:hover { color: var(--gray-800); }
.btn-sm { padding: .35rem .65rem; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Forms ──────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: .4rem; font-size: .875rem; }
input[type=text], input[type=number], input[type=email], input[type=time], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: .55rem .75rem; border: 1px solid var(--gray-200); border-radius: var(--radius);
  font-size: .875rem; font-family: inherit; color: var(--gray-800); background: white; transition: border .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(37,211,102,.1); }
textarea { resize: vertical; }
.input-row { display: flex; gap: .5rem; }
.input-row input { flex: 1; }
.checkbox-label { display: flex; align-items: center; gap: .5rem; cursor: pointer; font-weight: 500; }
.checkbox-label input { width: auto; }
.hint { color: var(--gray-600); font-size: .8rem; margin-top: .3rem; }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--gray-100); }

.days-grid { display: flex; gap: .4rem; flex-wrap: wrap; }
.day-btn { padding: .35rem .65rem; border: 1px solid var(--gray-200); border-radius: var(--radius); background: white; cursor: pointer; font-size: .8rem; transition: all .15s; }
.day-btn.selected { background: var(--green); color: white; border-color: var(--green); }

/* ── Modals ─────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.modal-box { position: relative; background: white; border-radius: var(--radius); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal-box-wide { max-width: 680px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--gray-100); position: sticky; top: 0; background: white; z-index: 1; }
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--gray-400); line-height: 1; padding: 0; }
.modal-box:not(.modal-contacts-box) form,
.modal-box:not(.modal-contacts-box) > div:not(.modal-header) { padding: 1.25rem 1.5rem; }
.rules-hint { padding: .75rem 1.5rem; background: #fffbeb; border-bottom: 1px solid #fde68a; font-size: .8rem; color: #92400e; }

/* ── Rules list ─────────────────────────────────────────── */
.rule-item { display: flex; align-items: flex-start; gap: .75rem; padding: .75rem; border: 1px solid var(--gray-200); border-radius: var(--radius); margin-bottom: .5rem; background: white; }
.rule-item.inactive { opacity: .55; }
.rule-item-info { flex: 1; }
.rule-item-name { font-weight: 600; font-size: .875rem; }
.rule-item-cond { color: var(--gray-600); font-size: .8rem; margin-top: .2rem; }
.rule-item-msg { color: var(--gray-800); font-size: .8rem; margin-top: .3rem; background: var(--gray-50); padding: .4rem .6rem; border-radius: 4px; }
.rule-item-actions { display: flex; gap: .25rem; }

/* ── WhatsApp ───────────────────────────────────────────── */
.wa-status { display: flex; align-items: center; gap: .75rem; padding: .75rem 0; }
.wa-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.wa-dot.connected { background: var(--green); box-shadow: 0 0 0 3px rgba(37,211,102,.2); }
.wa-dot.disconnected { background: var(--gray-400); }
.wa-dot.initializing { background: #f59e0b; animation: pulse 1s infinite; }
.wa-dot.qr_ready { background: #3b82f6; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity:1 } 50% { opacity:.4 } }

/* ── Misc ───────────────────────────────────────────────── */
.code-block { background: var(--gray-800); color: #a5f3fc; padding: 1rem; border-radius: var(--radius); font-size: .8rem; line-height: 1.7; overflow-x: auto; white-space: pre; }
.loading { color: var(--gray-400); padding: 2rem; text-align: center; }
.empty-state { color: var(--gray-400); padding: 3rem; text-align: center; }
.empty-state p { font-size: .875rem; }

.user-row { display: flex; align-items: center; gap: 1rem; padding: .75rem 1rem; border: 1px solid var(--gray-200); border-radius: var(--radius); background: white; margin-bottom: .5rem; }
.user-row-info { flex: 1; }
.user-row-name { font-weight: 500; }
.user-row-email { color: var(--gray-600); font-size: .8rem; }

.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: var(--gray-800); color: white; padding: .65rem 1.25rem; border-radius: var(--radius); font-size: .875rem; z-index: 200; }
.toast.success { background: #065f46; }
.toast.error { background: #991b1b; }

/* ── Contacts modal ─────────────────────────────────────── */
.modal-contacts-box { max-width: 440px; display: flex; flex-direction: column; overflow: hidden; }

.contacts-search-wrap { position: relative; padding: .75rem 1.25rem; border-bottom: 1px solid var(--gray-100); flex-shrink: 0; }
.contacts-search-wrap input { padding-left: 2.25rem; width: 100%; }
.contacts-search-wrap input::-webkit-search-cancel-button { display: none; }
.contacts-search-icon { position: absolute; left: 1.9rem; top: 50%; transform: translateY(-50%); color: var(--gray-400); pointer-events: none; }

.contacts-list { flex: 1; overflow-y: auto; max-height: 240px; min-height: 60px; }
.contact-item { display: flex; align-items: center; gap: .75rem; padding: .6rem 1.25rem; cursor: pointer; transition: background .12s; user-select: none; }
.contact-item:hover { background: var(--gray-50); }
.contact-item.is-selected { background: #f0fdf4; }
.contact-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--gray-200); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: .75rem; color: var(--gray-600); flex-shrink: 0; transition: background .12s; }
.contact-avatar.is-group { background: #dbeafe; color: #1d4ed8; }
.contact-item.is-selected .contact-avatar { background: #d1fae5; color: #065f46; }
.contact-info { flex: 1; min-width: 0; }
.contact-name { font-weight: 500; font-size: .875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-type { font-size: .72rem; color: var(--gray-400); margin-top: 1px; }
.contact-check { color: var(--green); flex-shrink: 0; opacity: 0; transition: opacity .12s; }
.contact-item.is-selected .contact-check { opacity: 1; }

.contacts-email-section { border-top: 1px solid var(--gray-100); padding: .85rem 1.25rem; background: var(--gray-50); flex-shrink: 0; }
.contacts-email-label { display: flex; align-items: center; gap: .4rem; font-size: .7rem; font-weight: 600; color: var(--gray-400); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .6rem; }
.contacts-email-row { display: flex; gap: .5rem; }
.contacts-email-row input { flex: 1; min-width: 0; }
.contacts-email-row input:nth-child(2) { max-width: 130px; }

.contacts-footer { display: flex; align-items: center; justify-content: space-between; padding: .85rem 1.25rem; border-top: 1px solid var(--gray-100); flex-shrink: 0; }
.contacts-count { font-size: .8rem; color: var(--gray-600); font-weight: 500; }
