:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --text: var(--tg-theme-text-color, #f5f5f7);
  --hint: var(--tg-theme-hint-color, #8e9aab);
  --link: var(--tg-theme-link-color, #6ab7ff);
  --btn: var(--tg-theme-button-color, #3390ec);
  --btn-text: var(--tg-theme-button-text-color, #fff);
  --secondary: var(--tg-theme-secondary-bg-color, #232e3c);
  --radius: 14px;
  --radius-sm: 10px;
  --bottom-nav-h: 56px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  padding: 0;
  padding-top: env(safe-area-inset-top, 0);
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 12px));
}

.app-header {
  padding: 12px 16px 10px;
  flex-shrink: 0;
}

.app-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.app-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-sub {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: var(--hint);
  line-height: 1.35;
}

.btn-icon {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  margin: -6px -8px 0 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--link);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:active {
  opacity: 0.75;
  background: rgba(255, 255, 255, 0.06);
}

.filter-strip {
  margin-top: 10px;
}

.filter-strip.filter-strip--hidden {
  display: none;
}

.filter-select {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--secondary);
  color: var(--text);
  font-size: 0.92rem;
}

.main-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 4px 14px 16px;
  -webkit-overflow-scrolling: touch;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: stretch;
  gap: 2px;
  padding: 6px 10px calc(10px + env(safe-area-inset-bottom, 0));
  background: var(--secondary);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  z-index: 60;
}

.bottom-tab {
  flex: 1;
  min-width: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--hint);
  padding: 6px 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-family: inherit;
}

.bottom-tab.active {
  color: var(--link);
  background: rgba(106, 183, 255, 0.12);
}

.bottom-tab-icon {
  font-size: 1rem;
  line-height: 1;
  opacity: 0.95;
}

.bottom-tab-plus {
  font-size: 1.35rem;
  font-weight: 300;
  margin-bottom: -2px;
}

.bottom-tab-label {
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.surface {
  background: var(--secondary);
  border-radius: var(--radius);
  padding: 14px 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.surface-spaced {
  margin-top: 12px;
}

.surface-muted {
  opacity: 0.97;
}

.surface-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.surface-head-wrap {
  flex-wrap: wrap;
}

.surface-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.chip {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(106, 183, 255, 0.14);
  color: var(--link);
  flex-shrink: 0;
}

.tz-badge {
  font-size: 0.72rem;
  color: var(--hint);
  font-weight: 600;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.micro-hint {
  margin: -4px 0 12px;
  font-size: 0.76rem;
  color: var(--hint);
  line-height: 1.35;
}

.period-caption {
  margin: 12px 0 8px;
  font-size: 0.8rem;
  color: var(--hint);
  font-weight: 650;
}

.date-range-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: end;
}

.date-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.date-cell-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.date-input {
  width: 100%;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.15);
  color: var(--text);
  font-size: 0.85rem;
}

.date-range-arrow {
  color: var(--hint);
  padding-bottom: 12px;
  font-size: 0.85rem;
  text-align: center;
}

.btn-range-submit {
  margin-top: 12px;
}

.list-tight {
  gap: 8px;
}

.hint-tight {
  margin-top: 10px;
  margin-bottom: 0;
}

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-weight: 650;
  font-size: 0.92rem;
  cursor: pointer;
  background: var(--btn);
  color: var(--btn-text);
  font-family: inherit;
}

.btn.fill {
  width: 100%;
}

.btn.primary {
  background: var(--btn);
  color: var(--btn-text);
}

.btn.ghost {
  background: transparent;
  color: var(--link);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.btn.danger.ghost {
  color: #ff9a9a;
  border-color: rgba(255, 140, 140, 0.45);
}

.compact-form .field {
  margin-bottom: 12px;
}

.field-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.field-grow {
  flex: 1;
  min-width: 0;
}

.field-narrow {
  width: 88px;
  flex-shrink: 0;
}

.datetime-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.dt-picker {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.15);
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
}

.hint-under-field {
  display: block;
  font-size: 0.78rem;
  color: var(--hint);
  margin-top: 4px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}

.field-narrow-inline {
  max-width: 160px;
}

.saved-toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 12px) + 56px);
  z-index: 400;
  max-width: min(92vw, 360px);
  padding: 12px 22px;
  border-radius: 999px;
  background: rgba(42, 115, 72, 0.96);
  color: #dff7e6;
  font-size: 0.92rem;
  font-weight: 650;
  text-align: center;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.38);
  pointer-events: none;
}

.saved-toast.hidden {
  display: none;
}

.field-flat {
  margin-bottom: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 0.72rem;
  font-weight: 650;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.muted-small {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}

.field input,
.field select,
.field textarea {
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.15);
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
}

.field textarea {
  resize: vertical;
  min-height: 64px;
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
}

.row-inline {
  flex-direction: row;
  align-items: center;
  gap: 12px;
}

.row-inline input[type="checkbox"] {
  width: auto;
  transform: scale(1.15);
}

.advanced-block {
  margin: 8px 0 14px;
  border-radius: var(--radius-sm);
  border: 1px dashed rgba(255, 255, 255, 0.12);
  padding: 8px 10px;
}

.advanced-summary {
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--hint);
}

.advanced-block[open] .advanced-summary {
  margin-bottom: 8px;
}

.json-hint-inline {
  margin: 8px 0 0;
  font-size: 0.72rem;
  color: var(--hint);
  line-height: 1.35;
}

.json-hint-inline code {
  font-size: 0.68rem;
  word-break: break-all;
  color: var(--text);
}

.bot-hint-line {
  margin-top: 10px;
  text-align: center;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  background: rgba(0, 0, 0, 0.18);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.card-clickable {
  cursor: pointer;
  transition: background 0.12s ease, transform 0.08s ease;
}

.card-clickable:active {
  transform: scale(0.99);
  background: rgba(106, 183, 255, 0.08);
}

.card-title {
  font-weight: 650;
  margin: 0 0 6px;
  font-size: 0.95rem;
  line-height: 1.25;
}

.card-time {
  font-size: 0.86rem;
  color: var(--text);
  opacity: 0.92;
  margin: 0;
}

.badge {
  display: inline-block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(106, 183, 255, 0.18);
  color: var(--link);
  margin-right: 6px;
  vertical-align: middle;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal-sheet {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: min(92vh, 640px);
  overflow-y: auto;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(22px + env(safe-area-inset-bottom, 0));
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.35);
}

.modal-title {
  margin: 0 0 14px;
  font-size: 1.08rem;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
}

.modal-actions-row {
  justify-content: flex-start;
  flex-wrap: wrap;
  align-items: center;
}

.modal-actions-spacer {
  flex: 1;
  min-width: 8px;
}

.hint {
  font-size: 0.82rem;
  color: #e29a4a;
}

.empty {
  text-align: center;
  color: var(--hint);
  padding: 22px 12px;
  font-size: 0.88rem;
  line-height: 1.45;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.error-bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 12px) + 8px);
  max-width: 496px;
  margin: 0 auto;
  padding: 12px 14px;
  background: #3d2424;
  color: #ffb4b4;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  z-index: 150;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

.error-bar.hidden {
  display: none;
}

@media (min-width: 480px) {
  .modal {
    align-items: center;
    padding: 24px;
  }

  .modal-sheet {
    border-radius: var(--radius);
    padding-bottom: 22px;
  }
}
