/* ============================================================
   Edícula Tebaldi — tema sobre Bootstrap 5.3
   Paleta: azul-piscina (primária) + areia quente (destaque)
   ============================================================ */

:root,
[data-bs-theme="light"] {
  --app-primary: #0b7285;
  --app-primary-rgb: 11, 114, 133;
  --app-primary-hover: #095c6b;
  --app-accent: #f59f00;
  --app-surface: #f4f7f8;
  --app-card-shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);

  --cal-free-bg: #e6f6ec;
  --cal-free-fg: #1b6b3a;
  --cal-busy-bg: #fde2e1;
  --cal-busy-fg: #a4221c;
  --cal-pre-bg: #fff1cc;
  --cal-pre-fg: #8a5a00;
  --cal-past: .45;

  --bs-primary: var(--app-primary);
  --bs-primary-rgb: var(--app-primary-rgb);
  --bs-link-color: var(--app-primary);
  --bs-link-color-rgb: var(--app-primary-rgb);
  --bs-link-hover-color: var(--app-primary-hover);
  --bs-body-bg: var(--app-surface);
  --bs-font-sans-serif: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif;
}

[data-bs-theme="dark"] {
  --app-primary: #1098ad;
  --app-primary-rgb: 16, 152, 173;
  --app-primary-hover: #15aabf;
  --app-surface: #0f1720;
  --app-card-shadow: 0 0 0 1px rgba(255, 255, 255, .06);

  --cal-free-bg: rgba(64, 192, 87, .16);
  --cal-free-fg: #8ce99a;
  --cal-busy-bg: rgba(250, 82, 82, .22);
  --cal-busy-fg: #ffa8a8;
  --cal-pre-bg: rgba(250, 176, 5, .2);
  --cal-pre-fg: #ffd43b;
  --cal-past: .4;

  --bs-body-bg: var(--app-surface);
  --bs-secondary-bg: #16212c;
  --bs-tertiary-bg: #131d27;
  --bs-link-color: #66d9e8;
  --bs-link-color-rgb: 102, 217, 232;
  --bs-link-hover-color: #99e9f2;
  --bs-border-color: #263341;
}

[data-bs-theme="dark"] .bg-body,
[data-bs-theme="dark"] .card,
[data-bs-theme="dark"] .modal-content,
[data-bs-theme="dark"] .offcanvas-lg,
[data-bs-theme="dark"] .dropdown-menu {
  --bs-body-bg: #16212c;
  --bs-card-bg: #16212c;
  background-color: #16212c;
}

.btn-primary {
  --bs-btn-bg: var(--app-primary);
  --bs-btn-border-color: var(--app-primary);
  --bs-btn-hover-bg: var(--app-primary-hover);
  --bs-btn-hover-border-color: var(--app-primary-hover);
  --bs-btn-active-bg: var(--app-primary-hover);
  --bs-btn-active-border-color: var(--app-primary-hover);
  --bs-btn-disabled-bg: var(--app-primary);
  --bs-btn-disabled-border-color: var(--app-primary);
}

.btn-outline-primary {
  --bs-btn-color: var(--app-primary);
  --bs-btn-border-color: var(--app-primary);
  --bs-btn-hover-bg: var(--app-primary);
  --bs-btn-hover-border-color: var(--app-primary);
  --bs-btn-active-bg: var(--app-primary);
  --bs-btn-active-border-color: var(--app-primary);
}
[data-bs-theme="dark"] .btn-outline-primary { --bs-btn-color: #66d9e8; }

.nav-pills { --bs-nav-pills-link-active-bg: var(--app-primary); }
.nav-pills .nav-link:not(.active):hover { background: rgba(var(--app-primary-rgb), .08); }
.form-control:focus, .form-select:focus, .form-check-input:focus {
  border-color: rgba(var(--app-primary-rgb), .6);
  box-shadow: 0 0 0 .2rem rgba(var(--app-primary-rgb), .2);
}
.form-check-input:checked { background-color: var(--app-primary); border-color: var(--app-primary); }
.page-link { --bs-pagination-active-bg: var(--app-primary); --bs-pagination-active-border-color: var(--app-primary); }

body { -webkit-tap-highlight-color: transparent; }

.card { border: 0; box-shadow: var(--app-card-shadow); border-radius: .85rem; }
.card-header { background: transparent; font-weight: 600; }

/* ------------------------------------------------ Shell do painel */
.app-topbar { padding-top: max(.5rem, env(safe-area-inset-top)); z-index: 1030; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: var(--app-primary); color: #fff; font-weight: 600; font-size: .9rem;
}
.app-main { flex: 1; min-width: 0; }

@media (min-width: 992px) {
  .app-shell { display: flex; align-items: flex-start; }
  .app-sidebar {
    width: 240px; flex-shrink: 0;
    position: sticky; top: 57px; height: calc(100vh - 57px); overflow-y: auto;
    background: var(--bs-body-bg);
  }
}

@media (max-width: 991.98px) {
  body.admin { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
}

.app-tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
  display: flex; justify-content: space-around; align-items: center;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 10px rgba(0, 0, 0, .05);
}
.app-tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--bs-secondary-color); text-decoration: none; font-size: .7rem; padding: 4px 0;
}
.app-tabbar a i { font-size: 1.3rem; line-height: 1; }
.app-tabbar a.active { color: var(--app-primary); font-weight: 600; }
[data-bs-theme="dark"] .app-tabbar a.active { color: #66d9e8; }
.app-tabbar a.tab-add {
  flex: 0 0 auto; width: 52px; height: 52px; border-radius: 50%; margin-top: -26px;
  background: var(--app-primary); color: #fff; justify-content: center;
  box-shadow: 0 4px 12px rgba(var(--app-primary-rgb), .45);
}
.app-tabbar a.tab-add i { font-size: 1.6rem; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.page-head h1 { font-size: 1.35rem; font-weight: 700; margin: 0; }
.page-head .actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }

/* ------------------------------------------------ KPIs */
.kpi { padding: 1rem 1.1rem; height: 100%; }
.kpi .kpi-label { font-size: .8rem; color: var(--bs-secondary-color); display: flex; align-items: center; gap: .4rem; }
.kpi .kpi-value { font-size: 1.45rem; font-weight: 700; line-height: 1.2; margin-top: .25rem; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { font-size: .78rem; color: var(--bs-secondary-color); }
.kpi-icon {
  width: 30px; height: 30px; border-radius: .5rem; display: inline-grid; place-items: center;
  background: rgba(var(--app-primary-rgb), .12); color: var(--app-primary);
}
[data-bs-theme="dark"] .kpi-icon { color: #66d9e8; }

.tabular { font-variant-numeric: tabular-nums; }
.text-money-in { color: #2b8a3e; }
.text-money-out { color: #c92a2a; }
[data-bs-theme="dark"] .text-money-in { color: #8ce99a; }
[data-bs-theme="dark"] .text-money-out { color: #ffa8a8; }

/* Lista em cards no celular (tabelas viram cards) */
@media (max-width: 767.98px) {
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr {
    background: var(--bs-body-bg); border-radius: .75rem; margin-bottom: .6rem;
    box-shadow: var(--app-card-shadow); padding: .6rem .85rem;
  }
  [data-bs-theme="dark"] .table-cards tr { background: #16212c; }
  .table-cards td { border: 0; padding: .15rem 0; }
  .table-cards td[data-label]::before {
    content: attr(data-label); display: inline-block; min-width: 92px;
    color: var(--bs-secondary-color); font-size: .78rem;
  }
  .table-cards td.td-actions { padding-top: .5rem; }
  .table-cards-wrap { background: transparent !important; box-shadow: none !important; }
}

/* ------------------------------------------------ Calendário */
.cal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.cal-month { padding: .85rem; }
.cal-month h3 { font-size: 1rem; font-weight: 700; text-align: center; margin: 0 0 .6rem; }
.cal-week, .cal-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-week div { font-size: .7rem; font-weight: 600; color: var(--bs-secondary-color); text-transform: uppercase; padding-bottom: 2px; }
.cal-day {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: .5rem; font-size: .9rem; font-weight: 500; position: relative;
  border: 0; padding: 0; color: inherit; background: transparent; text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.cal-day.free { background: var(--cal-free-bg); color: var(--cal-free-fg); }
.cal-day.busy { background: var(--cal-busy-bg); color: var(--cal-busy-fg); font-weight: 700; }
.cal-day.pre { background: var(--cal-pre-bg); color: var(--cal-pre-fg); font-weight: 700; }
.cal-day.past { opacity: var(--cal-past); }
.cal-day.today { outline: 2px solid var(--app-primary); outline-offset: 1px; }
.cal-day.weekend.free { font-weight: 700; }
a.cal-day, button.cal-day { cursor: pointer; transition: transform .08s ease; }
a.cal-day:hover, button.cal-day:hover { transform: scale(1.08); z-index: 1; }
.cal-day .cal-dot { position: absolute; bottom: 4px; width: 4px; height: 4px; border-radius: 50%; background: currentColor; }

.cal-legend { display: flex; flex-wrap: wrap; gap: 1rem; font-size: .85rem; }
.cal-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.cal-legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }

/* Um mês por vez no celular */
.cal-toolbar { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.cal-toolbar .cal-title { font-weight: 700; font-size: 1.1rem; min-width: 150px; text-align: center; }

@media (max-width: 575.98px) {
  .cal-grid { grid-template-columns: 1fr; }
  .cal-day { font-size: 1rem; }
}

/* ------------------------------------------------ Galeria admin */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.photo-card { position: relative; overflow: hidden; border-radius: .75rem; background: var(--bs-secondary-bg); }
.photo-card img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.photo-card.inativa img { opacity: .35; filter: grayscale(1); }
.photo-card .photo-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 2px; padding: .3rem;
}
.photo-card .badge-ordem { position: absolute; top: .4rem; left: .4rem; }
.dropzone {
  border: 2px dashed var(--bs-border-color); border-radius: .85rem; padding: 1.5rem; text-align: center;
  cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--app-primary); background: rgba(var(--app-primary-rgb), .06); }

/* ------------------------------------------------ Login */
.app-main-guest { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; }
.login-brand img { width: 72px; height: 72px; border-radius: 1rem; box-shadow: 0 6px 20px rgba(var(--app-primary-rgb), .35); }

/* ------------------------------------------------ Diversos */
.search-bar .form-control { border-radius: 2rem; padding-left: 2.4rem; }
.search-bar { position: relative; }
.search-bar .bi-search { position: absolute; left: .95rem; top: 50%; transform: translateY(-50%); color: var(--bs-secondary-color); }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--bs-secondary-color); }
.empty-state i { font-size: 2.5rem; display: block; margin-bottom: .5rem; opacity: .6; }
.list-group-item-action { cursor: pointer; }
.offline-banner {
  position: fixed; bottom: calc(76px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  z-index: 1050; border-radius: 2rem; padding: .4rem 1rem; font-size: .85rem;
}
@media (min-width: 992px) { .offline-banner { bottom: 1rem; } }
pre.json { font-size: .75rem; white-space: pre-wrap; word-break: break-word; margin: 0; }
.cal-grid.cal-single { grid-template-columns: minmax(0, 560px); justify-content: center; }

/* Feriados no calendário: marcador no canto + lista do mês */
.cal-day .cal-hol {
  position: absolute; top: 3px; right: 3px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--hol-cor, #7048e8); box-shadow: 0 0 0 1.5px var(--bs-body-bg);
}
.h-nacional, .h-estadual, .h-municipal { --hol-cor: #7048e8; }
.h-facultativo { --hol-cor: #1c7ed6; }
.h-comemorativo { --hol-cor: #e64980; }
[data-bs-theme="dark"] .h-nacional, [data-bs-theme="dark"] .h-estadual, [data-bs-theme="dark"] .h-municipal { --hol-cor: #b197fc; }
[data-bs-theme="dark"] .h-facultativo { --hol-cor: #74c0fc; }
[data-bs-theme="dark"] .h-comemorativo { --hol-cor: #faa2c1; }
.cal-day.holiday:not(.busy):not(.pre) { box-shadow: inset 0 0 0 1.5px var(--hol-cor); }
.cal-hol-list { list-style: none; padding: .5rem 0 0; margin: .5rem 0 0; border-top: 1px dashed var(--bs-border-color); font-size: .75rem; color: var(--bs-secondary-color); }
.cal-hol-list li { display: flex; gap: .4rem; align-items: baseline; line-height: 1.5; }
.cal-hol-list li::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--hol-cor); flex-shrink: 0; transform: translateY(-1px); }
.cal-hol-list b { color: var(--bs-body-color); font-variant-numeric: tabular-nums; }
.cal-legend .leg-hol { width: 10px !important; height: 10px !important; border-radius: 50% !important; }
.cal-hol-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--hol-cor); flex-shrink: 0; display: inline-block; }

/* Utilitário ausente no Bootstrap: permite truncar texto dentro de flex */
.min-w-0 { min-width: 0; }

/* Sidebar: offcanvas-lg vira flex em linha no desktop; força coluna e versão no rodapé */
.app-sidebar .offcanvas-body { display: flex; flex-direction: column; }
.app-sidebar .sidebar-rodape { margin-top: auto; padding-top: 1rem; font-size: .75rem; color: var(--bs-secondary-color); text-align: center; }
.app-sidebar .sidebar-rodape .sep { opacity: .5; margin: 0 .25rem; }

/* Interessados (lista de espera) no calendário do painel */
.cal-day .cal-int { position: absolute; top: 1px; left: 4px; font-size: .6rem; line-height: 1; color: #1971c2; }
[data-bs-theme="dark"] .cal-day .cal-int { color: #74c0fc; }

/* Dias selecionados no calendário */
.cal-day.selected, .cal-day.selected.free, .cal-day.selected.busy, .cal-day.selected.pre {
  background: var(--app-primary); color: #fff; opacity: 1; font-weight: 700;
  box-shadow: 0 0 0 2px rgba(var(--app-primary-rgb), .35);
}
.cal-day.selected .cal-int { color: #fff; }

/* Barra de seleção (fixa no rodapé) */
.sel-bar {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 1045;
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: min(640px, calc(100% - 24px)); border-radius: 1rem; padding: .75rem .9rem;
  background: var(--bs-body-bg); box-shadow: 0 10px 30px rgba(0, 0, 0, .22); border: 1px solid var(--bs-border-color);
}
[data-bs-theme="dark"] .sel-bar { background: #1b2733; }
@media (max-width: 991.98px) { body.admin .sel-bar { bottom: calc(80px + env(safe-area-inset-bottom)); } }
.sel-bar .sel-dias { font-size: .85rem; }

/* Impressão (ex.: balanço anual): só o conteúdo */
@media print {
  .app-topbar, .app-sidebar, .app-tabbar, .no-print, .toast-container, .offline-banner, .sel-bar { display: none !important; }
  body, body.admin { background: #fff !important; padding: 0 !important; }
  .app-shell { display: block !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd !important; break-inside: avoid; }
  .collapse:not(.show) { display: none !important; }
  a { text-decoration: none !important; color: inherit !important; }
}

/* Valores dos KPIs não quebram "R$" do número; menores no celular */
.kpi .kpi-value { white-space: nowrap; }
@media (max-width: 575.98px) { .kpi .kpi-value { font-size: 1.15rem; } }
