:root {
  color-scheme: light dark;
  --surface: #f5f5f5;
  --surface-dark: #1f1f1f;
  --text: #1f1f1f;
  --text-dark: #f5f5f5;
  --accent: #2c6bed;
  --accent-dark: #94b9ff;
  --border: rgba(0, 0, 0, 0.1);
  --border-dark: rgba(255, 255, 255, 0.1);
  --danger: #d64545;
  --warning: #d68b13;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--surface);
  color: var(--text);
  padding: 1.5rem clamp(1rem, 4vw, 2.5rem);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

@media (prefers-color-scheme: dark) {
  body {
    background: var(--surface-dark);
    color: var(--text-dark);
  }
}

.page-header h1 {
  margin: 0;
  font-size: clamp(1.75rem, 2vw + 1rem, 2.2rem);
}

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

.header-actions {
  display: flex;
  gap: 0.75rem;
}

.tagline {
  margin: 0.35rem 0 0;
  max-width: 40ch;
  opacity: 0.8;
}

.layout {
  width: 100%;
  max-width: none;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.tabs-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

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

.tabs-actions {
  display: flex;
  gap: 0.5rem;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  background: rgba(0, 0, 0, 0.03);
  padding: 0.4rem;
  border-radius: 0.65rem;
  gap: 0.35rem;
}

.tab {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid transparent;
  background: white;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.95rem;
  user-select: none;
}

.tab[aria-selected="true"] {
  background: var(--accent);
  color: white;
}

.tab[draggable="true"] {
  -webkit-user-drag: element;
}

.tab-content {
  background: white;
  border-radius: 1rem;
  padding: 1.25rem clamp(1rem, 4vw, 1.75rem) 1.5rem;
  box-shadow: 0 24px 45px -40px rgba(0, 0, 0, 0.4);
  min-height: 380px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  overflow-x: hidden;
}

.tab-content h2 {
  margin: 0;
}

.tab-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.tab-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.tree-item {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.item-card {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.85rem 1rem;
  border-radius: 0.8rem;
  background: rgba(0, 0, 0, 0.04);
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.item-card[draggable="true"] {
  cursor: grab;
}

.item-card[draggable="true"]:active {
  cursor: grabbing;
}

.item-card:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.item-card[data-drop="before"] {
  box-shadow:
    -2px 0 0 -1px var(--accent),
    0 -2px 0 -1px var(--accent);
  border-top-left-radius: 0.85rem;
}

.item-card[data-drop="after"] {
  box-shadow:
    2px 0 0 -1px var(--accent),
    0 2px 0 -1px var(--accent);
  border-bottom-right-radius: 0.85rem;
}

.item-card[data-drop="inside"] {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.item-card[data-drop] {
  transform: translateZ(0);
}

.item-header {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 0.65rem;
}

.item-toggle {
  border: none;
  background: none;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}

.item-toggle:hover,
.item-toggle:focus {
  background: rgba(0, 0, 0, 0.08);
  outline: none;
}

.tree-item.is-collapsed > .tree-children {
  display: none;
}

.tree-item.is-collapsed > .item-card {
  opacity: 0.9;
}

.item-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  flex: 1;
}

.item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.6rem;
  background: rgba(0, 0, 0, 0.06);
  font-size: 1.1rem;
  flex-shrink: 0;
}

.item-title {
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
}

.item-title a {
  color: inherit;
  text-decoration: none;
  white-space: normal;
}

.item-title a:hover {
  text-decoration: underline;
}

.tree-children {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-left: 1.25rem;
  border-left: 2px dashed rgba(0, 0, 0, 0.08);
  margin-left: 0.5rem;
}

.icon-button {
  background: rgba(0, 0, 0, 0.08);
  border: none;
  border-radius: 999px;
  width: 2.25rem;
  height: 2.25rem;
  font-size: 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-button:hover {
  background: rgba(0, 0, 0, 0.12);
}

.management-panel {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: flex-end;
  pointer-events: none;
  z-index: 999;
}

.management-panel[hidden] {
  display: none;
}

.management-panel__backdrop {
  display: none;
}

.management-panel__content {
  width: min(420px, 92vw);
  height: 100%;
  padding: 1.5rem;
  background: var(--surface);
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: -24px 0 60px -40px rgba(0, 0, 0, 0.35);
  transform: translateX(100%);
  transition: transform 240ms ease;
  pointer-events: auto;
}

.management-panel.is-open .management-panel__content {
  transform: translateX(0);
}

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

.management-panel__header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.management-panel__body {
  overflow-y: auto;
  padding-right: 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 768px) {
  .management-panel__content {
    border-radius: 1.25rem 0 0 1.25rem;
  }
}

.card,
.card summary {
  background: white;
  border-radius: 1rem;
  padding: 1.25rem;
  box-shadow: 0 24px 45px -40px rgba(0, 0, 0, 0.4);
}

.card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.card summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}

.card summary::marker,
.card summary::-webkit-details-marker {
  display: none;
}

.card[open] summary {
  margin-bottom: 0.5rem;
}

.card summary::after {
  content: "▾";
  font-size: 0.8rem;
  opacity: 0.7;
}

.card[open] summary::after {
  transform: rotate(180deg);
}

.card form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.card h2 {
  margin: 0;
  font-size: 1.05rem;
}

.card__hint {
  margin: 0;
  font-size: 0.85rem;
  opacity: 0.75;
}

.folder {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.9rem 1.1rem;
  border-radius: 0.8rem;
  background: rgba(0, 0, 0, 0.04);
}

.folder-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

.folder-actions {
  display: flex;
  gap: 0.5rem;
}

.folder-drop-target {
  border: 2px dashed transparent;
  border-radius: 0.75rem;
  transition: border-color 120ms ease;
}

.folder-drop-target.is-droppable {
  border-color: var(--accent);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  width: 100%;
}

.field--checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

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

input,
select {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  font: inherit;
  width: 100%;
}

@media (prefers-color-scheme: dark) {
  .tabs,
  .tab-content,
  .card,
  .tab,
  .card summary,
  .management-panel__content {
    background: rgba(255, 255, 255, 0.05);
  }

  .tab-content,
  .card,
  .management-panel__content {
    box-shadow: 0 24px 45px -40px rgba(0, 0, 0, 0.8);
  }

  input,
  select {
    background: rgba(255, 255, 255, 0.05);
    color: inherit;
    border: 1px solid var(--border-dark);
  }

  .context-menu {
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 18px 48px -32px rgba(0, 0, 0, 0.85);
  }

  .context-menu__item:hover,
  .context-menu__item:focus {
    background: rgba(255, 255, 255, 0.12);
  }

  .tree-children {
    border-left-color: rgba(255, 255, 255, 0.2);
  }

  .item-toggle:hover,
  .item-toggle:focus {
    background: rgba(255, 255, 255, 0.12);
  }
}

.button {
  padding: 0.55rem 0.85rem;
  border-radius: 0.65rem;
  border: 1px solid transparent;
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 0.35rem;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.button--primary {
  background: var(--accent);
  color: white;
}

.button--secondary {
  background: rgba(0, 0, 0, 0.06);
}

.button--warning {
  background: rgba(214, 139, 19, 0.15);
  color: inherit;
}

.button--danger {
  background: rgba(214, 69, 69, 0.15);
  color: inherit;
}

.google-search {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.google-search input {
  flex: 1;
}

.empty-state {
  padding: 0.85rem 1rem;
  border-radius: 0.75rem;
  background: rgba(0, 0, 0, 0.04);
  font-size: 0.95rem;
  opacity: 0.75;
  list-style: none;
  margin: 0;
  text-align: center;
}

.context-menu {
  position: fixed;
  background: var(--surface);
  border-radius: 0.75rem;
  box-shadow: 0 18px 48px -32px rgba(0, 0, 0, 0.6);
  padding: 0.5rem 0;
  display: flex;
  flex-direction: column;
  min-width: 160px;
  z-index: 1500;
}

.context-menu[hidden] {
  display: none;
}

.context-menu__item {
  padding: 0.5rem 1rem;
  background: none;
  border: none;
  text-align: left;
  font: inherit;
  cursor: pointer;
  width: 100%;
}

.context-menu__item:hover {
  background: rgba(0, 0, 0, 0.08);
}

.context-menu__item:focus {
  outline: none;
  background: rgba(0, 0, 0, 0.12);
}

.quick-add-container {
  margin: 0.25rem 0 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.quick-add-container.is-collapsed .quick-add {
  display: none;
}

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

.quick-add-toggle[aria-expanded="true"] {
  background: var(--accent);
  color: white;
}

.quick-add {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.5rem;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.03);
  border-radius: 0.75rem;
  align-items: start;
}

.quick-add button {
  justify-self: start;
  padding: 0.45rem 0.75rem;
}

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font: inherit;
}

.link-button:hover {
  text-decoration: underline;
}

.auth-overlay,
.edit-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(4px);
  background: rgba(0, 0, 0, 0.4);
  z-index: 1000;
}

.auth-overlay[hidden],
.edit-overlay[hidden] {
  display: none !important;
}

.auth-dialog,
.edit-dialog {
  width: min(420px, 100% - 2rem);
  background: var(--surface);
  border-radius: 1rem;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 30px 60px -45px rgba(0, 0, 0, 0.65);
}

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

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.auth-switch {
  margin: 0;
  font-size: 0.9rem;
}

.auth-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.9rem;
}

.edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.deleted-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.deleted-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.03);
  border-radius: 0.5rem;
}

.deleted-item__icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.deleted-item__info {
  flex: 1;
  min-width: 0;
}

.deleted-item__title {
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.deleted-item__path {
  font-size: 0.85rem;
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.button--small {
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

@media (prefers-color-scheme: dark) {
  .deleted-item {
    background: rgba(255, 255, 255, 0.05);
  }
}

.activity-log {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 400px;
  overflow-y: auto;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.02);
  border-radius: 0.5rem;
}

.activity-log__entry {
  display: flex;
  gap: 0.75rem;
  padding: 0.5rem;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.activity-log__entry:last-child {
  border-bottom: none;
}

.activity-log__time {
  flex-shrink: 0;
  min-width: 140px;
  font-size: 0.85rem;
  opacity: 0.7;
  font-family: monospace;
}

.activity-log__action {
  flex: 1;
  word-break: break-word;
}

@media (prefers-color-scheme: dark) {
  .activity-log {
    background: rgba(255, 255, 255, 0.03);
  }
  
  .activity-log__entry {
    border-bottom-color: var(--border-dark);
  }
}

