/* shadcn-подібна тема: фон сторінки, картки, primary як у попередньому React-панелі */
:root {
  --background: 210 17% 95%;
  --foreground: 220 15% 18%;
  --card: 0 0% 100%;
  --card-foreground: 220 15% 18%;
  --primary: 211 100% 50%;
  --primary-foreground: 0 0% 100%;
  --secondary: 210 14% 93%;
  --secondary-foreground: 220 15% 28%;
  --muted: 210 14% 92%;
  --muted-foreground: 215 12% 48%;
  --accent: 211 55% 94%;
  --accent-foreground: 211 90% 38%;
  --destructive: 0 72% 51%;
  --border: 214 18% 86%;
  --input: 214 18% 86%;
  --ring: 211 100% 50%;
  --radius: 0.75rem;
  --radius-sm: 0.5rem;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --shadow-sm: 0 1px 2px 0 rgb(15 23 42 / 0.05);
  --shadow-card: 0 1px 3px 0 rgb(15 23 42 / 0.06), 0 1px 2px -1px rgb(15 23 42 / 0.06);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  color: hsl(var(--foreground));
  background: hsl(var(--background));
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100dvh;
  padding-bottom: max(0.75rem, var(--safe-bottom));
}

/* Шапка: повна ширина, контент по центру як max-w-lg */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: hsl(var(--card));
  border-bottom: 1px solid hsl(var(--border));
  box-shadow: var(--shadow-sm);
}

.app-header-inner {
  max-width: 32rem;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.75rem 1rem;
  min-height: 3.25rem;
}

.header-brand-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: hsl(var(--primary));
}

.header-brand-icon svg {
  width: 1.25rem;
  height: 1.25rem;
}

.app-header h1 {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.app-header .count {
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: none;
  background: transparent;
  color: hsl(var(--primary));
  border-radius: var(--radius-sm);
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: hsl(var(--accent));
}

.icon-btn:active {
  background: hsl(var(--accent));
  opacity: 0.9;
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Контент під шапкою */
.page-inner {
  max-width: 32rem;
  margin: 0 auto;
  padding: 0.75rem;
}

/* Пошук */
.search-wrap {
  position: relative;
  margin-bottom: 0.75rem;
}

.search-icon-svg {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  color: hsl(var(--muted-foreground));
  pointer-events: none;
}

.search-input {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.625rem 0.875rem 0.625rem 2.625rem;
  font-size: 0.9375rem;
  font-family: inherit;
  color: hsl(var(--foreground));
  background: hsl(var(--card));
  border: 1px solid hsl(var(--input));
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-input::placeholder {
  color: hsl(var(--muted-foreground));
}

.search-input:focus {
  outline: none;
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.18);
}

/* Список */
.list {
  background: hsl(var(--card));
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border));
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 3.5rem;
  padding: 0.75rem 1rem;
  border: none;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  font: inherit;
  color: inherit;
  transition: background 0.12s ease;
}

.list-item:last-child {
  border-bottom: none;
}

.list-item:hover {
  background: hsl(var(--accent) / 0.45);
}

.list-item:active {
  background: hsl(var(--accent) / 0.65);
}

.list-avatar {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 9999px;
  background: hsl(var(--primary) / 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  color: hsl(var(--primary));
}

.list-avatar svg {
  width: 1.125rem;
  height: 1.125rem;
}

.list-body {
  flex: 1;
  min-width: 0;
}

.list-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.list-title .muted {
  font-weight: 400;
  color: hsl(var(--muted-foreground));
}

.list-sub {
  margin: 0.125rem 0 0;
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-chev {
  flex-shrink: 0;
  display: flex;
  color: hsl(var(--muted-foreground));
  opacity: 0.55;
}

.list-chev svg {
  width: 1.125rem;
  height: 1.125rem;
}

.empty {
  text-align: center;
  padding: 2.5rem 1rem;
  font-size: 0.9375rem;
  color: hsl(var(--muted-foreground));
}

.error-box {
  padding: 1.25rem;
  background: hsl(var(--card));
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border));
  box-shadow: var(--shadow-card);
  color: hsl(var(--destructive));
  font-size: 0.9375rem;
}

/* Налаштування */
.settings {
  padding-bottom: 0.5rem;
}

.settings-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  margin-bottom: 0.75rem;
  background: hsl(var(--card));
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border));
  box-shadow: var(--shadow-sm);
}

.settings-header .back {
  flex-shrink: 0;
}

.settings-header .meta h2 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.settings-header .meta p {
  margin: 0.2rem 0 0;
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.block {
  background: hsl(var(--card));
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border));
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.block-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid hsl(var(--border));
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: hsl(var(--muted-foreground));
  background: hsl(var(--muted) / 0.35);
}

.block-head svg {
  width: 1rem;
  height: 1rem;
  color: hsl(var(--primary));
  flex-shrink: 0;
}

.block-body {
  padding: 1rem;
}

.field {
  margin-bottom: 1rem;
}

.field:last-child {
  margin-bottom: 0;
}

.field-label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
}

.field-label.highlight {
  color: hsl(var(--primary));
}

.field-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.field input[type="text"],
.field input[type="password"] {
  flex: 1;
  min-width: 0;
  min-height: 2.75rem;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  color: hsl(var(--foreground));
  background: hsl(var(--secondary));
  border: 1px solid hsl(var(--input));
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.field input:focus {
  outline: none;
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.15);
  background: hsl(var(--card));
}

.field input.hl {
  background: hsl(var(--card));
  border-color: hsl(var(--primary) / 0.45);
  box-shadow: 0 0 0 1px hsl(var(--primary) / 0.25);
}

.field .suffix {
  flex-shrink: 0;
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
  font-variant-numeric: tabular-nums;
}

.field-shell {
  padding: 0.5rem 0.625rem;
  margin: 0 -0.625rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s, box-shadow 0.15s;
}

.field-shell.dirty {
  background: hsl(var(--primary) / 0.06);
  box-shadow: inset 0 0 0 2px hsl(var(--primary) / 0.32);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 2.75rem;
  gap: 0.75rem;
}

.toggle-row span {
  font-size: 0.9375rem;
  font-weight: 500;
}

/* Перемикач */
.switch {
  position: relative;
  width: 3rem;
  height: 1.625rem;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  inset: 0;
  background: hsl(var(--muted-foreground) / 0.35);
  border-radius: 9999px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.switch-slider::before {
  content: "";
  position: absolute;
  width: 1.25rem;
  height: 1.25rem;
  left: 0.1875rem;
  top: 50%;
  transform: translateY(-50%);
  background: hsl(var(--card));
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease;
}

.switch input:checked + .switch-slider {
  background: hsl(var(--primary));
}

.switch input:checked + .switch-slider::before {
  transform: translateY(-50%) translateX(1.25rem);
}

.actions {
  display: flex;
  gap: 0.625rem;
  padding: 0.75rem 0 0;
}

.btn {
  flex: 1;
  min-height: 2.75rem;
  padding: 0 1rem;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-outline {
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  border: 1px solid hsl(var(--input));
  box-shadow: var(--shadow-sm);
}

.btn-outline:hover:not(:disabled) {
  background: hsl(var(--accent) / 0.5);
}

.btn-primary {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(0.96);
}

.btn-primary:active:not(:disabled) {
  filter: brightness(0.92);
}

/* Тост */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(5rem, calc(var(--safe-bottom) + 4rem));
  transform: translateX(-50%);
  max-width: min(22rem, calc(100% - 2rem));
  padding: 0.625rem 1rem;
  background: hsl(220 15% 18% / 0.94);
  color: hsl(0 0% 98%);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
  z-index: 100;
}

.toast[hidden] {
  display: none;
}

.spin {
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.skeleton {
  height: 3.5rem;
  margin-bottom: 0.5rem;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border));
  background: linear-gradient(
    90deg,
    hsl(var(--muted)) 0%,
    hsl(var(--secondary)) 50%,
    hsl(var(--muted)) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.1s ease-in-out infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spin,
  .skeleton {
    animation: none;
  }
}
