:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #f3f5f8);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #172033);
  --muted: var(--tg-theme-hint-color, #718096);
  --accent: var(--tg-theme-button-color, #3b6ef5);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #d64545;
  --border: color-mix(in srgb, var(--muted) 22%, transparent);
  --soft-accent: color-mix(in srgb, var(--accent) 12%, var(--surface));
  --soft-surface: color-mix(in srgb, var(--surface) 86%, var(--bg));
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { min-height: 100vh; margin: 0; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
svg { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.9; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(20px + env(safe-area-inset-top)) 18px 14px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(22px);
}
.eyebrow { color: var(--accent); font-size: 12px; font-weight: 750; text-transform: uppercase; letter-spacing: .12em; }
h1, h2, p { margin: 0; }
h1 { margin-top: 3px; font-size: 25px; line-height: 1.15; letter-spacing: -.025em; }
h2 { font-size: 17px; }
main { max-width: 760px; margin: 0 auto; padding: 8px 14px 110px; }
.loading-indicator {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  z-index: 8;
  transform: translate(-50%, -16px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 12px;
  color: var(--muted);
  background: var(--surface);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--text) 8%, transparent);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: .18s ease-out;
}
.loading-indicator.visible { transform: translate(-50%, 0); opacity: 1; }
.view { display: none; }
.view.active { display: block; animation: appear .18s ease-out; }
@keyframes appear { from { opacity: .4; transform: translateY(4px); } }

.metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.card, .metric, .entry, .setting, .banner {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 8px 28px color-mix(in srgb, var(--text) 5%, transparent);
}
.metric { min-height: 104px; padding: 16px; display: flex; flex-direction: column; justify-content: space-between; }
.metric strong { font-size: 28px; }
.metric.danger strong { color: var(--danger); }
.muted, .metric span, .task-meta, .entry-meta { color: var(--muted); font-size: 13px; }
.banner { margin-bottom: 12px; padding: 12px 14px; font-size: 14px; }
.banner.warning { border-color: color-mix(in srgb, #d69e2e 50%, transparent); }
.section-heading { display: flex; align-items: center; justify-content: space-between; margin: 24px 2px 10px; }
.link-button, .icon-button { border: 0; color: var(--accent); background: transparent; }
.icon-button { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 14px; background: var(--soft-accent); }
.icon-button svg { width: 21px; height: 21px; }
.icon-button:active { transform: scale(.96); }

.task-list, .entry-list, .settings-list, .user-list { display: grid; gap: 10px; }
.task {
  position: relative;
  display: block;
  overflow: hidden;
  padding: 15px 16px 15px 18px;
  border: 1px solid var(--border);
  border-radius: 16px;
  color: inherit;
  background: var(--surface);
  box-shadow: 0 8px 28px color-mix(in srgb, var(--text) 5%, transparent);
  text-decoration: none;
}
.task::before { content: ""; position: absolute; inset: 13px auto 13px 0; width: 3px; border-radius: 0 4px 4px 0; background: var(--accent); }
.task:active { transform: scale(.99); background: var(--soft-surface); }
.task-title { margin: 10px 0 8px; font-size: 15px; font-weight: 720; line-height: 1.38; }
.task-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.badge { border-radius: 999px; padding: 4px 8px; background: var(--soft-accent); color: var(--accent); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.badge.bitrix24 { color: #1f78d1; background: color-mix(in srgb, #1f78d1 13%, transparent); }
.due { color: var(--muted); font-size: 12px; font-weight: 650; }
.due.overdue { color: var(--danger); font-weight: 700; }
.empty { padding: 30px 14px; text-align: center; color: var(--muted); }

.filters { display: grid; gap: 12px; margin-bottom: 14px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface);
  color: var(--text);
}
.search-field { position: relative; display: block; }
.search-field svg { position: absolute; top: 50%; left: 14px; width: 19px; height: 19px; color: var(--muted); transform: translateY(-50%); pointer-events: none; }
.search-field input { height: 48px; padding: 12px 42px; border-radius: 15px; background: var(--surface); outline: none; }
.search-field input:focus { border-color: color-mix(in srgb, var(--accent) 65%, transparent); box-shadow: 0 0 0 3px var(--soft-accent); }
.search-field input::-webkit-search-cancel-button { opacity: .65; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 4px; border-radius: 14px; background: var(--soft-surface); }
.segmented button { border: 0; border-radius: 10px; padding: 9px 4px; color: var(--muted); background: transparent; font-size: 13px; font-weight: 650; }
.segmented button.selected { color: var(--accent); background: var(--surface); box-shadow: 0 2px 8px color-mix(in srgb, var(--text) 8%, transparent); }
.task-toolbar { display: flex; align-items: center; justify-content: space-between; min-height: 34px; padding: 0 2px; }
.result-count { color: var(--muted); font-size: 13px; font-weight: 650; }
.select-field { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.select-field select { width: auto; min-width: 74px; border: 0; padding: 5px 22px 5px 5px; color: var(--text); background: transparent; font-size: 13px; font-weight: 700; appearance: none; }
.select-field svg { width: 15px; height: 15px; margin-left: -24px; color: var(--muted); pointer-events: none; }

.time-summary { display: flex; align-items: center; justify-content: space-between; padding: 14px; }
.time-summary strong { display: block; margin-top: 4px; font-size: 24px; }
.time-summary input { width: auto; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-top: 12px; }
.day { min-height: 54px; padding: 6px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); font-size: 12px; }
.day.outside { opacity: .3; }
.day strong { display: block; margin-top: 8px; color: var(--accent); font-size: 11px; }
.entry { padding: 12px 14px; }
.entry strong { display: block; margin-bottom: 5px; }
.primary-button { width: 100%; margin-top: 16px; border: 0; border-radius: 13px; padding: 13px; color: var(--accent-text); background: var(--accent); font-weight: 750; }
#time-view > .primary-button { position: sticky; bottom: 82px; box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 28%, transparent); }

.setting { display: flex; align-items: center; justify-content: space-between; padding: 14px; }
.admin-search { margin-bottom: 12px; }
.user-card { padding: 15px; }
.user-heading, .user-actions, .user-connections { display: flex; align-items: center; gap: 8px; }
.user-heading { justify-content: space-between; }
.user-id { font-size: 15px; font-weight: 750; }
.user-details { display: grid; gap: 6px; margin-top: 10px; color: var(--muted); font-size: 12px; }
.user-connections { flex-wrap: wrap; }
.user-actions { justify-content: flex-end; margin-top: 12px; }
.danger-button, .secondary-button {
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 8px 12px;
  background: transparent;
  font-size: 12px;
  font-weight: 700;
}
.danger-button { border-color: color-mix(in srgb, var(--danger) 35%, transparent); color: var(--danger); }
.secondary-button { color: var(--accent); }
.status.blocked { color: var(--danger); }
.status { color: var(--danger); font-size: 13px; font-weight: 700; }
.status.connected { color: #278a58; }
.switch { position: relative; width: 46px; height: 26px; border: 0; border-radius: 99px; background: var(--border); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: white; transition: transform .18s; }
.switch.enabled { background: var(--accent); }
.switch.enabled::after { transform: translateX(20px); }

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(62px, 1fr));
  gap: 3px;
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(22px);
}
.bottom-nav button { position: relative; display: grid; justify-items: center; gap: 3px; border: 0; border-radius: 12px; padding: 7px 2px 6px; color: var(--muted); background: transparent; font-size: 11px; }
.bottom-nav button svg { width: 20px; height: 20px; }
.bottom-nav button.selected { color: var(--accent); background: var(--soft-accent); font-weight: 750; }
.nav-badge { position: absolute; top: 2px; left: calc(50% + 7px); min-width: 17px; border: 2px solid var(--surface); border-radius: 999px; padding: 1px 4px; color: white; background: var(--danger); font-size: 9px; font-weight: 800; }

dialog { width: min(92vw, 460px); border: 1px solid var(--border); border-radius: 20px; padding: 0; color: var(--text); background: var(--surface); }
dialog::backdrop { background: rgba(10, 18, 35, .5); backdrop-filter: blur(3px); }
dialog form { display: grid; gap: 13px; padding: 18px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.toast { position: fixed; left: 50%; bottom: 90px; z-index: 10; transform: translateX(-50%) translateY(20px); max-width: 90vw; padding: 11px 15px; border-radius: 12px; color: white; background: #172033; opacity: 0; pointer-events: none; transition: .2s; }
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 680px) {
  .metrics { grid-template-columns: repeat(4, 1fr); }
  .filters { grid-template-columns: minmax(220px, 1fr) auto; align-items: center; }
  .task-toolbar { grid-column: 1 / -1; }
  .bottom-nav { right: 50%; left: auto; width: min(760px, 100%); transform: translateX(50%); }
}
