:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --header-top-offset: var(--safe-top);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bg-main: #09090b;
  --bg-header: rgba(19, 19, 22, 0.92);
  --bg-header-top: #121215;
  --bg-card: #131316;
  --bg-elevated: #1c1c21;
  --bg-input: #232329;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);
  --text-main: #f4f4f5;
  --text-muted: #a1a1aa;
  --text-dim: #71717a;
  --blue: #3b82f6;
  --indigo: #6366f1;
  --emerald: #10b981;
  --rose: #f43f5e;
  --amber: #f59e0b;
  --pink: #ec4899;
  --purple: #a855f7;
}

@media (max-width: 600px) {
  :root {
    --header-top-offset: calc(var(--safe-top) + 2rem);
  }
}

* {
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Inter", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: auto;
  user-select: none;
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-top-offset);
  background: var(--bg-header-top);
  z-index: 29;
  pointer-events: none;
}

input, select, textarea {
  font-size: 16px !important;
  user-select: text;
  font-family: inherit;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

button:active, .interactive-card:active {
  transform: scale(0.97);
}

.hidden {
  display: none !important;
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: "SF Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Scrollbars */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 999px; }

/* Layout Containers */
.container {
  max-width: 36rem;
  width: 100%;
  margin: 0 auto;
  padding-left: 0.875rem;
  padding-right: 0.875rem;
}

/* Header & Navigation */
.app-header {
  position: sticky;
  top: var(--header-top-offset);
  z-index: 30;
  background: var(--bg-header);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  margin-top: var(--header-top-offset);
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
}

.header-top, .brand-group {
  min-width: 0;
  flex-shrink: 1;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-logo {
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 0.75rem;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.25), rgba(16, 185, 129, 0.2));
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #60a5fa;
  flex-shrink: 0;
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.brand-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
  white-space: nowrap;
}

.brand-subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 155px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.5rem;
  border-radius: 0.7rem;
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  color: #e4e4e7;
  transition: background 0.15s ease, transform 0.1s ease;
  flex-shrink: 0;
}

.pill-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.pill-btn-blue {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.3);
  color: #93c5fd;
}

/* Ukrywa napis "Sync" obok ikony serwera na telefonie, dzięki czemu ikona telefonu mieści się obok */
@media (max-width: 430px) {
  .header-actions .pill-btn-blue span {
    display: none;
  }
}

.sync-badge {
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.625rem;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Status Dots */
.status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  display: inline-block;
  flex-shrink: 0;
}
.dot-emerald { background-color: #34d399; }
.dot-blue    { background-color: #60a5fa; }
.dot-rose    { background-color: #fb7185; }
.dot-amber   { background-color: #fbbf24; }
.dot-pink    { background-color: #f472b6; }

@keyframes pulseSubtle {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.pulse { animation: pulseSubtle 2.2s infinite ease-in-out; }

/* Segmented Tabs (All / Me / Together) */
.segmented-control {
  margin-top: 0.75rem;
  padding: 0.25rem;
  border-radius: 0.75rem;
  background: rgba(24, 24, 27, 0.9);
  border: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.25rem;
}

.segment-btn {
  padding: 0.4rem 0.5rem;
  border-radius: 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-align: center;
  transition: all 0.15s ease;
}

.segment-btn.active {
  background: #27272a;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.08);
}

/* Main Content Area */
.main-content {
  flex: 1;
  padding-top: 1rem;
  padding-bottom: 7rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Sample Notice Banner */
.info-banner {
  border-radius: 1rem;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.25);
  padding: 0.625rem 0.875rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.75rem;
  color: #bfdbfe;
}

.info-banner-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Bento Overview Stats */
.bento-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.625rem;
}

.ios-card {
  background: linear-gradient(180deg, rgba(28, 28, 34, 0.78) 0%, rgba(19, 19, 23, 0.92) 100%);
  border: 1px solid var(--border-subtle);
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.45), inset 0 1px 0 0 rgba(255, 255, 255, 0.06);
  border-radius: 1.25rem;
}

.stat-card {
  padding: 0.875rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.stat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--text-muted);
}

.stat-value-row {
  margin-top: 0.375rem;
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.stat-big-number {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
}

.stat-subtext {
  margin-top: 0.5rem;
  font-size: 0.65rem;
  color: var(--text-muted);
}

.mini-progress-track {
  margin-top: 0.5rem;
  width: 100%;
  height: 0.375rem;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  overflow: hidden;
}

.mini-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue), #34d399);
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* Category Filter Pills */
.category-scroll {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  overflow-x: auto;
  padding-bottom: 0.15rem;
}

.cat-pill {
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.cat-pill.active {
  background: #fff;
  color: #09090b;
  border-color: #fff;
  font-weight: 600;
}

/* Goal Cards List */
.goals-list {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.goal-card {
  padding: 1rem;
  border-radius: 1.5rem;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.goal-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.625rem;
}

.goal-badges {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-wrap: wrap;
}

.badge {
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.badge-owner-a    { background: rgba(59, 130, 246, 0.15); color: #93c5fd; border: 1px solid rgba(59, 130, 246, 0.3); }
.badge-owner-b    { background: rgba(236, 72, 153, 0.15); color: #f9a8d4; border: 1px solid rgba(236, 72, 153, 0.3); }
.badge-owner-both { background: rgba(168, 85, 247, 0.15); color: #d8b4fe; border: 1px solid rgba(168, 85, 247, 0.3); }
.badge-category   { background: rgba(255, 255, 255, 0.06); color: #d4d4d8; font-weight: 500; }

.goal-card-main {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
}

.goal-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}

.goal-numbers {
  margin-top: 0.25rem;
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.goal-current {
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
}

.goal-unit {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.goal-target-info {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.goal-sparkline-box {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
}

.goal-start-caption {
  font-size: 0.625rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.goal-progress-track {
  margin-top: 0.75rem;
  width: 100%;
  height: 0.5rem;
  background: rgba(9, 9, 11, 0.9);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.goal-progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.45s ease;
}

.goal-card-footer {
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
}

/* Dynamic Color Themes for Cards & Bars */
.bar-emerald { background: linear-gradient(90deg, #10b981, #2dd4bf); }
.bar-blue    { background: linear-gradient(90deg, #3b82f6, #22d3ee); }
.bar-rose    { background: linear-gradient(90deg, #f43f5e, #f472b6); }
.bar-amber   { background: linear-gradient(90deg, #f59e0b, #fb923c); }
.bar-violet  { background: linear-gradient(90deg, #8b5cf6, #c084fc); }

.text-emerald { color: #34d399; }
.text-blue    { color: #60a5fa; }
.text-rose    { color: #fb7185; }
.text-amber   { color: #fbbf24; }
.text-violet  { color: #a78bfa; }

.update-chip-emerald { background: rgba(16, 185, 129, 0.15); border: 1px solid rgba(16, 185, 129, 0.3); color: #34d399; }
.update-chip-blue    { background: rgba(59, 130, 246, 0.15); border: 1px solid rgba(59, 130, 246, 0.3); color: #60a5fa; }
.update-chip-rose    { background: rgba(244, 63, 94, 0.15);  border: 1px solid rgba(244, 63, 94, 0.3);  color: #fb7185; }
.update-chip-amber   { background: rgba(245, 158, 11, 0.15); border: 1px solid rgba(245, 158, 11, 0.3); color: #fbbf24; }
.update-chip-violet  { background: rgba(139, 92, 246, 0.15); border: 1px solid rgba(139, 92, 246, 0.3); color: #a78bfa; }

/* Empty State */
.empty-state {
  padding: 2rem 1.5rem;
  text-align: center;
  margin: 1.5rem 0;
}

.empty-icon {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 1rem;
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.25);
  color: #60a5fa;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 0.875rem;
}

/* Floating Bottom Action Bar */
.fab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  pointer-events: none;
  padding-bottom: max(1.5rem, calc(var(--safe-bottom) + 1rem));
}

.fab-inner {
  display: flex;
  justify-content: flex-end;
}

.fab-btn {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 1.25rem;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue), var(--indigo));
  color: #fff;
  font-weight: 600;
  font-size: 0.875rem;
  box-shadow: 0 12px 28px -4px rgba(37, 99, 235, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Toast Notification */
.toast-wrapper {
  position: fixed;
  top: var(--header-top-offset);
  left: 0;
  right: 0;
  z-index: 9999;
  pointer-events: none;
  display: flex;
  justify-content: center;
  padding: 0 1rem;
  opacity: 0;
  transform: translateY(-0.5rem);
  transition: all 0.28s ease;
}

.toast-wrapper.open {
  opacity: 1;
  transform: translateY(0);
}

.toast-pill {
  background: rgba(22, 22, 26, 0.96);
  backdrop-filter: blur(20px);
  padding: 0.625rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
}

/* Modals & Bottom Sheets */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.bottom-sheet {
  background: rgba(22, 22, 26, 0.97);
  backdrop-filter: saturate(190%) blur(30px);
  -webkit-backdrop-filter: saturate(190%) blur(30px);
  width: 100%;
  max-width: 36rem;
  margin: 0 auto;
  border-radius: 1.75rem 1.75rem 0 0;
  border-top: 1px solid var(--border-strong);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: max(1.5rem, calc(var(--safe-bottom) + 0.75rem));
  transform: translateY(100%);
  transition: transform 0.34s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal-backdrop.open .bottom-sheet {
  transform: translateY(0);
}

.sheet-header {
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-shrink: 0;
}

.sheet-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sheet-close-btn {
  padding: 0.45rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: #d4d4d8;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sheet-body {
  overflow-y: auto;
  padding: 1.125rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.125rem;
}

/* Forms & Inputs inside Sheets */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: #d4d4d8;
}

.form-input, .form-select {
  width: 100%;
  border-radius: 0.75rem;
  background: var(--bg-input);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 0.625rem 0.875rem;
  color: #fff;
  outline: none;
  transition: border-color 0.15s ease;
}

.form-input:focus, .form-select:focus {
  border-color: var(--blue);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.625rem;
}

/* Buttons */
.btn-primary {
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 0.75rem;
  background: linear-gradient(90deg, var(--blue), var(--indigo));
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 8px 20px -4px rgba(59, 130, 246, 0.35);
}

.btn-secondary {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e4e4e7;
  font-weight: 600;
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.section-box {
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

/* Check-in Mode Switcher & Presets */
.mode-switch {
  padding: 0.15rem;
  border-radius: 0.5rem;
  background: #18181b;
  border: 1px solid var(--border-subtle);
  display: inline-flex;
}

.mode-btn {
  padding: 0.25rem 0.65rem;
  border-radius: 0.375rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

.mode-btn.active {
  background: var(--blue);
  color: #fff;
  font-weight: 600;
}

.checkin-amount-row {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
}

.checkin-amount-input {
  position: relative;
  flex: 1;
  min-width: 0;
}

.checkin-amount-input .form-input {
  height: 100%;
}

.checkin-amount-input .goal-unit {
  position: absolute;
  top: 50%;
  right: 0.75rem;
  transform: translateY(-50%);
  pointer-events: none;
}

.checkin-direction-control {
  flex: 0 0 auto;
  align-items: stretch;
}

.checkin-direction-control .mode-btn {
  min-width: 2.25rem;
  padding: 0.5rem 0.65rem;
  font-size: 1rem;
  line-height: 1;
}

.preset-chip {
  padding: 0.375rem 0.65rem;
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.75rem;
  font-weight: 600;
}

/* Color Swatches */
.swatch-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.color-swatch {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 999px;
  border: 2px solid transparent;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.color-swatch.active {
  border-color: #fff;
  transform: scale(1.15);
}

/* History Item Row */
.history-item {
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  padding: 0.625rem 0.875rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.alert-box {
  border-radius: 0.75rem;
  padding: 0.65rem 0.875rem;
  font-size: 0.75rem;
  line-height: 1.4;
  border: 1px solid transparent;
}
.alert-error   { background: rgba(244, 63, 94, 0.15); border-color: rgba(244, 63, 94, 0.35); color: #fecdd3; }
.alert-info    { background: rgba(59, 130, 246, 0.12); border-color: rgba(59, 130, 246, 0.3); color: #bfdbfe; }
.alert-success { background: rgba(16, 185, 129, 0.15); border-color: rgba(16, 185, 129, 0.35); color: #a7f3d0; }

/* Role Picker Cards */
.role-card-a, .role-card-b {
  padding: 1.25rem;
  border-radius: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  border: 2px solid transparent;
}
.role-card-a { background: rgba(59, 130, 246, 0.15); border-color: rgba(59, 130, 246, 0.4); }
.role-card-b { background: rgba(236, 72, 153, 0.15); border-color: rgba(236, 72, 153, 0.4); }

.role-avatar {
  width: 3rem;
  height: 3rem;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.125rem;
}