:root {
  --bg: #f6f7f9;
  --surface: #fff;
  --ink: #202124;
  --muted: #5f6368;
  --line: #e6e8eb;
  --accent: #1a73e8;
  --accent-soft: #e8f0fe;
  --danger: #c5221f;
  --danger-soft: #fce8e6;
  --ok: #137333;
  --ok-soft: #e6f4ea;
  --overdue: #c5221f;
  --soon: #b06000;
  --shadow: 0 1px 2px rgba(32, 33, 36, .12);
  --radius: 10px;
  --topbar: 56px;
  --sidebar: 260px;
  --font: "Google Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 15px/1.45 var(--font);
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0);
}

/* Auth */
.is-auth { background: var(--bg); }
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border-radius: 16px; padding: 32px 28px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 1.5rem; font-weight: 500; margin: 12px 0 4px; }
.login-card .muted { margin: 0 0 20px; }
.login-card label { display: block; font-size: .85rem; margin: 12px 0 4px; color: var(--muted); }
.login-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.login-card input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.muted { color: var(--muted); }
.inline { display: inline; }
.btn-as-link, .text-link {
  background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit;
}
.topbar-right .text-link { margin-left: 12px; }

.flash { padding: 10px 12px; border-radius: 8px; margin: 0 0 16px; }
.flash-error, .flash-danger { background: var(--danger-soft); color: var(--danger); }
.flash-ok, .flash-success { background: var(--ok-soft); color: var(--ok); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  background: var(--line); color: var(--ink);
}
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--accent-soft); color: var(--accent); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; margin-top: 16px; }
.btn.sm { padding: 4px 10px; font-size: .85rem; }

.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%;
  cursor: pointer; color: var(--muted); display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--line); color: var(--ink); }
.icon-btn.sm { width: 28px; height: 28px; font-size: 1.1rem; }

/* App chrome */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar); background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 500; font-size: 1.15rem; }
.brand:hover { text-decoration: none; }
.search {
  flex: 1; max-width: 560px; margin: 0 8px; display: flex; align-items: center; gap: 8px;
  background: var(--bg); border-radius: 8px; padding: 0 12px; color: var(--muted);
}
.search input {
  flex: 1; border: 0; background: transparent; padding: 10px 0; outline: none;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; font-size: .9rem; }
.who { color: var(--muted); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.shell { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: var(--sidebar); background: var(--surface); border-right: 1px solid var(--line);
  padding: 12px 8px; flex-shrink: 0;
}
.nav-label {
  font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
  padding: 14px 12px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 0 24px 24px 0;
  color: var(--ink); margin-right: 8px;
}
.nav-item:hover { background: var(--bg); text-decoration: none; }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.nav-icon { display: flex; }
.nav-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count { margin-left: auto; font-size: .75rem; color: var(--muted); }
.pill {
  font-size: .65rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 1px 6px;
}

.main { flex: 1; padding: 20px 20px 80px; max-width: 860px; width: 100%; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h1 { font-size: 1.35rem; font-weight: 500; margin: 0; }
.sort-bar { display: flex; gap: 10px; align-items: center; font-size: .9rem; }
.sort-bar a { color: var(--muted); }
.sort-bar a.is-on { color: var(--accent); font-weight: 500; }

.reminders {
  background: var(--accent-soft); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px;
}
.reminders ul { margin: 6px 0 0; padding: 0; list-style: none; }
.reminders li { display: flex; gap: 10px; flex-wrap: wrap; padding: 3px 0; }

.add-task {
  display: flex; gap: 8px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.add-task input[type="text"] {
  flex: 1; border: 0; padding: 8px 10px; outline: none; background: transparent;
}
.add-task select { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: #fff; }

.task-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.task-row { border-bottom: 1px solid var(--line); }
.task-row:last-child { border-bottom: 0; }
.task-line {
  display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 4px 10px 4px 8px;
}
.task-row:hover .task-line { background: #fafbfc; }
.task-title {
  flex: 1; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  color: var(--ink); min-width: 0; padding: 8px 0;
}
.task-title:hover { text-decoration: none; }
.task-title span:first-child { overflow: hidden; text-overflow: ellipsis; }
.task-row.is-done .task-title span:first-child { color: var(--muted); text-decoration: line-through; }
.task-due { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.task-due.is-overdue { color: var(--overdue); font-weight: 500; }
.task-due.is-soon { color: var(--soon); }
.meta-chip { font-size: .72rem; color: var(--muted); background: var(--bg); border-radius: 999px; padding: 1px 7px; }

.check {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid #80868b; background: #fff;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: #fff; padding: 0;
}
.check:hover { border-color: var(--accent); }
.check.is-checked { background: var(--ok); border-color: var(--ok); }
.check.is-ghost { border-style: dashed; opacity: .4; }
.check.sm { width: 18px; height: 18px; }

.task-expand { background: #fbfcfd; border-top: 1px solid var(--line); }
.expand-inner { padding: 12px 16px 16px 42px; }
.title-input {
  width: 100%; border: 0; background: transparent; font-size: 1.1rem; font-weight: 500;
  padding: 4px 0 10px; outline: none; border-bottom: 1px solid transparent;
}
.title-input:focus { border-bottom-color: var(--accent); }
.field-label { font-size: .8rem; color: var(--muted); margin: 12px 0 6px; }
textarea, .expand-form input[type="datetime-local"], .expand-form select, .expand-form input[type="text"] {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff;
}
textarea { resize: vertical; min-height: 72px; }
.field-grid {
  display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 12px;
}
.field-grid label { font-size: .8rem; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.subtasks ul, .attachments ul, .plain-list { list-style: none; margin: 0; padding: 0; }
.subtasks li, .attachments li, .plain-list li {
  display: flex; align-items: center; gap: 8px; min-height: 36px;
}
.subtasks li.is-done span { color: var(--muted); text-decoration: line-through; }
.add-sub, .add-att, .form-inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.add-sub input { flex: 1; min-width: 140px; }
.attachments li a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.notes-static { white-space: pre-wrap; }

.meta {
  display: grid; gap: 4px; margin: 16px 0 0; font-size: .8rem; color: var(--muted);
}
.meta div { display: flex; gap: 8px; }
.meta dt { min-width: 84px; font-weight: 500; }
.meta dd { margin: 0; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty h1 { font-size: 3rem; margin: 0; color: var(--ink); font-weight: 400; }

.panel {
  background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.panel-title { font-size: 1rem; font-weight: 500; margin: 0 0 12px; }
.form-grid { display: grid; gap: 10px; }
.form-grid label, .panel label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.form-grid input, .form-grid select, .panel input, .panel select, .form-inline input, .form-inline select {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; color: var(--ink);
}
.checkset { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px 14px; }
.checkset legend { font-size: .85rem; color: var(--muted); padding: 0; margin-bottom: 6px; }
.check-label { flex-direction: row !important; align-items: center; gap: 6px !important; color: var(--ink) !important; }

.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
.data th, .data td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 500; }
.data input, .data select { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; width: 100%; max-width: 220px; }
.data .nowrap { white-space: nowrap; }
.data tr.is-muted { opacity: .55; }
.inline-edit { display: contents; }

.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(32,33,36,.4); z-index: 25;
}
.sidebar-backdrop[hidden] { display: none !important; }
.sidebar-backdrop:not([hidden]) { display: block; }

@media (min-width: 720px) {
  .field-grid { grid-template-columns: 1fr 1fr; }
  .sidebar-toggle { display: none; }
}
@media (max-width: 719px) {
  .who { display: none; }
  .search { max-width: none; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 30; transform: translateX(-105%);
    transition: transform .2s ease; box-shadow: 2px 0 12px rgba(0,0,0,.12);
  }
  .sidebar.is-open { transform: none; }
  .expand-inner { padding-left: 16px; }
  .main { padding: 12px 12px 96px; }
  .add-task { position: sticky; bottom: 8px; z-index: 10; }
}


/* Notes */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.filter-bar label {
  display: flex; flex-direction: column; gap: 4px; font-size: .8rem; color: var(--muted);
}
.filter-bar input, .filter-bar select {
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: #fff; color: var(--ink);
}
.filter-actions { display: flex; gap: 6px; align-items: center; }

.add-note {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.add-note input[type="text"], .add-note select, .add-note textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff;
}
.add-note textarea { min-height: 88px; resize: vertical; }

.note-list { display: grid; gap: 10px; }
.note-card {
  display: block; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); color: var(--ink);
}
.note-card:hover { text-decoration: none; border-color: #d2e3fc; box-shadow: 0 2px 8px rgba(26,115,232,.12); }
.note-card-title { font-size: 1.05rem; font-weight: 500; margin: 0 0 6px; }
.note-card-snippet { margin: 0 0 10px; color: var(--muted); font-size: .92rem; }
.note-card-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }

.cat-pill {
  font-size: .72rem; background: var(--bg); border-radius: 999px; padding: 2px 8px; color: var(--muted);
}
.cat-pill.has-color {
  background-color: var(--cat-color); background: var(--cat-color); color: #fff;
}
.cat-dot {
  width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0;
  background-color: var(--cat-color, var(--line)); background: var(--cat-color, var(--line));
}
.inline-dot { display: inline-block; vertical-align: middle; margin-right: 6px; }

.note-editor label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); margin-bottom: 12px; }
.note-editor .title-input {
  width: 100%; border: 0; border-bottom: 1px solid var(--line); background: transparent;
  font-size: 1.25rem; font-weight: 500; padding: 6px 0; outline: none; color: var(--ink);
}
.note-editor .title-input:focus { border-bottom-color: var(--accent); }
.note-editor textarea {
  width: 100%; min-height: 280px; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; background: #fff; resize: vertical;
}
.note-editor select {
  width: 100%; max-width: 320px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff;
}
.note-danger-row { margin-top: 8px; padding: 0 4px; }

@media (max-width: 719px) {
  .add-note { position: static; }
  .filter-bar { padding: 10px; }
}


.header-clock {
  font-size: .85rem; color: var(--muted); white-space: nowrap; margin-right: 10px;
  font-variant-numeric: tabular-nums;
}
.color-picker {
  display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.color-picker input[type="color"] {
  width: 40px; height: 36px; padding: 0; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; cursor: pointer;
}
.color-picker .js-color-hex { max-width: 110px; }
@media (max-width: 719px) {
  .header-clock { font-size: .72rem; margin-right: 6px; }
}

/* Calendar */
.main-calendar { max-width: 1100px; }
.cal-head { align-items: center; }
.cal-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cal-nav h1 { margin: 0 4px; min-width: 9rem; text-align: center; }
.cal-filter { margin-bottom: 16px; }
.cal-layout {
  display: grid; gap: 16px;
  grid-template-columns: 1fr;
}
@media (min-width: 900px) {
  .cal-layout { grid-template-columns: minmax(0, 1.4fr) minmax(260px, .9fr); align-items: start; }
}
.cal-month {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); overflow: hidden;
}
.cal-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr);
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.cal-wd {
  text-align: center; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); padding: 8px 4px; font-weight: 500;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-day {
  min-height: 72px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  color: var(--ink); display: flex; flex-direction: column; gap: 4px; background: #fff;
}
.cal-day:nth-child(7n) { border-right: 0; }
.cal-day:hover { background: var(--accent-soft); text-decoration: none; }
.cal-day.is-other { color: #9aa0a6; background: #fafbfc; }
.cal-day.is-today .cal-day-num {
  background: var(--accent); color: #fff; border-radius: 50%;
  width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center;
}
.cal-day.is-selected { outline: 2px solid var(--accent); outline-offset: -2px; z-index: 1; }
.cal-day-num { font-size: .9rem; font-weight: 500; }
.cal-dots { display: flex; gap: 3px; align-items: center; flex-wrap: wrap; margin-top: auto; }
.cal-dot { width: 6px; height: 6px; border-radius: 50%; background-color: var(--cat-color, var(--accent)); background: var(--cat-color, var(--accent)); }
.cal-more { font-size: .65rem; color: var(--muted); }
.cal-count {
  font-size: .65rem; color: var(--muted); margin-top: auto; align-self: flex-end;
}
.cal-day-panel {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); padding: 14px; min-height: 200px;
}
.cal-day-panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.cal-day-panel-head h2 { font-size: 1rem; font-weight: 500; margin: 0; }
.cal-empty-day { margin: 24px 0; text-align: center; }

.event-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.event-list-page { gap: 10px; }
.event-card {
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.event-card-link {
  display: block; padding: 10px 12px; color: var(--ink);
}
.event-card-link:hover { text-decoration: none; background: var(--accent-soft); border-radius: 8px; }
.event-card-time { font-size: .8rem; color: var(--muted); margin-bottom: 2px; }
.event-card-title { font-weight: 500; margin-bottom: 4px; }

.event-editor label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); margin-bottom: 12px; }
.event-editor .title-input {
  width: 100%; border: 0; border-bottom: 1px solid var(--line); background: transparent;
  font-size: 1.25rem; font-weight: 500; padding: 6px 0; outline: none; color: var(--ink);
}
.event-editor .title-input:focus { border-bottom-color: var(--accent); }
.event-editor textarea {
  width: 100%; min-height: 160px; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; background: #fff; resize: vertical;
}
.event-editor select, .event-editor input[type="datetime-local"], .event-editor input[type="date"] {
  width: 100%; max-width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff;
}
.check-inline { flex-direction: row !important; align-items: center; gap: 8px !important; color: var(--ink) !important; }
.tiny-help { font-size: .8rem; margin: -4px 0 12px; }

@media (max-width: 719px) {
  .cal-day { min-height: 56px; padding: 4px; }
  .cal-count { display: none; }
  .cal-nav h1 { min-width: auto; font-size: 1.1rem; }
}

.cal-category-list { margin-top: 16px; }
.cal-category-list .panel-title { margin-top: 0; }
.event-card-date { font-variant-numeric: tabular-nums; }

/* Version footer */
.app-version {
  text-align: center;
  font-size: .75rem;
  line-height: 1.4;
  margin: 20px 8px 8px;
  color: var(--muted);
}
.app-version a { color: var(--muted); }
.login-card .app-version { margin: 18px 0 0; }
.changelog-pre {
  margin: 0;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: .8rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
  max-width: 100%;
}
