/* Design tokens — light theme by default, dark via prefers-color-scheme. */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #4f46e5;
  --primary-press: #4338ca;
  --success: #16a34a;
  --danger: #dc2626;
  --whatsapp: #25d366;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111a2e;
    --text: #e8edf6;
    --muted: #93a1b8;
    --border: #243049;
    --primary: #818cf8;
    --primary-press: #6366f1;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
/* Author display rules (e.g. .btn) outrank the UA [hidden] style, so enforce it. */
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
.container { width: min(760px, 100% - 2rem); margin-inline: auto; }

/* Header */
.app-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-press));
  color: #fff;
  padding: 1.6rem 0;
  box-shadow: var(--shadow);
}
.app-header h1 { margin: 0; font-size: 1.5rem; }
.subtitle { margin: .25rem 0 0; opacity: .9; font-size: .95rem; }

/* Top navigation (Reports / Schedule) */
.main-nav { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: 1rem; background: rgba(255, 255, 255, .15); border-radius: 12px; padding: .25rem; }
.nav-btn { font: inherit; font-weight: 600; cursor: pointer; border: 0; background: transparent; color: #fff; border-radius: 9px; padding: .45rem 1rem; transition: background .15s; }
.nav-btn.is-active { background: var(--surface); color: var(--primary); }

main { padding-block: 1.25rem 3rem; }
.page { display: grid; gap: 1.25rem; }

/* Cards & form */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 1rem; font-size: 1.15rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; }
.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.field:last-of-type { margin-bottom: 0; }
label { font-weight: 600; font-size: .9rem; }
.req { color: var(--danger); }
.opt { color: var(--muted); font-weight: 400; font-size: .8rem; }

input, textarea {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .6rem .75rem;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 4.5rem; }
input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}
[aria-invalid="true"] { border-color: var(--danger); }
.error { color: var(--danger); font-size: .8rem; min-height: 1em; }
.form-actions { display: flex; gap: .6rem; }
.form-actions [type="submit"] { flex: 1; justify-content: center; padding-block: .7rem; }
.form-actions .btn-ghost { padding-block: .7rem; }

/* Buttons */
.btn {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: .55rem .9rem;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  text-decoration: none;
  transition: background .15s, border-color .15s, opacity .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-press); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.93); }
.btn-block { width: 100%; justify-content: center; padding-block: .7rem; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-done { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.btn-done:hover { background: color-mix(in srgb, var(--success) 24%, transparent); }
.btn-reopen { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); }
.btn-wa { background: var(--whatsapp); color: #053; }
.btn-wa:hover { filter: brightness(.96); }
.btn-icon { background: transparent; padding: .5rem; line-height: 1; }
.btn-del:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); }

/* Toolbar & status filters */
.toolbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; }
.filters { display: inline-flex; flex-wrap: wrap; gap: .15rem; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .25rem; box-shadow: var(--shadow); }
.filters:empty { display: none; }
.filter { font: inherit; font-weight: 600; cursor: pointer; border: 0; background: transparent; color: var(--muted); border-radius: 9px; padding: .45rem .9rem; display: inline-flex; align-items: center; gap: .4rem; transition: background .15s, color .15s; }
.filter.is-active { background: var(--primary); color: #fff; }
.count { background: rgba(127, 127, 127, .25); border-radius: 999px; padding: 0 .5rem; font-size: .8rem; min-width: 1.4em; text-align: center; }
.filter.is-active .count { background: rgba(255, 255, 255, .3); }

/* Report list */
.list { display: grid; gap: .85rem; }
/* Cards — reports and generic items share one shell, body, meta and actions */
.report, .item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: start;
  justify-content: space-between;
}
.report-body, .item-body { flex: 1 1 16rem; min-width: 0; }
.report-meta, .item-meta { display: flex; flex-wrap: wrap; gap: .4rem .6rem; align-items: center; color: var(--muted); font-size: .85rem; }
.report-actions, .item-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.report-desc, .item-title { font-size: 1.05rem; font-weight: 600; overflow-wrap: anywhere; }
.report-desc { margin: 0 0 .55rem; }
.item-title { margin: 0 0 .35rem; }
.badge { background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: .15rem .6rem; font-weight: 600; color: var(--text); }
.report-reporter { overflow-wrap: anywhere; }
.report-time { margin-inline-start: auto; white-space: nowrap; }
.item-desc { margin: 0 0 .5rem; color: var(--muted); overflow-wrap: anywhere; white-space: pre-wrap; }
.item-desc:last-child { margin-bottom: 0; }
.item-desc a { color: var(--primary); }
.num-phone { direction: ltr; }
.task-due { white-space: nowrap; }
.is-overdue .task-due { color: var(--danger); font-weight: 700; }
.btn-call { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.btn-call:hover { background: color-mix(in srgb, var(--success) 26%, transparent); }

.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; font-size: 1.05rem; }

/* Schedule page */
.sch-nav { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.btn-nav { font-size: 1.4rem; line-height: 1; padding: .35rem .8rem; }
.sch-date-wrap { flex: 1; min-width: 0; text-align: center; }
.sch-date { display: block; font-weight: 700; font-size: 1.05rem; }
.btn-link { background: none; border: 0; color: var(--primary); font: inherit; font-size: .85rem; cursor: pointer; padding: 0; margin-top: .15rem; }
/* Day calendar (Google-Calendar-style grid) */
.cal { position: relative; max-height: 62vh; overflow-y: auto; margin-bottom: 1rem; padding-block-start: .55rem; --gutter: 46px; }
.cal:empty { display: none; }
.cal-grid { position: relative; }
.cal-line { position: absolute; inset-inline: var(--gutter) 0; border-top: 1px solid var(--border); }
.cal-label { position: absolute; inset-inline-start: calc(-1 * var(--gutter)); top: -.62em; width: calc(var(--gutter) - 6px); text-align: end; font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.cal-col { position: absolute; inset: 0; inset-inline-start: var(--gutter); }
.cal-event { position: absolute; box-sizing: border-box; min-height: 15px; overflow: hidden; display: flex; gap: 5px; align-items: baseline; background: color-mix(in srgb, var(--primary) 20%, var(--surface)); border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent); border-inline-start: 3px solid var(--primary); border-radius: 6px; padding: 1px 7px; font-size: .76rem; line-height: 1.3; cursor: default; }
.cal-event-time { flex: 0 0 auto; direction: ltr; color: var(--primary); font-weight: 700; font-size: .68rem; font-variant-numeric: tabular-nums; }
.cal-event-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-now { position: absolute; inset-inline: 0; border-top: 2px solid var(--danger); z-index: 2; }
.cal-now::before { content: ''; position: absolute; inset-inline-start: -4px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.hint { margin: 0 0 .6rem; color: var(--muted); font-size: .85rem; }
.hint code { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: .1rem .35rem; font-family: ui-monospace, "Courier New", monospace; }
#sch-text { width: 100%; font-family: ui-monospace, "Courier New", monospace; margin-bottom: 1rem; }

/* Dialog */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  width: min(560px, 100% - 2rem);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(15, 23, 42, .55); }
.dialog-body { padding: 1.25rem; }
.dialog-body h2 { margin: 0 0 .85rem; font-size: 1.15rem; }
#msg-text { font-family: ui-monospace, "Courier New", monospace; white-space: pre-wrap; }
.dialog-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1rem; }

/* Toast */
.toast {
  position: fixed;
  inset-block-end: 1.25rem;
  inset-inline: 0;
  margin-inline: auto;
  width: max-content;
  max-width: calc(100% - 2rem); /* never overflow a narrow screen */
  text-align: center;
  background: var(--text);
  color: var(--surface);
  padding: .7rem 1.2rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-weight: 600;
  z-index: 10;
}
.toast.is-error { background: var(--danger); color: #fff; }

@media (max-width: 560px) {
  .container { width: calc(100% - 1.5rem); }
  .app-header { padding: 1.15rem 0; }
  .app-header h1 { font-size: 1.3rem; }
  .main-nav { justify-content: center; margin-top: .85rem; }
  .nav-btn { padding: .4rem .7rem; }
  .grid { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .report-time { margin-inline-start: 0; }
  .sch-date { font-size: .95rem; }
  .btn-icon { padding: .55rem .65rem; } /* comfortable touch target */
}
