/* ==========================================
   Index — Dieter Rams × Monocle × TE
   ========================================== */

:root {
  --bg: #F2F0EB;
  --surface: #FFFFFF;
  --surface-hover: #F8F7F4;
  --text: #1A1A1A;
  --text-secondary: #6B6560;
  --text-tertiary: #A39E98;
  --accent: #FF6633;
  --accent-hover: #E8551F;
  --accent-subtle: rgba(255, 102, 51, 0.06);
  --border: #E6E3DC;
  --danger: #CC3333;
  --danger-subtle: rgba(204, 51, 51, 0.06);

  --font-display: 'Newsreader', Georgia, 'Times New Roman', serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  --font-mono: 'SF Mono', ui-monospace, monospace;

  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;

  --shadow-card:
    0 0 0 1px rgba(0, 0, 0, 0.03),
    0 1px 2px rgba(0, 0, 0, 0.02),
    0 4px 16px rgba(0, 0, 0, 0.04);
  --shadow-card-hover:
    0 0 0 1px rgba(0, 0, 0, 0.03),
    0 2px 4px rgba(0, 0, 0, 0.03),
    0 8px 32px rgba(0, 0, 0, 0.07);
  --shadow-modal:
    0 0 0 1px rgba(0, 0, 0, 0.04),
    0 16px 48px rgba(0, 0, 0, 0.12),
    0 4px 12px rgba(0, 0, 0, 0.06);

  --tint: rgba(0, 0, 0, 0.04);
  --header-bg: rgba(242, 240, 235, 0.8);
  --backdrop-bg: rgba(26, 26, 26, 0.2);
  --ease: cubic-bezier(0.2, 0, 0, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161616;
    --surface: #1E1E1E;
    --surface-hover: #252525;
    --text: #E8E6E1;
    --text-secondary: #9B9690;
    --text-tertiary: #6B6560;
    --accent: #FF7A4D;
    --accent-hover: #FF9470;
    --accent-subtle: rgba(255, 122, 77, 0.1);
    --border: #2C2A27;
    --danger: #E85454;
    --danger-subtle: rgba(232, 84, 84, 0.1);

    --tint: rgba(255, 255, 255, 0.07);
    --header-bg: rgba(22, 22, 22, 0.8);
    --backdrop-bg: rgba(0, 0, 0, 0.5);

    --shadow-card:
      0 0 0 1px rgba(255, 255, 255, 0.04),
      0 1px 2px rgba(0, 0, 0, 0.2),
      0 4px 16px rgba(0, 0, 0, 0.2);
    --shadow-card-hover:
      0 0 0 1px rgba(255, 255, 255, 0.06),
      0 2px 4px rgba(0, 0, 0, 0.2),
      0 8px 32px rgba(0, 0, 0, 0.3);
    --shadow-modal:
      0 0 0 1px rgba(255, 255, 255, 0.06),
      0 16px 48px rgba(0, 0, 0, 0.4),
      0 4px 12px rgba(0, 0, 0, 0.3);
  }
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ---- Header ---- */

.header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0 40px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 480px;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 36px;
  padding: 0 36px 0 36px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 400;
  border: none;
  border-radius: 10px;
  background: var(--tint);
  color: var(--text);
  outline: none;
  transition-property: background, box-shadow;
  transition-duration: 0.2s;
  transition-timing-function: var(--ease);
}

.search-input:focus {
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--accent), 0 2px 8px rgba(255, 102, 51, 0.08);
}

.search-input::placeholder {
  color: var(--text-tertiary);
  font-weight: 400;
}

.search-kbd {
  position: absolute;
  right: 10px;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--tint);
  border-radius: 4px;
  pointer-events: none;
  line-height: 1.4;
  transition-property: opacity;
  transition-duration: 0.12s;
}

.search-input:focus + .search-kbd,
.search-input:not(:placeholder-shown) + .search-kbd {
  opacity: 0;
}

.btn-edit {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  padding: 0 14px;
  height: 32px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  letter-spacing: 0.02em;
  transition-property: background, border-color, color, transform;
  transition-duration: 0.12s;
  transition-timing-function: var(--ease);
}

.btn-edit:hover {
  border-color: var(--text-tertiary);
  color: var(--text);
}

.btn-edit:active {
  transform: scale(0.96);
}

.btn-edit.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.btn-edit.active:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* ---- Layout ---- */

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 40px 80px;
}

.grid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* ---- Folder Card ---- */

.folder-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-card);
  animation: fadeInUp 0.4s var(--ease) both;
  transition-property: box-shadow, transform;
  transition-duration: 0.25s;
  transition-timing-function: var(--ease);
}

.folder-card.no-anim {
  animation: none;
}

.folder-card {
  width: 100%;
  max-width: 548px;
}

.folder-card:hover {
  box-shadow: var(--shadow-card-hover);
}

.folder-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 8px;
  transition: margin-bottom 0.3s var(--ease);
}

.folder-name {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  font-style: italic;
  text-wrap: balance;
  line-height: 1.2;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.folder-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: transform 0.2s var(--ease), color 0.15s var(--ease), background 0.15s var(--ease);
  position: relative;
  top: 1px;
}

.folder-toggle:hover {
  background: var(--bg);
  color: var(--text-secondary);
}

.folder-card.collapsed .folder-toggle {
  transform: rotate(-90deg);
}

.folder-body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.3s var(--ease);
}

.folder-body-inner {
  overflow: hidden;
}

.folder-card.collapsed .folder-body {
  grid-template-rows: 0fr;
}

.folder-card.collapsed .folder-header {
  margin-bottom: 0;
}

.folder-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  font-weight: 400;
  letter-spacing: 0.02em;
}

.folder-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  pointer-events: none;
  transition-property: opacity;
  transition-duration: 0.15s;
  transition-timing-function: var(--ease);
  flex-shrink: 0;
}

/* Only show on hover in edit mode */
.editing .folder-header:hover .folder-actions {
  opacity: 1;
  pointer-events: auto;
}

.folder-divider {
  height: 1px;
  background: var(--border);
  margin-bottom: 10px;
  opacity: 0.7;
}

/* ---- Bookmarks ---- */

.bookmark-list {
  list-style: none;
}

.bookmark {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  margin: 1px -8px;
  border-radius: var(--radius-xs);
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  transition-property: background;
  transition-duration: 0.1s;
  transition-timing-function: var(--ease);
  min-height: 36px;
}

.bookmark:hover,
.bookmark.highlight {
  background: var(--surface-hover);
}

.bookmark.highlight {
  box-shadow: inset 2px 0 0 var(--accent);
}

.bookmark:active {
  background: var(--bg);
}

.bookmark-icon {
  font-size: 16px;
  width: 16px;
  flex-shrink: 0;
  color: var(--text-tertiary);
  line-height: 1;
}

.bookmark-title {
  flex: 1;
  font-size: 13.5px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.bookmark:hover .bookmark-title {
  color: var(--text);
}

.bookmark-actions {
  display: flex;
  gap: 1px;
  opacity: 0;
  pointer-events: none;
  flex-shrink: 0;
  transition-property: opacity;
  transition-duration: 0.12s;
  transition-timing-function: var(--ease);
}

/* Only show on hover in edit mode */
.editing .bookmark:hover .bookmark-actions {
  opacity: 1;
  pointer-events: auto;
  transition-delay: 0.08s;
}

/* ---- Icon Buttons ---- */

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition-property: background, color;
  transition-duration: 0.1s;
  transition-timing-function: var(--ease);
  position: relative;
  flex-shrink: 0;
}

/* 40px hit area */
.btn-icon::before {
  content: '';
  position: absolute;
  inset: -7px;
}

.btn-icon:hover {
  background: var(--bg);
  color: var(--text-secondary);
}

.btn-icon.danger:hover {
  background: var(--danger-subtle);
  color: var(--danger);
}

.btn-icon.confirming {
  background: var(--danger);
  color: white;
  border-radius: var(--radius-xs);
  width: auto;
  padding: 0 8px;
}

.btn-icon.confirming:hover {
  background: #CC2222;
  color: white;
}

/* ---- Profile Visibility ---- */

.folder-card.folder-hidden {
  opacity: 0.35;
}

.folder-card.folder-hidden:hover {
  opacity: 0.5;
}

.btn-visibility i {
  font-size: 14px;
  line-height: 1;
}

/* Always show actions on hidden folders so user can unhide */
.editing .folder-card.folder-hidden .folder-actions {
  opacity: 1;
  pointer-events: auto;
}

/* ---- Drag Reorder ---- */

.drag-handle {
  display: none;
  align-items: center;
  cursor: grab;
  color: var(--text-tertiary);
  padding: 2px;
  margin: -2px 0;
  border-radius: 3px;
  align-self: center;
  opacity: 0.5;
  transition: opacity 0.15s var(--ease), color 0.15s var(--ease);
}

.drag-handle:hover {
  opacity: 1;
  color: var(--text-secondary);
}

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

body.editing .drag-handle {
  display: flex;
}

.folder-card {
  position: relative;
}

.folder-card.dragging {
  opacity: 0.35;
}

.folder-card.drop-above::before,
.folder-card.drop-below::after {
  content: '';
  position: absolute;
  left: 24px;
  right: 24px;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
  pointer-events: none;
}

.folder-card.drop-above::before { top: -9px; }
.folder-card.drop-below::after { bottom: -9px; }

/* ---- Bookmark Drag ---- */

.bm-drag-handle {
  display: none;
  cursor: grab;
  color: var(--text-tertiary);
  opacity: 0.35;
  flex-shrink: 0;
  padding: 0 2px;
  transition: opacity 0.15s var(--ease);
}

.bm-drag-handle:hover { opacity: 1; }
.bm-drag-handle:active { cursor: grabbing; }

body.editing .bm-drag-handle {
  display: flex;
  align-items: center;
}

.bookmark-list li {
  position: relative;
}

.bookmark-list li.bm-dragging {
  opacity: 0.3;
}

.bookmark-list li.bm-drop-above::before,
.bookmark-list li.bm-drop-below::after {
  content: '';
  position: absolute;
  left: 8px;
  right: 8px;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
  pointer-events: none;
  z-index: 1;
}

.bookmark-list li.bm-drop-above::before { top: -1px; }
.bookmark-list li.bm-drop-below::after { bottom: -1px; }

.folder-card.bm-drop-target {
  box-shadow: var(--shadow-card), inset 0 0 0 2px var(--accent);
}

/* ---- Add Bookmark ---- */

.add-bookmark-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: calc(100% + 16px);
  margin: 8px -8px 0;
  padding: 6px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition-property: border-color, color, background;
  transition-duration: 0.12s;
  transition-timing-function: var(--ease);
  min-height: 34px;
}

.add-bookmark-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-subtle);
}

.add-bookmark-btn:active {
  transform: scale(0.98);
}

/* ---- Add Folder ---- */

.add-folder-card {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 548px;
  min-height: 100px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.02em;
  transition-property: border-color, color, background;
  transition-duration: 0.15s;
  transition-timing-function: var(--ease);
  animation: fadeInUp 0.4s var(--ease) both;
}

.add-folder-card:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-subtle);
}

.add-folder-card:active {
  transform: scale(0.98);
}

/* ---- Modal ---- */

dialog {
  border: none;
  border-radius: var(--radius-md);
  padding: 0;
  max-width: 380px;
  width: calc(100% - 48px);
  margin: auto;
  box-shadow: var(--shadow-modal);
  animation: modalIn 0.2s var(--ease);
  font-family: var(--font-body);
  background: var(--surface);
  color: var(--text);
}

dialog::backdrop {
  background: var(--backdrop-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-card {
  padding: 28px;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  font-style: italic;
  margin-bottom: 22px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  color: var(--text-tertiary);
  margin-bottom: 6px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.form-group input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  font-family: var(--font-body);
  font-size: 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition-property: border-color, box-shadow;
  transition-duration: 0.15s;
  transition-timing-function: var(--ease);
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 102, 51, 0.08);
}

.form-group.hidden {
  display: none;
}

.icon-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 40px;
  align-items: center;
}

.icon-picker.loading {
  justify-content: center;
}

.icon-picker-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
}

.icon-option {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  transition: border-color 0.12s var(--ease), background 0.12s var(--ease), color 0.12s var(--ease);
}

.icon-option:hover {
  border-color: var(--text-tertiary);
  color: var(--text);
}

.icon-option.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
}

.btn-primary,
.btn-secondary {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  padding: 0 18px;
  height: 36px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  letter-spacing: 0.02em;
  transition-property: background, transform;
  transition-duration: 0.12s;
  transition-timing-function: var(--ease);
  border: none;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:active {
  transform: scale(0.96);
}

.btn-secondary {
  background: var(--bg);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background: var(--border);
  color: var(--text);
}

.btn-secondary:active {
  transform: scale(0.96);
}

/* ---- Empty ---- */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-tertiary);
  grid-column: 1 / -1;
  font-size: 13px;
  font-family: var(--font-mono);
}

/* ---- Animations ---- */

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-5px); }
  40%       { transform: translateX(5px); }
  60%       { transform: translateX(-3px); }
  80%       { transform: translateX(3px); }
}

.form-group input.error {
  border-color: var(--danger);
  animation: shake 0.4s var(--ease);
}

.btn-full {
  width: 100%;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.97) translateY(6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ---- Responsive ---- */

@media (max-width: 640px) {
  .header {
    padding: 14px 16px;
    height: auto;
    gap: 10px;
  }

  .search-wrapper { max-width: none; }

  .search-input {
    height: 44px;
    font-size: 16px;
    border-radius: 12px;
  }

  .btn-edit { font-size: 13px; height: 36px; }

  .container {
    padding: 16px 16px 60px;
  }

  .grid { gap: 14px; }
  .folder-card { max-width: none; }

  .folder-card { padding: 20px; }
  .folder-name { font-size: 24px; }
  .folder-count { font-size: 13px; }
  .bookmark { min-height: 44px; padding: 8px 10px; gap: 12px; }
  .bookmark-icon { font-size: 20px; width: 20px; }
  .bookmark-title { font-size: 16px; }
  .folder-divider { margin-bottom: 4px; }
}
