:root {
  font-family: 'Segoe UI', Roboto, sans-serif;
  background-color: #f5f5f5;
  color: #1d1d1f;
  --header-height: 64px;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header,
.app-footer {
  background: linear-gradient(135deg, #4b8bff, #705dff);
  color: #fff;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header {
  min-height: var(--header-height);
  box-shadow: 0 12px 24px rgba(23, 43, 77, 0.15);
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-left h1 {
  margin: 0;
  font-size: 1.45rem;
}

.menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: background 0.2s ease, transform 0.2s ease;
}

.menu-toggle:hover,
.menu-toggle:focus-visible {
  background: rgba(255, 255, 255, 0.22);
  transform: translateY(-1px);
}

.menu-toggle:active {
  transform: translateY(0);
}

.menu-toggle[aria-expanded='true'] {
  background: rgba(255, 255, 255, 0.28);
  border-color: rgba(255, 255, 255, 0.6);
}

.menu-toggle-label {
  display: inline-block;
}

.menu-toggle-icon {
  font-size: 1.1rem;
  line-height: 1;
}

body:not(.authenticated) #toggle-list-menu {
  display: none;
}

.app-footer {
  font-size: 0.85rem;
  margin-top: auto;
}

main.app-body {
  flex: 1 1 auto;
  padding: 1.5rem;
}

body.authenticated main.app-body {
  display: flex;
  flex-direction: row;
  gap: 1.5rem;
  align-items: flex-start;
}

body:not(.authenticated) main.app-body {
  display: grid;
  grid-template-columns: minmax(0, 520px);
  justify-content: center;
  gap: 1.5rem;
}

body.initializing main.app-body {
  display: grid;
  place-items: center;
}

body.initializing #loading-screen {
  max-width: 360px;
  text-align: center;
  gap: 0.5rem;
}

.card {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 12px;
  box-shadow: 0 12px 24px rgba(23, 43, 77, 0.08);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#dashboard {
  width: 100%;
  max-width: clamp(240px, 28vw, 360px);
  align-self: stretch;
  overflow-y: auto;
}

body.authenticated #dashboard {
  flex: 0 0 clamp(240px, 28vw, 360px);
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
}

body.authenticated #list-detail {
  flex: 1 1 auto;
  min-width: 0;
}

.card.nested {
  background: rgba(245, 248, 254, 0.95);
  box-shadow: inset 0 0 0 1px rgba(99, 126, 255, 0.15);
}

#share-section {
  background: rgba(248, 250, 252, 0.5);
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.12);
  padding: 1rem;
  margin-top: 0.5rem;
}

#share-section .section-header h3 {
  font-size: 0.95rem;
  font-weight: 500;
  color: #64748b;
}

#share-section .icon-button {
  font-size: 0.85rem;
  color: #94a3b8;
}

#share-section .icon-button:hover {
  color: #64748b;
}

.flash {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  width: min(90vw, 420px);
  padding: 0.75rem 1rem;
  border-radius: 999px;
  background: #fde68a;
  color: #593b00;
  font-weight: 600;
  box-shadow: 0 12px 24px rgba(23, 43, 77, 0.2);
  z-index: 80;
  text-align: center;
  pointer-events: none;
}

.flash.error {
  background: #fee2e2;
  color: #991b1b;
}

.flash.success {
  background: #dcfce7;
  color: #166534;
}

.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 110;
}

body.list-menu-open .menu-overlay {
  opacity: 1;
  pointer-events: auto;
}

body.list-menu-open {
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
  z-index: 90;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 100;
}

.modal-content {
  width: min(480px, 100%);
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.2);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.35rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: #4b5563;
  padding: 0.25rem;
}

.modal-close:hover {
  color: #1f2937;
  transform: none;
  box-shadow: none;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.95rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.inline-controls {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.tab-buttons {
  display: inline-flex;
  gap: 0.5rem;
}

.tab-button {
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  background: rgba(75, 139, 255, 0.1);
  color: #1f2937;
  cursor: pointer;
  font-weight: 600;
}

.tab-button.active,
.tab-button:hover {
  background: #4b8bff;
  color: #fff;
}

.tab-panel {
  margin-top: 1rem;
}

.form-grid {
  display: grid;
  gap: 0.75rem;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.95rem;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: rgba(255, 255, 255, 0.9);
}

button {
  padding: 0.55rem 0.95rem;
  border-radius: 8px;
  border: none;
  background: #4b8bff;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 7px 14px rgba(75, 139, 255, 0.25);
}

button.danger {
  background: #ef4444;
}

button.icon-button {
  background: transparent;
  color: #64748b;
  padding: 0.25rem 0.5rem;
  font-size: 1rem;
  line-height: 1;
  border: none;
  transition: color 0.15s ease, transform 0.15s ease;
}

button.icon-button:hover {
  color: #1f2937;
  transform: none;
  box-shadow: none;
}

.ghost {
  background: transparent;
  color: #1f2937;
  border: 1px solid rgba(148, 163, 184, 0.6);
}

.ghost:hover {
  box-shadow: none;
  transform: none;
  background: rgba(148, 163, 184, 0.1);
}

.inline-form {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.inline-form input,
.inline-form select {
  flex: 1 1 auto;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.section-header h2,
.section-header h3,
.section-header h4 {
  margin: 0;
}

.controls {
  display: inline-flex;
  gap: 0.5rem;
}

.sort-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: #64748b;
}

.sort-control label {
  font-weight: 500;
}

.sort-control select {
  font-size: 0.8rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(255, 255, 255, 0.5);
  color: #475569;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.sort-control select:hover {
  border-color: rgba(148, 163, 184, 0.5);
}

.sort-control select:focus {
  outline: none;
  border-color: #4b8bff;
}

.items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.items li {
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 10px;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.items li.active {
  border-color: rgba(75, 139, 255, 0.55);
  box-shadow: 0 0 0 2px rgba(75, 139, 255, 0.18);
}

#lists-container li {
  cursor: pointer;
}

#lists-container li.shared-list {
  border-left: 3px solid rgba(107, 114, 128, 0.3);
  padding-left: 0.85rem;
}

#lists-container li.shared-list.active {
  border-left-color: rgba(75, 139, 255, 0.55);
}

#lists-container li:focus-visible {
  outline: 2px solid #4b8bff;
  outline-offset: 2px;
}

.items li .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.content {
  font-weight: 600;
}

.items.compact li {
  padding: 0.6rem 0.75rem;
}

.items .muted {
  font-size: 0.85rem;
  color: #6b7280;
}

@media (hover: hover) {
  .items li:hover {
    box-shadow: 0 12px 24px rgba(23, 43, 77, 0.12);
    transform: translateY(-1px);
  }
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: rgba(75, 139, 255, 0.15);
  color: #1d4ed8;
  text-transform: capitalize;
}

.badge.owner {
  background: rgba(75, 139, 255, 0.15);
  color: #1d4ed8;
}

.badge.collaborator {
  background: rgba(34, 197, 94, 0.15);
  color: #15803d;
}

.badge.viewer {
  background: rgba(107, 114, 128, 0.15);
  color: #374151;
}

.entry-actions {
  display: inline-flex;
  gap: 0.4rem;
}

.entry-content {
  display: inline-flex;
  align-items: flex-start;
  gap: 0.5rem;
  width: 100%;
}

.entry-content input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  cursor: pointer;
}

.entries .content {
  flex: 1 1 auto;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.entries li {
  padding: 0.35rem 0.55rem;
  gap: 0.2rem;
}

.entries li .row {
  gap: 0.4rem;
  align-items: flex-start;
}

.entries li .entry-actions {
  gap: 0.25rem;
  align-items: center;
}

.entries li .entry-actions button {
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  line-height: 1.1;
  min-width: 0;
}

.entries li .muted {
  font-size: 0.78rem;
  margin-left: 1.75rem;
}

.entries li {
  border-radius: 10px;
}

.user-status {
  display: inline-flex;
  gap: 0.75rem;
  align-items: center;
}

.share-columns {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.share-columns > div {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.share-forms {
  display: grid;
  gap: 0.75rem;
}

.entries .content {
  font-weight: 600;
}

.entries .content.completed {
  text-decoration: line-through;
  color: #6b7280;
}

.muted {
  color: #6b7280;
}

#list-description {
  margin-top: 0.25rem;
}

@media (max-width: 900px) {
  main.app-body {
    padding: 1rem;
  }

  body.authenticated main.app-body {
    display: block;
  }

  #dashboard {
    flex: none;
    position: fixed;
    top: 0.75rem;
    left: 1rem;
    right: auto;
    bottom: 1rem;
    width: min(90vw, 340px);
    max-width: 360px;
    transform: translateX(-115%);
    transition: transform 0.3s ease;
    z-index: 160;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.45);
  }

  body.list-menu-open #dashboard {
    transform: translateX(0);
  }

  #list-detail {
    margin-top: 1rem;
  }

  body.lists-collapsed #dashboard {
    display: none;
  }
}

@media (max-width: 480px) {
  .menu-toggle-label {
    display: none;
  }
  .menu-toggle {
    padding-inline: 0.6rem;
    border-radius: 50%;
  }
}

/* Inline editing styles */
.editable {
  cursor: text;
  transition: all 0.2s ease;
}

.editable:hover {
  background-color: rgba(75, 139, 255, 0.08);
  border-radius: 4px;
  padding: 2px 4px;
  margin: -2px -4px;
}

.editable:focus {
  outline: 2px solid rgba(75, 139, 255, 0.4);
  outline-offset: 2px;
  background-color: rgba(75, 139, 255, 0.12);
  border-radius: 4px;
  padding: 2px 4px;
  margin: -2px -4px;
}

#list-title.editable {
  display: inline-block;
  min-width: 200px;
}

#list-title.editable:hover {
  background-color: rgba(75, 139, 255, 0.1);
}

span.content.editable {
  display: inline-block;
  min-width: 100px;
}

/* Entry checkbox styling */
.entry-checkbox {
  margin-right: 0.5rem;
  cursor: pointer;
  flex-shrink: 0;
}

/* Drag and drop styling */
.drag-handle {
  cursor: grab;
  color: #94a3b8;
  font-size: 1rem;
  padding: 0.25rem 0.5rem;
  margin-right: 0.25rem;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: color 0.15s ease;
  line-height: 1;
}

.drag-handle:hover {
  color: #64748b;
}

.drag-handle:active {
  cursor: grabbing;
}

.entries li.dragging {
  opacity: 0.5;
  background: rgba(75, 139, 255, 0.1);
  border-color: rgba(75, 139, 255, 0.3);
  transform: scale(0.98);
  box-shadow: 0 8px 16px rgba(23, 43, 77, 0.15);
}

.entries li.drag-over-top {
  border-top: 3px solid #4b8bff;
  padding-top: calc(0.35rem - 2px);
  background: rgba(75, 139, 255, 0.05);
}

.entries li.drag-over-bottom {
  border-bottom: 3px solid #4b8bff;
  padding-bottom: calc(0.35rem - 2px);
  background: rgba(75, 139, 255, 0.05);
}

/* Prevent text selection during drag */
body.dragging {
  user-select: none;
  -webkit-user-select: none;
  cursor: grabbing !important;
}

/* Touch feedback */
@media (hover: none) {
  .drag-handle {
    font-size: 1.1rem;
    padding: 0.4rem 0.6rem;
  }
}

/* Entry matches dropdown */
.entry-matches-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: 240px;
  overflow-y: auto;
  background: #ffffff;
  border: 1px solid rgba(148, 163, 184, 0.6);
  border-radius: 8px;
  box-shadow: 0 12px 24px rgba(23, 43, 77, 0.15);
  z-index: 10;
  display: flex;
  flex-direction: column;
}

.modal-form label {
  position: relative;
}

.entry-match-item {
  padding: 0.75rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  cursor: pointer;
  transition: background-color 0.15s ease;
  text-align: left;
}

.entry-match-item:last-child {
  border-bottom: none;
}

.entry-match-item:hover {
  background-color: rgba(75, 139, 255, 0.08);
}

.entry-match-item:active {
  background-color: rgba(75, 139, 255, 0.15);
}

.entry-match-content {
  font-weight: 600;
  color: #1d1d1f;
  margin-bottom: 0.25rem;
}

.entry-match-note {
  font-size: 0.85rem;
  color: #6b7280;
}

.entry-match-item.completed .entry-match-content {
  text-decoration: line-through;
  color: #6b7280;
}
