:root {
  color: #172033;
  background: #f4f6f8;
  font-family: system-ui, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  --blue: #2463eb;
  --line: #dfe3e8;
  --muted: #667085;
  --danger: #c9362b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
  min-height: 100dvh;
  background: #f4f6f8;
}
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.app-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 54px;
  padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.brand, .account, .control-row, .auth-actions, .note-main { display: flex; align-items: center; }
.brand { gap: 8px; white-space: nowrap; }
.brand img { width: 26px; height: 26px; }
.account { gap: 7px; min-width: 0; color: var(--muted); font-size: 13px; }
#account-name { max-width: 116px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #344054;
  font-size: 21px;
}
.icon-button:hover { background: #f1f3f5; }
.icon-button.bordered { border: 1px solid var(--line); background: #fff; }
.icon-button.danger { color: var(--danger); }

.sync-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: #98a2b3; }
.sync-dot[data-state="syncing"] { background: #2463eb; }
.sync-dot[data-state="synced"] { background: #16a064; }
.sync-dot[data-state="warning"] { background: #d99a16; }
.sync-dot[data-state="conflict"] { background: #d43b32; }

main {
  width: min(100%, 760px);
  margin: 0 auto;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
.auth-view { padding: 48px 16px; }
.auth-panel { max-width: 380px; margin: 0 auto; }
.auth-panel h1 { margin: 0 0 8px; font-size: 24px; }
.auth-panel > p { color: var(--muted); line-height: 1.6; }
.auth-panel label { display: grid; gap: 6px; margin-top: 16px; font-size: 14px; font-weight: 600; }

input, select, textarea {
  width: 100%;
  border: 1px solid #cfd5dd;
  border-radius: 6px;
  background: #fff;
  color: #172033;
  outline: none;
}
input, select { height: 42px; padding: 0 11px; }
textarea { padding: 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #2463eb1f; }

.auth-actions { gap: 8px; margin-top: 20px; }
.primary-button, .secondary-button, .text-button { min-height: 40px; padding: 0 15px; border-radius: 6px; }
.primary-button { border: 1px solid var(--blue); background: var(--blue); color: #fff; }
.secondary-button { border: 1px solid #cfd5dd; background: #fff; color: #344054; }
.text-button { border: 0; background: transparent; color: var(--muted); }
.message { min-height: 22px; color: var(--danger) !important; font-size: 13px; }

.view-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 10px 0;
  overflow-x: auto;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.view-tabs button {
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
}
.view-tabs button.selected { border-bottom-color: var(--blue); color: #172033; font-weight: 650; }

.controls {
  padding: 10px 12px;
  display: grid;
  gap: 9px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.control-row { gap: 8px; justify-content: space-between; }
#module-select { flex: 1; min-width: 0; }
.segment { display: inline-flex; padding: 2px; border: 1px solid var(--line); border-radius: 7px; background: #f5f7f9; }
.segment button { min-height: 30px; padding: 0 12px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); }
.segment button.selected { background: #fff; color: #172033; box-shadow: 0 1px 2px #10182814; }
.sync-label { color: var(--muted); font-size: 12px; }

.add-form {
  position: sticky;
  top: 54px;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px 12px;
  background: #f4f6f8e8;
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.note-list { background: #fff; }
.module-heading {
  min-height: 38px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8f9fb;
  border-bottom: 1px solid #e8ebef;
  color: #475467;
  font-size: 13px;
  font-weight: 650;
}
.note-row {
  min-height: 52px;
  padding: 8px 9px 8px 12px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 34px 34px;
  gap: 5px;
  align-items: center;
  border-bottom: 1px solid #eceff2;
}
.note-row input[type="checkbox"] { width: 19px; height: 19px; accent-color: var(--blue); }
.note-text { min-width: 0; line-height: 1.45; overflow-wrap: anywhere; }
.note-row.done .note-text { color: #98a2b3; text-decoration: line-through; }
.row-button { width: 34px; height: 34px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: #667085; font-size: 18px; }
.row-button:hover { background: #f1f3f5; }
.row-button.delete { color: var(--danger); }
.empty { padding: 48px 18px; text-align: center; color: var(--muted); }

dialog {
  width: min(calc(100% - 28px), 430px);
  padding: 20px;
  border: 0;
  border-radius: 8px;
  color: #172033;
  box-shadow: 0 18px 50px #10182838;
}
dialog::backdrop { background: #10182870; }
dialog h2 { margin: 0 0 10px; font-size: 19px; }
dialog p { color: var(--muted); line-height: 1.6; }
.dialog-actions { margin-top: 16px; display: flex; justify-content: flex-end; gap: 8px; }
.dialog-actions.vertical { display: grid; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 30;
  max-width: calc(100% - 32px);
  padding: 9px 13px;
  border-radius: 6px;
  background: #172033;
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: 160ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
[hidden] { display: none !important; }

@media (min-width: 700px) {
  main { margin-top: 18px; border: 1px solid var(--line); background: #fff; }
  .auth-view { min-height: 540px; display: grid; align-items: center; }
  .notes-view { min-height: 620px; }
}
@media (max-width: 420px) {
  .app-bar { gap: 6px; }
  .brand strong { font-size: 15px; }
  #account-name { max-width: 76px; }
  .account { gap: 4px; }
  .note-row { grid-template-columns: 26px minmax(0, 1fr) 32px 32px; }
}
