:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-alt: #f9fafb;
  --text: #1c1c1e;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.12);
  --radius: 10px;
  --bg-image-opacity: 0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101113;
    --surface: #1a1b1e;
    --surface-alt: #202126;
    --text: #f1f1f3;
    --muted: #9aa0aa;
    --border: #2c2d33;
    --accent: #60a5fa;
    --accent-strong: #93c5fd;
    --danger: #f87171;
    --success: #4ade80;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.45);
  }
}

:root[data-theme="light"] {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-alt: #f9fafb;
  --text: #1c1c1e;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.12);
}

:root[data-theme="dark"] {
  --bg: #101113;
  --surface: #1a1b1e;
  --surface-alt: #202126;
  --text: #f1f1f3;
  --muted: #9aa0aa;
  --border: #2c2d33;
  --accent: #60a5fa;
  --accent-strong: #93c5fd;
  --danger: #f87171;
  --success: #4ade80;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background-color 0.2s ease, color 0.2s ease;
}

.bg-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: var(--bg-image-opacity, 0);
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topnav .brand {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
  margin-right: auto;
}

.brand-logo {
  height: 22px;
  width: auto;
  display: none;
}

:root:not([data-theme="dark"]) .brand-logo-light { display: block; }
:root[data-theme="dark"] .brand-logo-dark { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .brand-logo-light { display: none; }
  :root:not([data-theme]) .brand-logo-dark { display: block; }
}

.brand-version {
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: 0.15rem;
}

.topnav a {
  color: var(--accent);
  text-decoration: none;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.nav-user {
  color: var(--muted);
  font-size: 0.9rem;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  list-style: none;
}

.icon-button::-webkit-details-marker { display: none; }

.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-sun, .icon-moon { display: none; }
:root:not([data-theme="dark"]) .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .icon-sun { display: none; }
  :root:not([data-theme]) .icon-moon { display: block; }
}

.settings-menu {
  position: relative;
}

.settings-menu > summary {
  list-style: none;
}

.settings-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.5rem);
  width: 280px;
  max-width: calc(100vw - 2rem);
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.settings-panel h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}

.settings-panel label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.settings-panel input[type="file"] {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  font-size: 0.82rem;
  color: var(--text);
}

.settings-panel input[type="range"] {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  accent-color: var(--accent);
}

.settings-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.push-settings {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.push-status {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

.workspace {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

.workspace-grid {
  display: flex;
  align-items: flex-start;
  gap: 1.5rem;
}

.sidebar {
  flex: 0 0 240px;
  position: sticky;
  top: 4.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.sidebar-toggle-summary {
  display: none;
}

.sidebar-toggle-body {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.sidebar-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  box-shadow: var(--shadow);
}

.sidebar-heading {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.sidebar-list {
  list-style: none;
  margin: 0 0 0.6rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.sidebar-link {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.92rem;
}

.sidebar-link:hover {
  background: var(--surface-alt);
}

.sidebar-link.active {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent-strong);
}

.sidebar-owner {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 400;
}

.sidebar-shared-badge {
  align-self: flex-start;
  margin-top: 0.2rem;
  font-size: 0.68rem;
  font-weight: 400;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
}

.sidebar-empty {
  font-size: 0.85rem;
  margin: 0 0 0.6rem;
  padding: 0;
}

.sidebar-new-list {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.4rem;
}

.sidebar-new-list input {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
}

.sidebar-new-list button {
  padding: 0.45rem 0.7rem;
}

.main-content {
  flex: 1;
  min-width: 0;
}

.empty-hero {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--muted);
}

.empty-hero h1 {
  color: var(--text);
}

@media (max-width: 780px) {
  .workspace-grid {
    flex-direction: column;
  }
  .sidebar {
    position: static;
    width: 100%;
    flex: none;
  }

  .sidebar-toggle-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.6rem 0.85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    list-style: none;
  }

  .sidebar-toggle-summary::-webkit-details-marker {
    display: none;
  }

  .sidebar-toggle-current {
    font-weight: 400;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 55%;
  }

  .sidebar-toggle-body {
    margin-top: 0.75rem;
  }

  .topnav {
    padding: 0.6rem 0.85rem;
    gap: 0.5rem;
  }

  .nav-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.5rem;
  }

  .nav-user {
    max-width: 8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .todo-item {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .todo-check {
    flex-basis: 100%;
  }

  .todo-check input[type="checkbox"] {
    width: 1.3rem;
    height: 1.3rem;
  }

  .todo-meta {
    flex-basis: 100%;
  }

  .todo-actions {
    flex-basis: 100%;
    justify-content: flex-end;
  }

  .todo-actions .link-button {
    padding: 0.4rem 0.5rem;
  }
}

h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; margin-top: 2rem; color: var(--muted); }

a { color: var(--accent); }

.empty-state {
  color: var(--muted);
  font-style: italic;
  padding: 0.5rem 0;
}

.muted { color: var(--muted); font-size: 0.85rem; }

.flash-messages { margin-bottom: 1rem; }

.flash {
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.flash-error { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.flash-success { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }

.list-cards {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 1rem;
}

.list-cards li {
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  box-shadow: var(--shadow);
}

.list-cards a { font-weight: 600; text-decoration: none; }

.list-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.hide-done-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
  cursor: pointer;
}

.todo-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.todo-list.hide-done .todo-item.done {
  display: none;
}

.todo-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.4rem;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.todo-item:hover {
  box-shadow: var(--shadow-lg);
}

.todo-item.done .todo-text {
  text-decoration: line-through;
  color: var(--muted);
}

.todo-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  cursor: pointer;
}

.todo-check input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--accent);
}

.todo-meta {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--border);
  color: var(--text);
  white-space: nowrap;
}

.badge-reminder { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }
.badge-muted { opacity: 0.6; }
.badge-overdue { background: color-mix(in srgb, var(--danger) 20%, transparent); color: var(--danger); font-weight: 600; }
.badge-recurrence { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }

dialog.popup {
  border: none;
  border-radius: var(--radius);
  padding: 1.25rem;
  width: 90%;
  max-width: 420px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

dialog.popup::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.popup-header h2 {
  margin: 0;
  color: var(--text);
}

.icon-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  padding: 0.2rem 0.4rem;
  cursor: pointer;
}

.icon-close:hover {
  background: none;
  color: var(--text);
}

.button-outline {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.button-outline:hover {
  background: var(--surface-alt);
  border-color: var(--accent);
  color: var(--accent);
}

form label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

form input[type="text"],
form input[type="email"],
form input[type="password"],
form input[type="datetime-local"] {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.inline-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin: 0.5rem 0;
}

.todo-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.todo-actions .inline-form {
  margin: 0;
}

.inline-form input { margin: 0; }

button, .link-button {
  padding: 0.5rem 0.9rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 0.12s ease, transform 0.05s ease;
}

button:hover { background: var(--accent-strong); }
button:active { transform: translateY(1px); }

.link-button {
  background: none;
  color: var(--accent);
  padding: 0.2rem 0.4rem;
  text-decoration: underline;
}

.link-button:hover { background: none; color: var(--accent-strong); }

.danger { color: var(--danger); }
button.danger { background: var(--danger); color: white; }
button.danger:hover { background: var(--danger); filter: brightness(1.1); }

.share-list {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem;
}

.share-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
}

.user-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.user-table th, .user-table td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.user-table .actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.login-box {
  max-width: 360px;
  margin: 3rem auto;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.login-box button { width: 100%; margin-top: 0.5rem; }
