:root {
  --bg: #f4f7f6;
  --panel: #ffffff;
  --text: #1f2937;
  --soft: #64748b;
  --primary: #0f766e;
  --primary-strong: #0b5e58;
  --line: #dce6e2;
  --line-strong: #c8d8d2;
  --shadow: 0 8px 24px rgba(15, 118, 110, 0.06);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(180deg, #f9fcfb 0%, var(--bg) 70%);
  color: var(--text);
}

.page {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 10px 10px 20px;
  display: grid;
  gap: 10px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
}

.brand-wrap {
  min-width: 0;
}

.logo-church {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaf {
  margin-right: 5px;
}

.church-name {
  color: var(--primary);
}

.divider {
  margin: 0 5px;
  color: #94a3b8;
}

.system-name {
  color: #334155;
}

.subtitle {
  margin: 3px 0 0;
  color: var(--soft);
  font-size: 0.76rem;
  line-height: 1.2;
}

.session-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.session-status {
  color: #475569;
  font-size: 0.75rem;
  font-weight: 600;
}

.main-nav {
  display: flex;
  gap: 6px;
  padding: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.nav-tab {
  border: 1px solid #d2dde8;
  background: #f8fafc;
  color: #334155;
  border-radius: 9px;
  min-width: 106px;
  padding: 0 10px;
  height: 34px;
  font-weight: 700;
  font-size: 0.82rem;
  line-height: 1;
  white-space: nowrap;
}

.nav-tab:hover {
  border-color: #99f6e4;
  background: #ecfeff;
  color: var(--primary);
}

.nav-tab.is-active {
  border-color: transparent;
  background: var(--primary);
  color: #fff;
}

.container {
  display: grid;
  gap: 10px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 1.03rem;
}

.section-head {
  margin-bottom: 10px;
}

.section-head h1 {
  margin: 0;
  font-size: 1.16rem;
  line-height: 1.2;
}

.section-subtitle {
  margin: 4px 0 0;
  color: var(--soft);
  font-size: 0.8rem;
}

.panel h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  line-height: 1.2;
  color: #1f2937;
}

.dashboard-block {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line-strong);
}

.dashboard-block:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.login-grid,
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

label {
  display: grid;
  gap: 5px;
  font-size: 0.86rem;
  font-weight: 700;
  color: #334155;
}

input,
select {
  width: 100%;
  border: 1px solid #cfdae2;
  border-radius: 10px;
  height: 40px;
  padding: 8px 10px;
  font-size: 0.94rem;
  background: #fff;
}

input:focus,
select:focus {
  outline: 2px solid #ccfbf1;
  border-color: #5eead4;
}

button {
  grid-column: 1 / -1;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
}

button:hover {
  background: var(--primary-strong);
}

.secondary {
  width: 74px;
  height: 30px;
  border-radius: 8px;
  background: #475569;
  font-size: 0.75rem;
}

.secondary:hover {
  background: #334155;
}

.hint {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--soft);
}

.mensagem {
  min-height: 18px;
  margin: 8px 0 0;
  font-weight: 700;
  font-size: 0.84rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.card {
  border: 1px solid #dbe7e2;
  border-radius: 12px;
  padding: 9px 10px;
  min-height: 72px;
  background: #fff;
  box-shadow: 0 3px 8px rgba(15, 118, 110, 0.05);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.card span {
  display: block;
  color: #64748b;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.15;
}

.card strong {
  display: block;
  margin-top: 5px;
  font-size: 1.12rem;
  line-height: 1.1;
  color: #0f172a;
}

.card.destaque {
  border-color: #a7f3d0;
  background: #f0fdf9;
}

.card.principal {
  border-color: #5eead4;
  background: #ecfdf5;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.14);
}

.card.principal strong {
  font-size: 1.24rem;
}

.finance-grid .card:last-child,
.media-grid .card:last-child {
  grid-column: 1 / -1;
  min-height: 76px;
}

.table-wrapper {
  overflow-x: auto;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  background: #fff;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid #edf2f7;
  padding: 9px;
  white-space: nowrap;
  font-size: 0.82rem;
}

th {
  color: #475569;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.vazio {
  color: var(--soft);
  font-weight: 600;
  font-size: 0.86rem;
}

.panel-view {
  display: none;
}

.panel-view.is-active {
  display: block;
}

.escondido {
  display: none !important;
}

.btn-small {
  width: auto;
  height: 30px;
  padding: 0 10px;
  font-size: 0.75rem;
  border-radius: 8px;
  margin-right: 5px;
  margin-bottom: 4px;
}

.btn-small.danger {
  background: #b91c1c;
}

.btn-small.danger:hover {
  background: #991b1b;
}


.history-entry {
  display: block;
}

.history-button {
  width: 100%;
  height: 38px;
  border: 1px solid #9eead5;
  background: #f0fdf9;
  color: var(--primary);
  font-size: 0.84rem;
  font-weight: 700;
  box-shadow: none;
}

.history-button:hover {
  background: #dcfce7;
  color: #0b5e58;
}

.history-actions {
  margin-top: 12px;
}

.history-back {
  width: 100%;
  height: 36px;
  border: 1px solid #d3dee8;
  background: #f8fafc;
  color: #334155;
  font-size: 0.82rem;
  box-shadow: none;
}

.history-back:hover {
  background: #eef2f7;
}

@media (min-width: 720px) {
  .page {
    padding: 14px;
    gap: 12px;
  }

  .panel {
    padding: 16px;
  }

  .topbar {
    padding: 12px 14px;
  }

  .logo-church {
    font-size: 1.18rem;
  }

  .subtitle {
    font-size: 0.82rem;
  }

  .session-status {
    font-size: 0.8rem;
  }

  .main-nav {
    padding: 8px 10px;
  }

  .history-button {
    width: auto;
    min-width: 220px;
  }

  .history-actions {
    display: flex;
    justify-content: flex-end;
  }

  .history-back {
    width: auto;
    min-width: 170px;
  }

  .nav-tab {
    min-width: 124px;
    height: 36px;
    font-size: 0.85rem;
  }

  .login-grid,
  .form-grid {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }

  .cards {
    gap: 10px;
  }

  .summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .finance-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .media-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .finance-grid .card:last-child,
  .media-grid .card:last-child {
    grid-column: auto;
  }

  .card {
    min-height: 84px;
    padding: 11px;
  }

  .card strong {
    font-size: 1.2rem;
  }

  .card.principal strong {
    font-size: 1.3rem;
  }

  th,
  td {
    font-size: 0.85rem;
  }
}

@media (min-width: 980px) {
  .page {
    gap: 14px;
  }

  .panel {
    padding: 18px;
  }

  .section-head h1 {
    font-size: 1.35rem;
  }

  .section-subtitle {
    font-size: 0.86rem;
  }

  .panel h3 {
    font-size: 1rem;
  }

  .dashboard-block {
    margin-top: 18px;
    padding-top: 16px;
  }
}

@media (max-width: 380px) {
  .logo-church {
    font-size: 0.98rem;
  }

  .subtitle {
    font-size: 0.72rem;
  }

  .session-status {
    max-width: 86px;
  }

  .nav-tab {
    min-width: 96px;
    height: 32px;
  }
}

/* iPhone overflow fix: keep login/header inside viewport */
html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.page,
.panel,
.container,
#auth-panel,
#auth-panel .login-grid,
#auth-panel form {
  max-width: 100%;
  min-width: 0;
}

.page {
  width: 100%;
  max-width: 1120px;
}

.topbar,
.main-nav {
  max-width: 100%;
  overflow-x: hidden;
}

.main-nav {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.brand-wrap {
  flex: 1 1 auto;
  min-width: 0;
}

.session-wrap {
  min-width: 0;
  flex-shrink: 1;
}

.session-status {
  max-width: 88px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#auth-panel input,
#auth-panel select,
#auth-panel button {
  min-width: 0;
}

@media (max-width: 480px) {
  .page {
    padding-left: 8px;
    padding-right: 8px;
  }

  .panel {
    padding: 10px;
  }

  .topbar {
    gap: 6px;
    padding: 8px 10px;
  }

  .logo-church {
    font-size: 0.95rem;
  }

  .subtitle {
    font-size: 0.7rem;
  }

  .session-status {
    max-width: 72px;
    font-size: 0.7rem;
  }

  .secondary {
    width: 64px;
    height: 28px;
    font-size: 0.7rem;
  }

  .nav-tab {
    min-width: 92px;
    height: 32px;
    padding: 0 8px;
    font-size: 0.78rem;
  }
}

/* iOS keyboard stability: prevent zoom/jump on focus */
@supports (-webkit-touch-callout: none) {
  html {
    -webkit-text-size-adjust: 100%;
  }

  body {
    overscroll-behavior-x: none;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  #auth-panel input,
  #auth-panel select,
  #auth-panel textarea,
  #auth-panel button {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  #auth-panel .login-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Dashboard grouping and emphasis */
.dash-date {
  margin: 6px 0 0;
  font-size: 0.78rem;
  color: #0f766e;
  font-weight: 700;
}

.block-participantes,
.block-financeiro {
  margin-top: 14px;
  padding: 12px;
  border-top: none;
  border-radius: 12px;
}

.block-participantes {
  border: 1px solid #cfe0ff;
  background: #f5f9ff;
}

.block-participantes h3 {
  color: #1d4ed8;
}

.block-participantes .card {
  border-color: #cfe0ff;
}

.block-participantes .card.principal {
  border-color: #93c5fd;
  background: #eaf2ff;
}

.block-financeiro {
  border: 1px solid #cdeedd;
  background: #f4fbf7;
}

.block-financeiro h3 {
  color: #047857;
}

.block-financeiro .card {
  border-color: #bfe8d1;
}

.block-financeiro .card.principal {
  border-color: #34d399;
  background: #e9fbf1;
}

.medias-entry {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed #cbd5e1;
}

.medias-button {
  width: 100%;
  height: 36px;
  border: 1px solid #c8d8f6;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 0.82rem;
  font-weight: 700;
  box-shadow: none;
}

.medias-button:hover {
  background: #dbeafe;
  color: #1d4ed8;
}

.medias-panel {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px;
  background: #fafcff;
}

@media (min-width: 720px) {
  .dash-date {
    font-size: 0.82rem;
  }

  .block-participantes,
  .block-financeiro {
    padding: 14px;
  }

  .medias-button {
    width: auto;
    min-width: 220px;
  }
}

/* Header cleanup: only church name + readable logged user */
.divider,
.system-name {
  display: none;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.session-wrap {
  display: grid;
  justify-items: end;
  gap: 4px;
  min-width: 108px;
  max-width: 46%;
}

.session-status {
  max-width: 100%;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  text-align: right;
  line-height: 1.12;
  font-size: 0.72rem;
  font-weight: 700;
}

@media (max-width: 480px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
  }

  .session-wrap {
    min-width: 96px;
    max-width: 49%;
  }

  .session-status {
    font-size: 0.68rem;
  }
}
