* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Two-column layout */
.collections-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Sidebar */
.collections-sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--line);
}
.sidebar-header h2 { font-size: 14px; font-weight: 700; margin: 0; }
.sidebar-list {
  flex: 1; overflow-y: auto; padding: 8px 0;
}
.sidebar-empty {
  font-size: 13px; color: var(--fg-mute); text-align: center;
  padding: 24px 14px; margin: 0;
}
.sidebar-empty[hidden] { display: none; }

/* Sidebar items */
.sidebar-item {
  display: flex; flex-direction: column;
  cursor: pointer; transition: background .15s;
}
.sidebar-item-header {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 14px; font-size: 14px; font-weight: 600;
  color: var(--fg); transition: background .15s;
}
.sidebar-item-header:hover { background: var(--bg-elev-2); }
.sidebar-item.active > .sidebar-item-header {
  background: var(--bg-elev-2);
  border-left: 3px solid var(--accent);
  padding-left: 11px;
}
.sidebar-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Sidebar expanded stats */
.sidebar-item-stats {
  display: none; padding: 2px 14px 8px 26px;
  font-size: 12px; color: var(--fg-mute); line-height: 1.7;
}
.sidebar-item.active .sidebar-item-stats { display: block; }
.sidebar-stat-line::before { content: "– "; opacity: .5; }

.sidebar-item-daterange {
  padding: 0 14px 6px 26px;
  font-size: 11px; color: var(--fg-dim);
  display: none;
}
.sidebar-item.active .sidebar-item-daterange { display: block; }

.detail-calendar-link {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--accent);
  text-decoration: none; margin-bottom: 20px;
  opacity: .85; transition: opacity .15s;
}
.detail-calendar-link:hover { opacity: 1; }
.detail-calendar-link[hidden] { display: none; }

/* Detail pane */
.collection-detail {
  overflow-y: auto; padding: 28px 32px;
}
.detail-placeholder {
  display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--fg-mute); font-size: 15px;
}
.detail-placeholder[hidden] { display: none; }
.detail-placeholder p { margin: 0; }
.detail-content[hidden] { display: none; }

/* Detail header */
.detail-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 16px; gap: 16px;
}
.detail-header h1 {
  font-size: 24px; font-weight: 700; margin: 0; flex: 1;
  outline: none; min-width: 0; word-break: break-word;
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
  padding-bottom: 2px;
}
.detail-header h1:focus { border-bottom-color: var(--accent); }
.detail-header h1:empty::before {
  content: attr(data-placeholder); color: var(--fg-mute); font-weight: 400;
}

/* Description */
.detail-desc-wrap { margin-bottom: 24px; }
.detail-desc-wrap textarea {
  width: 100%; font: inherit; font-size: 14px; color: var(--fg);
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; outline: none;
  resize: vertical; transition: border-color .2s;
}
.detail-desc-wrap textarea:focus { border-color: var(--accent); }
.detail-desc-wrap textarea::placeholder { color: var(--fg-dim); }

/* Date fields */
.detail-dates-wrap { display: flex; gap: 12px; margin-bottom: 24px; }
.detail-date-field { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.detail-date-field label { font-size: 11px; font-weight: 600; color: var(--fg-mute); text-transform: uppercase; letter-spacing: .04em; }
.detail-date-field input[type="date"] {
  width: 100%; font: inherit; font-size: 13px; color: var(--fg);
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; outline: none;
  transition: border-color .2s; cursor: pointer;
}
.detail-date-field input[type="date"]:focus { border-color: var(--accent); }

/* Linked sections */
.detail-section { margin-bottom: 24px; }
.detail-section-header {
  font-size: 12px; font-weight: 700; color: var(--fg-mute);
  text-transform: uppercase; letter-spacing: .04em;
  margin: 0 0 10px; padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.detail-items { display: flex; flex-direction: column; gap: 4px; }

.detail-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 8px;
  background: var(--bg-elev); border: 1px solid var(--line);
  font-size: 14px; cursor: pointer;
  transition: border-color .2s, background .15s;
}
.detail-item:hover { border-color: rgba(110,168,255,.25); background: var(--bg-elev-2); }
.detail-item-name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-item-arrow { color: var(--fg-mute); font-size: 14px; flex-shrink: 0; }
.detail-item-unlink {
  background: transparent; border: none; color: var(--fg-mute); cursor: pointer;
  font-size: 14px; padding: 2px 6px; border-radius: 4px; flex-shrink: 0;
  opacity: 0; transition: opacity .15s, color .15s;
}
.detail-item:hover .detail-item-unlink { opacity: 1; }
.detail-item-unlink:hover { color: var(--danger, #f87171); background: rgba(248,113,113,.1); }

.detail-section-hint {
  font-size: 12px; color: var(--fg-mute); margin: 6px 0 0;
}

/* Add bar */
.detail-add-bar {
  display: flex; gap: 8px; flex-wrap: wrap;
  padding-top: 8px; border-top: 1px solid var(--line);
}
.add-bar-btn {
  font: inherit; font-size: 13px; font-weight: 600;
  color: var(--fg-mute); background: transparent;
  border: 1px dashed rgba(154,164,199,.25);
  border-radius: 8px; padding: 7px 14px;
  cursor: pointer; transition: color .2s, border-color .2s;
}
.add-bar-btn:hover { color: var(--accent); border-color: var(--accent); }

/* Make .main a flex column so collections-layout can fill it */
.main { display: flex; flex-direction: column; }

@media (max-width: 700px) {
  /* Layout */
  .app { grid-template-columns: 1fr; }
  .rail { display: none; }

  /* Stack sidebar above detail */
  .collections-layout { grid-template-columns: 1fr; }
  .collections-sidebar {
    max-height: 220px;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  /* Detail pane: tighter padding */
  .collection-detail { padding: 20px 16px; }
  .detail-header h1 { font-size: 20px; }

  /* Unlink buttons always visible on touch */
  .detail-item-unlink { opacity: 1; }

  /* Add bar buttons fill width */
  .detail-add-bar { flex-direction: column; }
  .add-bar-btn { width: 100%; text-align: center; }

  /* Bottom padding for nav bar */
  body::after { content: ''; display: block; height: 60px; }
}

/* Bottom nav (mobile only) */
.mobile-bottom-nav { display: none; }
@media (max-width: 700px) {
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 60px;
    background: var(--bg-elev);
    border-top: 1px solid var(--line);
    z-index: 100;
    align-items: center;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding: 0 12px; gap: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    color: var(--fg-mute);
    text-decoration: none;
    padding: 6px 10px;
    border-radius: var(--radius-xs, 6px);
    transition: color .15s;
    min-width: 56px; flex-shrink: 0;
    text-align: center;
  }
  .mobile-nav-item[data-active] { color: var(--accent); }
  .mobile-nav-item svg { flex-shrink: 0; }
}
