:root {
  --bg: #090d18;
  --surface: #11182a;
  --surface-2: #1b2740;
  --primary: #5a8cff;
  --accent: #5a8cff;
  --secondary: #8c66ff;
  --tertiary: #20d6be;
  --text: #f4f7ff;
  --text-2: #eaf0ff;
  --muted: #a8b2c7;
  --outline: #3c4f75;
  --divider: rgba(255, 255, 255, 0.12);
  --danger: #ff6b7a;
  --ok: #3dd68c;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-bg: color-mix(in srgb, var(--bg) 88%, white 6%);
  --field-h: 48px;
  --font: "SF Pro Display", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --app-height: 100vh;
  --app-height: 100dvh;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: var(--app-height);
  max-height: var(--app-height);
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(90, 140, 255, 0.28), transparent 55%),
    radial-gradient(ellipse 70% 45% at 90% 10%, rgba(140, 102, 255, 0.22), transparent 50%),
    radial-gradient(ellipse 60% 40% at 50% 100%, rgba(32, 214, 190, 0.08), transparent 55%),
    var(--bg);
}

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

a {
  color: var(--primary);
}

#app {
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: var(--safe-top);
}

/* —— Auth —— */
.auth-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 28px 22px calc(28px + var(--safe-bottom));
  max-width: 420px;
  width: 100%;
  margin: 0 auto;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}

.brand img {
  width: 72px;
  height: 72px;
  border-radius: 18px;
}

.brand h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
}

.card {
  background: rgba(17, 24, 42, 0.82);
  border: 1px solid rgba(60, 79, 117, 0.55);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-size: 0.8rem;
  color: var(--muted);
}

.field input,
.field textarea,
.field select {
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--outline);
  background: rgba(9, 13, 24, 0.65);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px; /* iOS: без автозума */
  line-height: 1.25;
  outline: none;
  box-sizing: border-box;
}

/* iOS native date/time controls иначе раздуваются */
.field input[type="date"],
.field input[type="datetime-local"],
.field input[type="time"],
.field input[type="month"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  height: var(--field-h);
  min-height: var(--field-h);
  max-height: var(--field-h);
  padding: 0 14px;
  color-scheme: dark;
}

.field input[type="date"]::-webkit-date-and-time-value,
.field input[type="datetime-local"]::-webkit-date-and-time-value,
.field input[type="time"]::-webkit-date-and-time-value {
  text-align: left;
  height: var(--field-h);
  line-height: var(--field-h);
  margin: 0;
  padding: 0;
}

.field input[type="date"]::-webkit-calendar-picker-indicator,
.field input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  opacity: 0.65;
  margin: 0;
  padding: 0;
}

.field select {
  height: var(--field-h);
  min-height: var(--field-h);
}

.field input:not([type="checkbox"]):not([type="radio"]):not([type="date"]):not([type="datetime-local"]):not([type="time"]) {
  min-height: var(--field-h);
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(90, 140, 255, 0.2);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 14px;
  padding: 13px 18px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  width: 100%;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), rgba(140, 102, 255, 0.92));
  box-shadow: 0 8px 24px rgba(90, 140, 255, 0.28);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  width: 100%;
}

.btn-soft {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid rgba(60, 79, 117, 0.6);
}

.btn-danger {
  background: rgba(255, 107, 122, 0.15);
  color: var(--danger);
}

.error-box {
  background: rgba(255, 107, 122, 0.12);
  border: 1px solid rgba(255, 107, 122, 0.35);
  color: #ffb3bb;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.9rem;
  margin-bottom: 14px;
}

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 16px;
}

/* —— Shell + tab bar (паттерн как в Эзоп) —— */
.app-shell,
.shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-height: 100%;
  overflow: hidden;
}

.main,
.shell-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 16px calc(56px + var(--safe-bottom));
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.page-title {
  margin: 4px 0 16px;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.toolbar .page-title {
  margin: 0;
}

.search {
  width: 100%;
  border: 1px solid var(--outline);
  background: rgba(17, 24, 42, 0.75);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 16px;
  margin-bottom: 14px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.kpi {
  background: rgba(17, 24, 42, 0.85);
  border: 1px solid rgba(60, 79, 117, 0.5);
  border-radius: 14px;
  padding: 14px;
}

.kpi .label {
  color: var(--muted);
  font-size: 0.75rem;
  margin-bottom: 6px;
}

.kpi .value {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.kpi.wide {
  grid-column: 1 / -1;
}

.section {
  margin-top: 18px;
}

.section h2 {
  margin: 0 0 10px;
  font-size: 1rem;
  color: var(--muted);
  font-weight: 600;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  background: rgba(17, 24, 42, 0.85);
  border: 1px solid rgba(60, 79, 117, 0.45);
  border-radius: 14px;
  padding: 14px;
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.list-item:active {
  background: rgba(27, 39, 64, 0.9);
}

.list-item .title {
  font-weight: 600;
  margin-bottom: 4px;
}

.list-item .meta {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space:nowrap;
}

.badge-ok {
  background: rgba(61, 214, 140, 0.15);
  color: var(--ok);
}

.badge-warn {
  background: rgba(255, 196, 87, 0.15);
  color: #ffc457;
}

.badge-muted {
  background: rgba(168, 178, 199, 0.12);
  color: var(--muted);
}

.badge-info {
  background: rgba(90, 140, 255, 0.15);
  color: var(--primary);
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 36px 12px;
}

.loading {
  display: grid;
  place-items: center;
  padding: 48px 12px;
  color: var(--muted);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(90, 140, 255, 0.25);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-bottom: 10px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  /* safe-area уже место под home indicator — без лишних +10px снизу */
  padding: 6px 6px var(--safe-bottom);
  background: var(--tabbar-bg);
  border: none;
  border-top: 1px solid var(--divider);
  border-radius: 0;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: none;
}

.tabbar a,
.tabbar .tab {
  text-decoration: none;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  padding: 6px 2px;
  border-radius: 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  -webkit-tap-highlight-color: transparent;
}

.tabbar a svg,
.tabbar .tab svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.tabbar a span,
.tabbar .tab span {
  line-height: 1.1;
  letter-spacing: -0.01em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabbar a.active,
.tabbar .tab.active {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.tabbar a .tab-badge,
.tabbar .tab .tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  margin-left: 2px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 16px;
}

.cal-day {
  aspect-ratio: 1;
  border: 1px solid rgba(60, 79, 117, 0.45);
  background: rgba(17, 24, 42, 0.7);
  border-radius: 10px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.85rem;
  cursor: pointer;
}

.cal-day.has-events {
  border-color: rgba(90, 140, 255, 0.55);
  background: rgba(90, 140, 255, 0.12);
}

.cal-day i {
  font-style: normal;
  font-size: 0.65rem;
  color: var(--primary);
  font-weight: 700;
}

.ok-box {
  background: rgba(61, 214, 140, 0.12) !important;
  border-color: rgba(61, 214, 140, 0.35) !important;
  color: #9aecc0 !important;
}

.auth-links {
  margin-top: 4px;
}

/* —— Modal (bottom sheet) —— */
body.sheet-open {
  overflow: hidden;
  overscroll-behavior: none;
}

body.sheet-open .main,
body.sheet-open .shell-content {
  overflow: hidden !important;
  touch-action: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: auto;
}

.modal {
  width: min(480px, 100%);
  max-height: calc(100svh - max(12px, var(--safe-top)) - 8px);
  max-height: calc(100dvh - max(12px, var(--safe-top)) - 8px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--outline);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  padding: 0;
  animation: sheet-up 0.22s ease;
  box-sizing: border-box;
}

.modal-grab {
  flex: 0 0 auto;
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: rgba(168, 178, 199, 0.45);
  margin: 10px auto 0;
}

.modal-sheet {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px 18px calc(18px + var(--safe-bottom));
}

@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

.modal h3 {
  margin: 0 0 14px;
  font-size: 1.15rem;
  position: sticky;
  top: 0;
  background: var(--surface);
  padding-bottom: 4px;
  z-index: 1;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--surface) 70%, transparent);
  padding-top: 10px;
  padding-bottom: 2px;
}

.modal-actions .btn {
  flex: 1;
}

.row-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.install-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  top: calc(10px + var(--safe-top));
  z-index: 60;
  background: rgba(17, 24, 42, 0.96);
  border: 1px solid rgba(90, 140, 255, 0.4);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.install-banner h4 {
  margin: 0 0 6px;
  font-size: 0.95rem;
}

.install-banner p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.install-banner .share {
  color: var(--primary);
  font-weight: 700;
}

.npd-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(60, 79, 117, 0.5);
  overflow: hidden;
  margin-top: 8px;
}

.npd-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--tertiary), var(--primary));
  border-radius: 999px;
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
}

.chip {
  border: 1px solid var(--outline);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.chip.active {
  background: rgba(90, 140, 255, 0.2);
  border-color: rgba(90, 140, 255, 0.55);
  color: var(--text);
}

.money-pos { color: var(--ok); }
.money-neg { color: var(--danger); }

.more-list a,
.more-list button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
  background: rgba(17, 24, 42, 0.85);
  border: 1px solid rgba(60, 79, 117, 0.45);
  border-radius: 14px;
  color: var(--text);
  text-decoration: none;
  margin-bottom: 8px;
  cursor: pointer;
  text-align: left;
  font-size: 1rem;
}

.splash {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
}

.splash img {
  width: 88px;
  height: 88px;
  border-radius: 22px;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.04); opacity: 0.85; }
}

@media (display-mode: standalone) {
  .install-banner { display: none !important; }
}
