:root {
  --bg: #fff7ea;
  --ink: #17302d;
  --muted: #62716f;
  --card: #fffdf8;
  --line: #ead9bd;
  --primary: #55bdb5;
  --primary-dark: #247f78;
  --accent: #ff7a1a;
  --accent-dark: #c84f00;
  --accent-soft: #ffe2c7;
  --success-soft: #dff6f3;
  --danger: #b94b3f;
  --shadow: 0 14px 34px rgba(34, 66, 61, 0.13);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 16% 0, rgba(85, 189, 181, 0.24), transparent 24rem),
    radial-gradient(circle at 100% 8%, rgba(255, 122, 26, 0.2), transparent 22rem),
    linear-gradient(180deg, #fff1dc 0%, var(--bg) 44%, #ffffff 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

button,
input,
select,
textarea {
  font: inherit;
}

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

.app-shell {
  width: min(100%, 480px);
  min-height: 100vh;
  margin: 0 auto;
  background: rgba(255, 253, 248, 0.6);
}

.hidden {
  display: none !important;
}

.auth-screen {
  min-height: 100vh;
  padding: max(34px, env(safe-area-inset-top)) 20px 28px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.brand-mark {
  width: 70px;
  height: 70px;
  display: grid;
  place-items: center;
  border: 4px solid #ffffff;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 58%, var(--primary) 0 20%, transparent 21%),
    radial-gradient(circle at 30% 26%, var(--primary) 0 12%, transparent 13%),
    radial-gradient(circle at 50% 18%, var(--primary) 0 12%, transparent 13%),
    radial-gradient(circle at 70% 26%, var(--primary) 0 12%, transparent 13%),
    #ffffff;
  color: #ffffff;
  font-weight: 900;
  text-transform: uppercase;
  box-shadow: 0 0 0 4px var(--accent), var(--shadow);
}

.auth-screen h1,
.topbar h1,
.entry-card h2,
.hero-panel h2,
.target-card h2,
.ai-sheet h2 {
  margin: 0;
  letter-spacing: 0;
}

.auth-screen h1 {
  font-size: 2.1rem;
}

.auth-screen p {
  max-width: 320px;
  margin: 5px 0 0;
  color: var(--muted);
  line-height: 1.42;
}

.auth-card,
.entry-card,
.hero-panel,
.stat,
.ai-sheet,
.target-card {
  border: 1px solid rgba(234, 217, 189, 0.9);
  background: rgba(255, 253, 248, 0.92);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-card {
  padding: 14px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 14px;
  border-radius: 8px;
  background: #f4e7d1;
}

.segmented button,
.tab {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segmented button {
  min-height: 42px;
}

.segmented button.active {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(34, 66, 61, 0.08);
}

.auth-form,
.entry-card,
.profile-form,
.inner-form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefb;
  color: var(--ink);
  padding: 13px 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(85, 189, 181, 0.18);
}

textarea {
  resize: vertical;
}

.primary,
.ghost,
.chip,
.ai-button,
.ai-hero {
  border: 0;
  border-radius: 8px;
  font-weight: 900;
}

.primary {
  min-height: 50px;
  background: var(--primary-dark);
  color: #ffffff;
}

.primary:active,
.ai-button:active,
.ai-hero:active {
  transform: translateY(1px);
}

.ghost {
  min-height: 38px;
  padding: 0 12px;
  color: var(--primary-dark);
  background: rgba(85, 189, 181, 0.14);
}

.chip,
.pill {
  min-height: 32px;
  padding: 0 11px;
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 900;
}

.message {
  min-height: 20px;
  margin: 10px 2px 0;
  color: var(--danger);
  font-size: 0.88rem;
}

.main-screen {
  min-height: 100vh;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 14px 10px;
  background: rgba(255, 247, 234, 0.92);
  backdrop-filter: blur(18px);
}

.topbar-main {
  min-width: 0;
}

.topbar h1 {
  max-width: 100%;
  overflow: hidden;
  font-size: 1.2rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#sign-out-btn {
  margin-top: 18px;
  white-space: nowrap;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(85, 189, 181, 0.35); }
  50% { box-shadow: 0 0 0 10px rgba(85, 189, 181, 0); }
}

.dog-switcher {
  margin-top: 6px;
  min-height: 34px;
  padding: 6px 9px;
  font-size: 0.86rem;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.view {
  display: none;
  padding: 10px 14px 18px;
}

.view.active {
  display: grid;
  gap: 14px;
}

.ai-hero {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  align-items: center;
  width: min(100%, 300px);
  min-height: 64px;
  justify-self: center;
  padding: 10px 12px;
  text-align: left;
  background: linear-gradient(135deg, var(--accent), #ff9e45);
  color: #ffffff;
  box-shadow: var(--shadow);
}

.ai-hero-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #ffffff;
  color: var(--accent);
  font-weight: 900;
}

.ai-hero strong,
.ai-hero small {
  display: block;
}

.ai-hero small {
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.86);
  line-height: 1.25;
  font-size: 0.72rem;
}

.hero-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  background: linear-gradient(135deg, #18423e, var(--primary-dark));
  color: #ffffff;
}

.hero-panel .muted {
  color: rgba(255, 255, 255, 0.74);
}

.hero-panel h2 {
  font-size: 1.35rem;
}

.target-ring {
  width: 94px;
  height: 94px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  align-content: center;
  border: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, var(--primary-dark) 0 57%, transparent 58%),
    conic-gradient(var(--accent) var(--target-progress, 0%), rgba(255, 255, 255, 0.24) 0);
  text-align: center;
}

.target-ring span {
  font-size: 1.2rem;
  font-weight: 900;
}

.target-ring small {
  max-width: 62px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.64rem;
  line-height: 1;
}

.target-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.target-card {
  min-height: 134px;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 14px;
}

.target-card h2 {
  font-size: 1.08rem;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(85, 189, 181, 0.18);
}

.progress-track span {
  width: 0%;
  height: 100%;
  display: block;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 180ms ease;
}

.entry-card {
  padding: 15px;
}

.accordion {
  padding: 0;
  overflow: hidden;
}

.accordion summary {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 15px;
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

.accordion summary::-webkit-details-marker {
  display: none;
}

.accordion summary::after {
  content: "+";
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--success-soft);
  color: var(--primary-dark);
}

.accordion[open] summary::after {
  content: "-";
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.accordion .inner-form,
.accordion .timeline,
.accordion .simple-list,
.accordion .dog-list {
  padding: 0 15px 15px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.card-head h2,
.entry-card h2,
.ai-sheet h2 {
  font-size: 1.04rem;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sticky-action {
  position: sticky;
  bottom: calc(84px + env(safe-area-inset-bottom));
}

.timeline,
.simple-list,
.dog-list {
  display: grid;
  gap: 10px;
}

.timeline-item,
.list-item,
.dog-item {
  position: relative;
  padding: 12px;
  border: 1px solid rgba(234, 217, 189, 0.78);
  border-radius: 8px;
  background: #ffffff;
}

.swipe-delete {
  touch-action: pan-y;
  transition: transform 160ms ease, opacity 160ms ease;
}

.swipe-delete::after {
  content: "Release to delete";
  position: absolute;
  inset: 0 0 0 auto;
  width: 126px;
  display: grid;
  place-items: center;
  border-radius: 0 8px 8px 0;
  background: #b94a34;
  color: #ffffff;
  font-size: 0.74rem;
  font-weight: 900;
  opacity: 0;
  transform: translateX(18px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.swipe-delete.swiping {
  transform: translateX(-70px);
}

.swipe-delete.swiping::after {
  opacity: 1;
  transform: translateX(0);
}

.timeline-item {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 12px;
}

.dog-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.dog-item.active {
  border-color: var(--primary);
  background: var(--success-soft);
}

.amount-badge {
  height: 54px;
  display: grid;
  place-items: center;
  align-content: center;
  border-radius: 8px;
  background: var(--success-soft);
  color: var(--primary-dark);
  font-weight: 900;
  text-align: center;
}

.amount-badge small {
  font-size: 0.64rem;
  font-weight: 800;
}

.row-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink);
  font-weight: 850;
}

.muted {
  color: var(--muted);
  font-size: 0.84rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.stat {
  min-height: 86px;
  display: grid;
  place-items: center;
  align-content: center;
  padding: 12px 6px;
  text-align: center;
}

.stat span {
  font-size: 0.98rem;
  font-weight: 900;
}

.stat small {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
}

.chart-card {
  min-height: 270px;
}

.chart-card canvas {
  width: 100% !important;
  height: 210px !important;
}

.bottom-tabs {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 8;
  width: min(100%, 480px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(234, 217, 189, 0.86);
  background: rgba(255, 253, 248, 0.94);
  backdrop-filter: blur(18px);
}

.tab {
  min-height: 48px;
}

.tab.active {
  background: var(--primary-dark);
  color: #ffffff;
}

.ai-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  background: rgba(23, 48, 45, 0.34);
}

.ai-sheet {
  width: min(100%, 480px);
  display: grid;
  gap: 12px;
  padding: 15px;
}

.listen-action.listening {
  background: var(--accent);
}

.listen-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.ai-actions {
  display: grid;
  justify-items: end;
}

.export-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.send-report-btn {
  grid-column: 1 / -1;
}

.ai-result {
  min-height: 22px;
  line-height: 1.35;
}

.toast {
  position: fixed;
  right: 14px;
  bottom: calc(90px + env(safe-area-inset-bottom));
  left: 14px;
  z-index: 30;
  max-width: 452px;
  margin: 0 auto;
  padding: 13px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 380px) {
  .stats-grid,
  .target-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .topbar {
    grid-template-columns: 1fr auto;
  }
}

@media (min-width: 700px) {
  body {
    padding: 24px 0;
  }

  .app-shell {
    min-height: calc(100vh - 48px);
    border: 1px solid rgba(234, 217, 189, 0.9);
    border-radius: 24px;
    overflow: hidden;
    box-shadow: var(--shadow);
  }

  .bottom-tabs {
    border-radius: 18px 18px 0 0;
  }
}
