:root {
  --rose-950: #4a1025;
  --rose-800: #9d174d;
  --rose-600: #db2777;
  --rose-500: #ec4899;
  --rose-400: #f472b6;
  --rose-300: #f9a8d4;
  --rose-200: #fbcfe8;
  --rose-100: #fce7f3;
  --blush: #fff1f5;
  --cream: #fff7fb;
  --ink: #3b1220;
  --muted: #8b5a6e;
  --line: rgba(190, 64, 110, 0.18);
  --card: rgba(255, 255, 255, 0.82);
  --shadow: 0 18px 50px rgba(157, 23, 77, 0.12);
  --ok: #0f766e;
  --danger: #be123c;
  --warn: #c2410c;
  --radius: 20px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Nunito", system-ui, sans-serif;
  --touch: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --nav-h: calc(64px + var(--safe-b));
}

*, *::before, *::after { box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  height: 100%;
}
body {
  margin: 0;
  min-height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  background:
    radial-gradient(900px 480px at 10% -10%, #ffd6e8 0%, transparent 55%),
    radial-gradient(700px 420px at 100% 0%, #ffc2d9 0%, transparent 50%),
    linear-gradient(180deg, var(--blush) 0%, var(--cream) 45%, #ffe4ef 100%);
  overscroll-behavior-y: none;
}
/* Mobile app chrome: shell scrolls, bottom bar stays pinned */
body:has(.nav-bottom) {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  padding-bottom: 0;
}
body:has(.auth-wrap) {
  display: block;
  height: auto;
  max-height: none;
  overflow: auto;
  padding-bottom: 0;
}

a { color: var(--rose-800); text-decoration: none; }
a:hover { color: var(--rose-600); }
button, a, input, select, textarea { -webkit-tap-highlight-color: rgba(219, 39, 119, 0.12); }

.app-shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 0.9rem 1.25rem;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: clip;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* ===== Top bar (brand + logout) — full-bleed on phone ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 calc(-1 * 0.9rem) 1rem;
  width: calc(100% + 1.8rem);
  max-width: none;
  position: sticky;
  top: 0;
  z-index: 40;
  padding-top: calc(0.55rem + var(--safe-t));
  padding-bottom: 0.55rem;
  padding-left: max(0.9rem, env(safe-area-inset-left, 0px));
  padding-right: max(0.9rem, env(safe-area-inset-right, 0px));
  min-height: calc(56px + var(--safe-t));
  box-sizing: border-box;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  background: rgba(255, 241, 245, 0.94);
  box-shadow: 0 8px 24px rgba(157, 23, 77, 0.06);
}
.brand {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 600;
  color: var(--rose-800);
  letter-spacing: -0.02em;
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
}
.brand span { color: var(--rose-500); }

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 0 0 auto;
}
.top-actions .btn-sm {
  white-space: nowrap;
  padding-left: 0.95rem;
  padding-right: 0.95rem;
}

/* Desktop top nav hidden on phone — bottom tabs instead */
.nav-desktop { display: none; }

/* ===== Bottom tab bar (mobile-first) ===== */
.nav-bottom {
  position: relative; /* pinned via body flex — more reliable than fixed on some phones */
  left: auto;
  right: auto;
  bottom: auto;
  z-index: 50;
  flex: 0 0 auto;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0;
  padding: 0.35rem 0.25rem calc(0.35rem + var(--safe-b));
  min-height: var(--nav-h);
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 30px rgba(157, 23, 77, 0.08);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  /* Keep above iOS home-indicator / browser chrome quirks */
  padding-left: max(0.25rem, env(safe-area-inset-left, 0px));
  padding-right: max(0.25rem, env(safe-area-inset-right, 0px));
}
.nav-bottom a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-height: 52px;
  padding: 0.3rem 0.1rem;
  border-radius: 14px;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.68rem;
  letter-spacing: 0.01em;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-bottom a .ico {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  line-height: 1;
}
.nav-bottom a.active,
.nav-bottom a:active {
  color: var(--rose-800);
  background: rgba(236, 72, 153, 0.12);
}

.hero {
  position: relative;
  overflow: hidden;
  border-radius: calc(var(--radius) + 4px);
  padding: 1.25rem 1.15rem;
  margin-bottom: 0.95rem;
  color: #fff;
  background: linear-gradient(135deg, #be185d 0%, #db2777 42%, #f472b6 100%);
  box-shadow: var(--shadow);
  animation: rise 0.55s ease both;
}
.hero::after {
  content: "";
  position: absolute;
  inset: auto -20% -45% 35%;
  height: 160px;
  background: radial-gradient(circle, rgba(255,255,255,0.35), transparent 65%);
  pointer-events: none;
}
.hero h1 {
  margin: 0 0 0.3rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.55rem, 6.5vw, 2.3rem);
  letter-spacing: -0.03em;
  position: relative;
  z-index: 1;
}
.hero p {
  margin: 0;
  max-width: 36rem;
  opacity: 0.96;
  font-size: 0.98rem;
  position: relative;
  z-index: 1;
}

.grid {
  display: grid;
  gap: 0.85rem;
  grid-template-columns: repeat(12, 1fr);
}
.col-4, .col-5, .col-6, .col-7, .col-8, .col-12 { grid-column: span 12; }

.panel {
  background: var(--card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1rem 1.05rem;
  box-shadow: 0 10px 30px rgba(190, 24, 93, 0.06);
  animation: rise 0.6s ease both;
}
.panel h2, .panel h3 {
  margin: 0 0 0.7rem;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
}
.panel h2 { font-size: 1.25rem; }
.panel h3 { font-size: 1.08rem; color: var(--rose-800); }

.stat { display: flex; flex-direction: column; gap: 0.15rem; }
.stat .label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.stat .value {
  font-family: var(--font-display);
  font-size: clamp(1.55rem, 6vw, 1.9rem);
  color: var(--rose-800);
}
.stat .sub { color: var(--muted); font-size: 0.92rem; }

.stats-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
  margin-bottom: 0.85rem;
}
.panel-sub { margin: -0.25rem 0 0.75rem; }
.w-full { width: 100%; }
.notify-row { margin: 0 0 0.5rem; }
.notify-status {
  margin: 0 0 0.85rem;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.35;
}
.notify-ok { color: var(--ok); }
.notify-warn { color: var(--muted); }
.tg-box {
  margin: 0 0 1rem;
  padding: 0.9rem 0.95rem;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.72);
}
.tg-box h3 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}
.tg-steps {
  margin: 0.35rem 0 0.85rem 1.1rem;
  padding: 0;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.95rem;
}
.tg-steps li { margin: 0.25rem 0; }
.tg-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  margin-bottom: 0.35rem;
}
.tg-actions form { margin: 0; }

.form-grid {
  display: grid;
  gap: 0.8rem;
  grid-template-columns: 1fr;
}
.form-grid .full { grid-column: 1 / -1; }
.form-grid .btn { width: 100%; }
.form-grid > * { min-width: 0; max-width: 100%; }
.grid > * { min-width: 0; max-width: 100%; }
.panel { max-width: 100%; overflow-x: clip; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--rose-950);
}

input, select, textarea {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.95);
  border-radius: 14px;
  padding: 0.85rem 0.95rem;
  min-height: var(--touch);
  font: inherit;
  font-size: 16px; /* prevents iOS zoom */
  color: var(--ink);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
::placeholder {
  color: var(--muted);
  opacity: 0.85;
  font-size: 0.95em;
}
label, .panel, .hero, .list-quiet li, td, th {
  overflow-wrap: anywhere;
  word-break: break-word;
}
/* Keep date/time native UI from blowing past the phone width */
label { max-width: 100%; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(236, 72, 153, 0.35);
  border-color: var(--rose-400);
}
textarea { min-height: 96px; resize: vertical; overflow: auto; }
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="month"],
select {
  min-height: var(--touch);
  -webkit-appearance: none;
  appearance: none;
  display: block;
}
input[type="date"]::-webkit-date-and-time-value,
input[type="datetime-local"]::-webkit-date-and-time-value,
input[type="time"]::-webkit-date-and-time-value {
  text-align: left;
  min-width: 0;
  width: 100%;
}
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 0;
  border-radius: 999px;
  padding: 0.85rem 1.2rem;
  min-height: var(--touch);
  font: inherit;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.98); }
.btn-block { width: 100%; }
.btn-primary {
  background: linear-gradient(135deg, var(--rose-600), var(--rose-500));
  color: #fff;
  box-shadow: 0 10px 24px rgba(219, 39, 119, 0.28);
}
.btn-ghost {
  background: rgba(255,255,255,0.8);
  color: var(--rose-800);
  border: 1px solid var(--line);
}
.btn-danger {
  background: rgba(190, 18, 60, 0.1);
  color: var(--danger);
}
.btn-sm {
  padding: 0.55rem 0.9rem;
  min-height: 42px;
  font-size: 0.9rem;
}

/* Tables → mobile cards */
.table-wrap { width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td {
  text-align: left;
  padding: 0.7rem 0.45rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

@media (max-width: 820px) {
  .table-wrap table,
  .table-wrap thead,
  .table-wrap tbody,
  .table-wrap th,
  .table-wrap td,
  .table-wrap tr { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr {
    margin-bottom: 0.75rem;
    padding: 0.85rem 0.9rem;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255,255,255,0.65);
  }
  .table-wrap tr:last-child { margin-bottom: 0; }
  .table-wrap td {
    border: 0;
    padding: 0.35rem 0;
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    align-items: flex-start;
  }
  .table-wrap td::before {
    content: attr(data-label);
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    flex: 0 0 34%;
    padding-top: 0.15rem;
  }
  .table-wrap td:last-child {
    padding-top: 0.65rem;
    margin-top: 0.25rem;
    border-top: 1px dashed var(--line);
    display: block;
  }
  .table-wrap td:last-child::before { display: none; }
  .table-wrap td.actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
    width: 100%;
  }
  .table-wrap td.actions form { margin: 0; }
  .table-wrap td.actions .btn,
  .table-wrap td .btn-block,
  .table-wrap td > form .btn { width: 100%; }
  .table-wrap td > form { width: 100%; margin: 0; }

  .hero p { font-size: 0.92rem; }
  .nav-bottom a { font-size: 0.62rem; }
  .nav-bottom a .ico { font-size: 1.15rem; }
  #enable-notify { width: 100%; }
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.28rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 800;
}
.badge-ok { background: rgba(15, 118, 110, 0.12); color: var(--ok); }
.badge-warn { background: rgba(194, 65, 12, 0.12); color: var(--warn); }
.badge-rose { background: rgba(236, 72, 153, 0.14); color: var(--rose-800); }
.badge-muted { background: rgba(139, 90, 110, 0.12); color: var(--muted); }

.flash {
  border-radius: 16px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.85rem;
  font-weight: 700;
  animation: rise 0.35s ease both;
}
.flash-ok { background: rgba(15, 118, 110, 0.12); color: var(--ok); }
.flash-error { background: rgba(190, 18, 60, 0.12); color: var(--danger); }

.auth-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(1rem, var(--safe-t)) 1rem max(1.25rem, var(--safe-b));
}
.auth-card {
  width: min(440px, 100%);
  background: rgba(255,255,255,0.88);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 1.5rem 1.2rem;
  box-shadow: var(--shadow);
  animation: rise 0.55s ease both;
}
.auth-card h1 {
  font-family: var(--font-display);
  margin: 0 0 0.35rem;
  color: var(--rose-800);
  letter-spacing: -0.03em;
  font-size: clamp(1.6rem, 7vw, 2rem);
}
.auth-card .lede { color: var(--muted); margin: 0 0 1.1rem; }
.auth-card .stack { display: grid; gap: 0.85rem; }
.auth-card .btn { width: 100%; }

.chart-box {
  position: relative;
  height: 220px;
  width: 100%;
  max-width: 100%;
  touch-action: pan-y;
}

.list-quiet { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.65rem; }
.list-quiet li {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
  padding: 0.85rem 0.9rem;
  border-radius: 16px;
  background: rgba(255,255,255,0.62);
  border: 1px solid var(--line);
}
.list-quiet li > div:first-child { min-width: 0; }
.list-quiet .actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  width: 100%;
}
.list-quiet .actions form { margin: 0; }
.list-quiet .actions .btn { width: 100%; }

.muted { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.footer-note {
  margin: 1.5rem 0 0.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding-bottom: 0.25rem;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== Larger phones / small tablets ===== */
@media (min-width: 600px) {
  .stats-row { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 720px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .list-quiet li {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
  .list-quiet .actions {
    display: flex;
    width: auto;
    grid-template-columns: none;
  }
  .list-quiet .actions .btn { width: auto; }
  .chart-box { height: 250px; }
  .app-shell { padding-left: 1.15rem; padding-right: 1.15rem; }
}


@media (max-width: 380px) {
  .app-shell { padding-left: 0.65rem; padding-right: 0.65rem; }
  .topbar {
    margin-left: -0.65rem;
    margin-right: -0.65rem;
    width: calc(100% + 1.3rem);
    padding-left: 0.65rem;
    padding-right: 0.65rem;
  }
  .panel { padding: 0.85rem 0.75rem; }
  input, select, textarea { padding-left: 0.7rem; padding-right: 0.7rem; }
  input[type="date"],
  input[type="datetime-local"],
  input[type="time"] { font-size: 15px; }
}

/* ===== Desktop ===== */
@media (min-width: 901px) {
  body,
  body:has(.nav-bottom) {
    display: block;
    height: auto;
    max-height: none;
    overflow: auto;
    padding-bottom: 2rem;
  }
  .app-shell {
    flex: none;
    overflow: visible;
    min-height: 0;
  }
  .nav-bottom { display: none; }
  .nav-desktop {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
  }
  .nav-desktop a {
    padding: 0.5rem 0.85rem;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    color: var(--rose-800);
    font-weight: 700;
    font-size: 0.92rem;
  }
  .nav-desktop a:hover,
  .nav-desktop a.active {
    background: rgba(236, 72, 153, 0.14);
  }
  .topbar {
    position: static;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-bottom: 0;
    box-shadow: none;
    margin: 0 0 1.35rem;
    width: 100%;
    min-height: 0;
    padding: 0.45rem 0;
  }
  .app-shell { padding-top: 1.25rem; }
  .col-4 { grid-column: span 4; }
  .col-5 { grid-column: span 5; }
  .col-6 { grid-column: span 6; }
  .col-7 { grid-column: span 7; }
  .col-8 { grid-column: span 8; }
  .col-12 { grid-column: span 12; }
  .hero { padding: 1.8rem 1.6rem; }
  .panel { padding: 1.15rem 1.2rem; }
  .chart-box { height: 260px; }
  .app-shell { padding: 1.25rem 1.1rem 3rem; }
  .table-wrap table,
  .table-wrap thead,
  .table-wrap tbody,
  .table-wrap th,
  .table-wrap td,
  .table-wrap tr { display: revert; }
  .table-wrap thead { display: table-header-group; }
  .table-wrap tr {
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
  }
  .table-wrap td {
    display: table-cell;
    border-bottom: 1px solid var(--line);
    padding: 0.7rem 0.45rem;
  }
  .table-wrap td::before { content: none; }
  .table-wrap td:last-child {
    border-top: 0;
    margin-top: 0;
    padding-top: 0.7rem;
  }
}
