:root {
  --bg: #0f172a;
  --bg-elevated: #1e293b;
  --bg-elevated-2: #263449;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-dark: #0284c7;
  --danger: #f87171;
  --warning: #fbbf24;
  --success: #4ade80;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app { min-height: 100vh; }

.screen { min-height: 100vh; }
.screen[hidden], [hidden] { display: none !important; }

.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
.error-text { color: var(--danger); font-size: 0.9rem; }

/* ---------------------------- Login ---------------------------- */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
}
.login-card h1 { margin: 0 0 4px; font-size: 1.4rem; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--text-muted); }

input, textarea, select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  width: 100%;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
input[type="date"], input[type="time"] { min-height: 46px; }

button { cursor: pointer; font-family: inherit; border: none; }

#login-submit, .send-btn {
  background: var(--accent);
  color: #01202e;
  font-weight: 600;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 1rem;
}
#login-submit:active, .send-btn:active { background: var(--accent-dark); }

.secondary-btn {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px dashed var(--border);
  color: var(--text-muted);
  padding: 12px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  margin-bottom: 18px;
}
.secondary-btn:active { border-color: var(--accent); color: var(--accent); }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.95rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.85rem;
  padding: 0 0 10px;
}

/* ---------------------------- Top bar ---------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  position: sticky;
  top: 0;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.topbar h1 { font-size: 1.15rem; margin: 0; }
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn.active { border-color: var(--accent); }

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 14px 90px;
}

/* ---------------------------- Captura ---------------------------- */
.capture-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.capture-card textarea { resize: vertical; min-height: 64px; }
.capture-actions { display: flex; gap: 10px; margin-top: 10px; }
.mic-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.mic-btn.recording {
  background: var(--danger);
  border-color: var(--danger);
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(248,113,113,0.5); }
  70% { box-shadow: 0 0 0 12px rgba(248,113,113,0); }
  100% { box-shadow: 0 0 0 0 rgba(248,113,113,0); }
}
.send-btn { flex: 1; }
.send-btn:disabled { opacity: 0.6; cursor: default; }

/* ---------------------------- Formulário ---------------------------- */
.form-card {
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.form-title { margin: 0; font-size: 1.05rem; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--text-muted); }
.form-row { display: flex; gap: 12px; }
.form-row .field { flex: 1; min-width: 0; }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.form-actions .ghost-btn { flex: 0 0 auto; }
.form-actions .send-btn { flex: 1; }

/* ---------------------------- Alternador de visão ---------------------------- */
.view-switch {
  display: flex;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 16px;
}
.view-btn {
  flex: 1;
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  padding: 9px 12px;
  font-size: 0.9rem;
}
.view-btn.active { background: var(--accent); color: #01202e; font-weight: 600; }

/* ---------------------------- Tabs ---------------------------- */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; overflow-x: auto; }
.tab {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.88rem;
  white-space: nowrap;
}
.tab.active { color: #01202e; background: var(--accent); border-color: var(--accent); font-weight: 600; }

/* ---------------------------- Calendário ---------------------------- */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.cal-header h2 { font-size: 1.05rem; margin: 0; text-transform: capitalize; }

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 6px;
}
.cal-weekdays span {
  text-align: center;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 20px;
}
.cal-day {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.cal-day.empty { background: transparent; border-color: transparent; cursor: default; }
.cal-day.today { border-color: var(--accent); font-weight: 700; color: var(--accent); }
.cal-day.selected { background: var(--accent); color: #01202e; font-weight: 700; border-color: var(--accent); }
.cal-day .dots {
  position: absolute;
  bottom: 5px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 3px;
}
.cal-day .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--text-muted); }
.cal-day .dot.high { background: var(--danger); }
.cal-day.selected .dot { background: #01202e; }

/* ---------------------------- Agenda list ---------------------------- */
.agenda-list { display: flex; flex-direction: column; gap: 18px; }

.day-group-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 4px 0 -6px 4px;
}

.entry-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.entry-card.overdue { border-color: var(--danger); }
.entry-card.done { opacity: 0.6; }

.entry-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.entry-time {
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 600;
  margin: 0 0 3px;
}
.entry-topic { font-weight: 600; font-size: 1.02rem; margin: 0; }
.entry-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

.badge {
  font-size: 0.72rem;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-elevated-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge.priority-alta, .badge.priority-urgente { color: var(--danger); border-color: var(--danger); }
.badge.priority-baixa { color: var(--text-muted); }

.entry-notes { font-size: 0.88rem; color: var(--text-muted); margin: 8px 0 0; }

.action-plan { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.action-plan li { display: flex; align-items: center; gap: 8px; font-size: 0.92rem; cursor: pointer; }
.action-plan li.done { text-decoration: line-through; color: var(--text-muted); }
.action-plan input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }

.reminders-list { margin: 10px 0 0; display: flex; flex-direction: column; gap: 4px; }
.reminder-chip { font-size: 0.8rem; color: var(--warning); display: flex; align-items: center; gap: 6px; }
.reminder-chip.sent { color: var(--text-muted); }

.entry-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.entry-footer button {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.82rem;
  padding: 6px 12px;
  border-radius: 8px;
}
.entry-footer button.complete-btn.is-done { color: var(--success); border-color: var(--success); }
.entry-footer button.delete-btn:active { color: var(--danger); border-color: var(--danger); }

/* ---------------------------- Toast ---------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  z-index: 50;
  max-width: 90vw;
}
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ===========================================================================
   v3 — cadastros, modais, anotações e relatórios
   =========================================================================== */

.mic-inline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  align-self: flex-start;
}
.mic-inline.recording { border-color: var(--danger); color: var(--danger); }

/* ------------------------------- Modais ------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.75);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal[hidden] { display: none !important; }

.modal-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}
@media (min-width: 700px) {
  .modal { align-items: center; padding: 20px; }
  .modal-box { border-radius: 18px; max-height: 88vh; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  border-radius: 18px 18px 0 0;
}
.modal-head h2 { margin: 0; font-size: 1.05rem; }

.modal-body {
  padding: 16px 18px 28px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 10px 0 0;
}

.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }
.inline-form button { flex: 0 0 auto; padding: 10px 14px; font-size: 0.9rem; }

/* ------------------------------- Mini listas ------------------------------- */
.mini-list { display: flex; flex-direction: column; gap: 6px; }
.mini-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.92rem;
}
.mini-row .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.mini-row button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 4px 6px;
}
.mini-row button.danger:active { color: var(--danger); }
.mini-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.mini-empty { color: var(--text-muted); font-size: 0.85rem; padding: 4px 2px; }

/* ------------------------------- Anotações ------------------------------- */
.notes-history { display: flex; flex-direction: column; gap: 10px; }
.note-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.note-item .note-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.note-item .note-body { font-size: 0.92rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.note-item textarea { margin-top: 6px; }
.note-actions { display: flex; gap: 6px; }
.note-actions button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 2px 4px;
}

/* ------------------------------- Extras nos cards ------------------------------- */
.badge.company { color: var(--accent); border-color: var(--accent); }
.notes-count { font-size: 0.8rem; color: var(--text-muted); margin: 10px 0 0; }

/* ------------------------------- Relatório ------------------------------- */
.report-group-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 12px 0 -4px;
}
.report-entry {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.report-entry h4 { margin: 0 0 4px; font-size: 0.98rem; }
.report-entry .meta { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 8px; }
.report-note {
  border-left: 2px solid var(--border);
  padding-left: 10px;
  margin: 8px 0 0;
  font-size: 0.88rem;
  white-space: pre-wrap;
}
.report-note .when { color: var(--text-muted); font-size: 0.75rem; display: block; }

/* ------------------------------- Impressão ------------------------------- */
#print-area { display: none; }

@media print {
  body { background: #fff; color: #000; }
  #app { display: none !important; }
  #print-area {
    display: block;
    padding: 0;
    color: #000;
    font-size: 12pt;
  }
  #print-area h1 { font-size: 17pt; margin: 0 0 4px; }
  #print-area .print-sub { font-size: 10pt; color: #444; margin: 0 0 18px; }
  #print-area h2 {
    font-size: 13pt;
    margin: 18px 0 6px;
    border-bottom: 1px solid #999;
    padding-bottom: 3px;
  }
  #print-area .p-entry { margin: 0 0 12px; page-break-inside: avoid; }
  #print-area .p-entry h3 { font-size: 11.5pt; margin: 0 0 2px; }
  #print-area .p-meta { font-size: 9.5pt; color: #555; margin: 0 0 4px; }
  #print-area .p-note { margin: 4px 0 4px 14px; font-size: 10.5pt; white-space: pre-wrap; }
  #print-area .p-note .when { color: #555; font-size: 9pt; }
  #print-area .p-empty { font-style: italic; color: #666; font-size: 10pt; }
}

/* ===========================================================================
   v4 — busca, anexos, período, recorrência e ajustes de layout
   =========================================================================== */

/* Alternador de visão fixo abaixo do cabeçalho */
.view-switch {
  position: sticky;
  top: 68px;
  z-index: 9;
  max-width: 640px;
  margin: 0 auto 4px;
  width: calc(100% - 28px);
}

main { padding-top: 12px; }

.hint { color: var(--text-muted); font-weight: 400; opacity: 0.8; }

/* ------------------------------- Busca ------------------------------- */
.search-bar {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 14px;
}
.search-bar .search-icon {
  position: absolute;
  left: 14px;
  font-size: 0.95rem;
  pointer-events: none;
  opacity: 0.7;
}
.search-bar input {
  padding-left: 40px;
  padding-right: 40px;
  border-radius: 999px;
}
.search-clear {
  position: absolute;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.95rem;
  padding: 6px;
}

/* ------------------------------- Cards ------------------------------- */
.entry-card {
  border-left: 3px solid var(--border);
  transition: border-color 0.15s ease;
}
.entry-card.priority-alta,
.entry-card.priority-urgente { border-left-color: var(--danger); }
.entry-card.has-time { border-left-color: var(--accent); }
.entry-card.done { border-left-color: var(--success); }

.entry-range {
  font-size: 0.8rem;
  color: var(--warning);
  font-weight: 600;
  margin: 0 0 3px;
}
.entry-recurrence {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 6px 0 0;
}

.day-title {
  font-size: 1rem;
  margin: 6px 0 10px;
  text-transform: capitalize;
}
.day-section-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 12px 0 -6px 2px;
}

/* Dia do calendário com itens ganha um fundo levemente destacado */
.cal-day.has-items { background: var(--bg-elevated-2); }
.cal-day.in-range { box-shadow: inset 0 -3px 0 0 var(--warning); }

/* ------------------------------- Anexos ------------------------------- */
.upload-row { display: flex; gap: 8px; flex-wrap: wrap; }
.upload-btn {
  flex: 1;
  min-width: 140px;
  text-align: center;
  background: var(--bg);
  border: 1px dashed var(--border);
  color: var(--text-muted);
  border-radius: 10px;
  padding: 12px;
  font-size: 0.9rem;
  cursor: pointer;
}
.upload-btn:active { border-color: var(--accent); color: var(--accent); }

.attachment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}
.attachment {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 6px;
}
.attachment img { width: 100%; height: 100%; object-fit: cover; }
.attachment .file-icon { font-size: 1.6rem; }
.attachment .file-name {
  font-size: 0.65rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-top: 4px;
  overflow-wrap: anywhere;
}
.attachment .remove {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(2, 6, 23, 0.8);
  border: none;
  color: #fff;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 0.7rem;
  line-height: 1;
}
.attachment a.open {
  position: absolute;
  inset: 0;
}
.attach-count { font-size: 0.8rem; color: var(--text-muted); margin: 6px 0 0; }

/* ------------------------------- Impressão de anexos ------------------------------- */
@media print {
  #print-area .p-photos {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 6px 0 0 14px;
  }
  #print-area .p-photos img {
    max-width: 32%;
    max-height: 190px;
    object-fit: contain;
    border: 1px solid #bbb;
  }
  #print-area .p-files { font-size: 9.5pt; color: #333; margin: 4px 0 0 14px; }
}

/* ===========================================================================
   v5 — ajustes para uso no celular
   =========================================================================== */

/* Cabeçalho + abas grudados no topo, respeitando a área segura do iPhone */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(10px);
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--border);
}
.app-header .topbar {
  position: static;
  border-bottom: none;
  backdrop-filter: none;
  background: transparent;
  padding-bottom: 8px;
}
.app-header .view-switch {
  position: static;
  margin: 0 auto 12px;
  width: calc(100% - 28px);
}

main {
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
}

/* Alvos de toque maiores e que quebram linha sem apertar */
.entry-footer {
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-start;
}
.entry-footer button {
  flex: 1 1 auto;
  min-width: 88px;
  min-height: 40px;
  font-size: 0.85rem;
  text-align: center;
}
.note-actions button { min-height: 34px; padding: 4px 8px; font-size: 0.82rem; }
.mini-row button { min-width: 38px; min-height: 38px; font-size: 1rem; }
.tab { min-height: 38px; }
.view-btn { min-height: 40px; }

/* Modais ocupam a tela toda no celular, com espaço para a barra inferior */
.modal-box { padding-bottom: env(safe-area-inset-bottom); }
.modal-body { padding-bottom: calc(28px + env(safe-area-inset-bottom)); }

/* Telas estreitas: campos lado a lado passam a empilhar */
@media (max-width: 430px) {
  .topbar h1 { font-size: 1.02rem; }
  .icon-btn { width: 38px; height: 38px; }
  .view-btn { font-size: 0.82rem; padding: 9px 6px; }
  .form-row { flex-direction: column; gap: 12px; }
  .cal-day { font-size: 0.85rem; }
  .cal-grid { gap: 3px; }
  .capture-card textarea { min-height: 74px; }
  .upload-btn { min-width: 100%; }
}

/* Evita que o iOS dê zoom ao focar num campo (fonte precisa ser >= 16px) */
input, textarea, select { font-size: 16px; }

/* Rolagem suave ao trocar de dia no calendário */
html { scroll-behavior: smooth; }
