:root {
  --bg: var(--tg-theme-bg-color, #f4f5f7);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #141414);
  --muted: var(--tg-theme-hint-color, #74777d);
  --accent: var(--tg-theme-button-color, #168acd);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #168acd);
  --border: color-mix(in srgb, var(--text) 12%, transparent);
  --danger: #c73e45;
  --positive: #238b57;
  --warning-bg: #fff4d6;
  --warning-text: #7b5700;
  --radius: 18px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { padding: env(safe-area-inset-top) env(safe-area-inset-right) calc(92px + env(safe-area-inset-bottom)) env(safe-area-inset-left); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.app { width: min(780px, 100%); margin: 0 auto; transition: padding .18s ease; }
.topbar { position: sticky; top: 0; z-index: 10; padding: 16px 16px 10px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(18px); }
.title-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 8px; }
h1 { margin: 0; font-size: 28px; letter-spacing: -0.03em; }
.summary { margin: 3px 0 0; color: var(--muted); font-size: 14px; }
.icon-button { width: 42px; height: 42px; border: 0; border-radius: 50%; background: var(--surface); display: grid; place-items: center; }
.density-button { min-height: 42px; border: 0; border-radius: 12px; padding: 0 12px; background: var(--surface); color: var(--link); font-size: 14px; font-weight: 700; }
.icon-button svg, .search svg { width: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.search { margin-top: 14px; height: 44px; display: flex; align-items: center; gap: 9px; padding: 0 13px; border-radius: 13px; background: var(--surface); }
.search svg { color: var(--muted); flex: 0 0 auto; }
.search input { min-width: 0; flex: 1; border: 0; outline: 0; background: transparent; font-size: 16px; }
.search button { border: 0; background: transparent; color: var(--muted); font-size: 24px; display: none; }
.search.has-value button { display: block; }
.tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; padding: 4px 16px 10px; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button, .filter-chip { white-space: nowrap; border: 0; border-radius: 12px; padding: 9px 8px; background: var(--surface); color: var(--muted); font-weight: 650; }
.tabs button { min-width: 0; min-height: 40px; font-size: 14px; }
.tabs button.active { background: var(--accent); color: var(--accent-text); }
.tabs span, .filter-chip span { font-variant-numeric: tabular-nums; opacity: .75; }
.filters { display: flex; gap: 8px; padding: 0 16px 12px; overflow-x: auto; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters select { min-height: 40px; max-width: 190px; border: 0; outline: 0; border-radius: 12px; padding: 9px 32px 9px 12px; background: var(--surface); color: var(--muted); font-size: 14px; font-weight: 600; }
.filter-chip { min-height: 40px; font-size: 14px; }
.filter-chip.active { background: var(--danger); color: #fff; }
.content { padding: 0 12px 20px; }
.day-group { margin: 8px 0 20px; }
.group-title { display: flex; justify-content: space-between; align-items: baseline; padding: 0 7px 8px; }
.group-title h2 { margin: 0; font-size: 17px; }
.group-title span { color: var(--muted); font-size: 13px; }
.project-group { margin: 0 0 13px; }
.area-title { margin: 15px 8px 7px 44px; color: var(--text); font-size: 14px; }
.project-title { margin: 0 8px 7px 44px; color: var(--muted); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .035em; }
.task-card { display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: start; padding: 14px 14px 14px 10px; margin-bottom: 7px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: 0 1px 0 rgba(0,0,0,.02); }
.task-card:active { transform: scale(.996); }
.task-card.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.check { width: 24px; height: 24px; margin: 0; accent-color: var(--accent); outline-offset: 7px; }
.task-main { min-width: 0; }
.task-title { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 7px; color: var(--muted); font-size: 13px; }
.meta-time { color: var(--text); font-weight: 600; }
.badge { display: inline-flex; align-items: center; padding: 2px 7px; border-radius: 999px; background: color-mix(in srgb, var(--accent) 9%, var(--surface)); color: var(--link); font-size: 12px; font-weight: 650; }
.badge.personal { color: #8b4fa2; background: color-mix(in srgb, #a855c4 10%, var(--surface)); }
.badge.client { color: #2b6e51; background: color-mix(in srgb, #2d966a 10%, var(--surface)); }
.badge.overdue { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, var(--surface)); }
.open-task { align-self: center; width: 40px; height: 40px; border: 0; background: transparent; color: var(--muted); font-size: 24px; line-height: 1; padding: 0; }
.task-card.active-task, .task-card.keyboard-active { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 18%, transparent); }
.compact .task-card { min-height: 60px; padding: 8px 8px; margin-bottom: 4px; border-radius: 13px; align-items: center; }
.compact .task-title { font-size: 15px; line-height: 1.25; }
.compact .task-meta { margin-top: 3px; gap: 3px 8px; }
.compact .badge { padding: 1px 6px; }
.compact .project-title { margin-bottom: 4px; }
.compact .project-group { margin-bottom: 8px; }
.empty, .error-state { margin: 30px 16px; padding: 34px 22px; text-align: center; border-radius: var(--radius); background: var(--surface); }
.empty-mark { width: 48px; height: 48px; margin: 0 auto 12px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--positive) 12%, var(--surface)); color: var(--positive); font-size: 26px; }
.empty h2, .error-state h2 { margin: 0 0 6px; font-size: 19px; }
.empty p, .error-state p { margin: 0 0 18px; color: var(--muted); }
.skeleton { height: 86px; margin: 8px 0; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface), color-mix(in srgb, var(--surface) 70%, var(--bg)), var(--surface)); background-size: 220% 100%; animation: pulse 1.3s infinite; }
@keyframes pulse { to { background-position: -220% 0; } }
.bulkbar { position: fixed; left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 20; max-width: 750px; margin: auto; padding: 11px; border: 1px solid var(--border); border-radius: 20px; background: color-mix(in srgb, var(--surface) 96%, transparent); box-shadow: 0 14px 42px rgba(0,0,0,.2); backdrop-filter: blur(18px); }
.bulk-head { display: flex; justify-content: space-between; padding: 0 3px 9px; font-size: 14px; }
.bulk-head button { border: 0; background: transparent; color: var(--link); }
.bulk-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.bulk-actions button { min-height: 42px; border: 0; border-radius: 11px; background: var(--bg); font-size: 13px; font-weight: 700; }
.bulk-actions .positive { color: var(--positive); }
.bulk-actions .danger { color: var(--danger); }
dialog { color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.38); backdrop-filter: blur(2px); }
.sheet { width: min(780px, 100%); height: min(92vh, 900px); max-width: none; max-height: none; margin: auto auto 0; padding: 0; border: 0; border-radius: 24px 24px 0 0; background: var(--bg); }
.sheet[open] { animation: rise .2s ease-out; }
@keyframes rise { from { transform: translateY(16px); opacity: .7; } }
.sheet form { height: 100%; display: flex; flex-direction: column; }
.sheet-handle { width: 38px; height: 4px; margin: 8px auto 2px; border-radius: 4px; background: var(--border); }
.sheet-header { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 10px 15px; border-bottom: 1px solid var(--border); }
.sheet-header button:last-child { justify-self: end; }
.text-button { padding: 8px 0; border: 0; background: transparent; color: var(--muted); }
.text-button.accent { color: var(--link); font-weight: 700; }
.notice { margin: 12px 15px 0; padding: 11px 13px; border-radius: 12px; background: var(--warning-bg); color: var(--warning-text); font-size: 13px; line-height: 1.35; }
.form-body { flex: 1; overflow-y: auto; padding: 14px 15px calc(30px + env(safe-area-inset-bottom)); }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field span { color: var(--muted); font-size: 12px; font-weight: 650; }
.field input, .field textarea, .field select { width: 100%; border: 1px solid var(--border); border-radius: 12px; outline: none; padding: 11px 12px; background: var(--surface); font-size: 16px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.field-title textarea { font-size: 20px; font-weight: 700; line-height: 1.3; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.detail-section, .source-details { margin: 17px 0 0; padding-top: 15px; border-top: 1px solid var(--border); }
.detail-section h3 { margin: 0 0 10px; font-size: 15px; }
.attachment { display: grid; gap: 7px; padding: 11px; margin-bottom: 7px; border-radius: 12px; background: var(--surface); }
.attachment-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.attachment-head button, .link-actions button { min-height: 40px; border: 0; border-radius: 10px; padding: 0 11px; background: var(--bg); color: var(--link); font-weight: 650; }
.attachment a { color: var(--link); font-weight: 650; text-decoration: none; overflow-wrap: anywhere; }
.attachment-meta { margin-top: 3px; color: var(--muted); font-size: 12px; }
.attachment audio, .attachment video, .attachment img { width: 100%; max-height: 360px; border-radius: 10px; }
.source-details summary { cursor: pointer; color: var(--link); font-weight: 650; }
.source-details pre { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); font: 14px/1.45 -apple-system, BlinkMacSystemFont, sans-serif; }
.source-details a, .link-item > a { color: var(--link); overflow-wrap: anywhere; }
.link-item { display: grid; gap: 8px; padding: 11px; margin-bottom: 7px; border-radius: 12px; background: var(--surface); }
.link-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.link-actions .route-button { background: var(--accent); color: var(--accent-text); }
.task-actions { position: sticky; bottom: 0; padding: 16px 0 4px; background: linear-gradient(transparent, var(--bg) 18%); }
.task-actions button { width: 100%; }
.compact-dialog { width: min(92vw, 440px); padding: 22px; border: 0; border-radius: 20px; background: var(--surface); }
.compact-dialog h2 { margin: 0 0 18px; font-size: 20px; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 18px; }
.send-options { display: grid; gap: 8px; }
.send-options button { min-height: 44px; border: 0; border-radius: 12px; background: var(--bg); color: var(--text); font-weight: 700; text-align: left; padding: 0 14px; }
.full-button { width: 100%; margin-top: 12px; }
.primary-button, .secondary-button, .danger-button { min-height: 44px; border: 0; border-radius: 12px; padding: 0 15px; font-weight: 700; }
.primary-button { background: var(--accent); color: var(--accent-text); }
.secondary-button { background: var(--bg); }
.danger-button { background: var(--danger); color: #fff; }
.toast { position: fixed; z-index: 40; left: 50%; bottom: calc(104px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: max-content; max-width: calc(100% - 30px); padding: 10px 14px; border-radius: 12px; background: #232427; color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: 14px; }
[hidden] { display: none !important; }

@media (max-width: 520px) {
  .bulk-actions { grid-template-columns: repeat(2, 1fr); }
  .field-grid { grid-template-columns: 1fr; gap: 0; }
  .task-card { grid-template-columns: 28px 1fr auto; }
  .density-button { display: none; }
}

@media (min-width: 700px) {
  .app { width: min(1240px, 100%); }
  .app.detail-open { padding-right: min(60vw, 720px); }
  .detail-open .tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-open .filters { flex-wrap: wrap; }
  .sheet[open] { position: fixed; inset: 0 max(0px, calc((100vw - 1240px) / 2)) 0 auto; width: min(60vw, 720px); height: 100vh; margin: 0; border-left: 1px solid var(--border); border-radius: 20px 0 0 20px; box-shadow: -14px 0 42px rgba(0,0,0,.16); }
  .sheet-handle { display: none; }
  .sheet-header { padding-top: 15px; }
  .sheet::backdrop { background: transparent; backdrop-filter: none; }
}

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
