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

html { background: #1a1a2e; } /* fills status-bar gap on iOS PWA */

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #1a1a2e;
  color: #222;
  padding-top: env(safe-area-inset-top, 0px);
}

nav {
  background: #1a1a2e;
  color: #fff;
  padding: 0.75rem 1.5rem;
  padding-top: 0.75rem;
  display: flex;
  gap: 1.5rem;
  align-items: center;
}
nav a { color: #ccc; text-decoration: none; }
nav a:hover { color: #fff; }
nav .nav-brand { font-weight: 700; color: #fff; font-size: 1.1rem; }

main { height: calc(100vh - 50px - env(safe-area-inset-top, 0px)); }

/* --- Master-detail --- */

.master-detail {
  display: flex;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.master {
  width: 35%;
  border-right: 1px solid #ddd;
  background: #fff;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.filter-bar {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #eee;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 10;
}

.filter-list {
  list-style: none;
  border-bottom: 1px solid #eee;
  padding: 0.35rem 0;
}
.filter-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
  gap: 0.5rem;
}
.filter-item:hover { background: #f0f4ff; }
.filter-item.active { background: #e0e8ff; }
.filter-name { font-weight: 500; flex: 1; }
.filter-item.active .filter-name { color: #1d4ed8; }
.filter-count {
  font-size: 0.78rem;
  color: #888;
  background: #f3f4f6;
  padding: 0.1rem 0.45rem;
  border-radius: 10px;
  min-width: 1.6rem;
  text-align: center;
}
.filter-item.active .filter-count { background: #bfdbfe; color: #1d4ed8; }

.toggle-btn {
  padding: 0.3rem 0.9rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #f5f5f5;
  color: #555;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.toggle-btn.active {
  background: #dbeafe;
  color: #1d4ed8;
  border-color: #bfdbfe;
}
.toggle-btn:hover:not(.active) { background: #e8e8e8; }

.search-input {
  width: 100%;
  padding: 0.4rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.9rem;
  outline: none;
}
.search-input:focus { border-color: #93c5fd; }

.master-list-wrap { flex: 1; }

#bookmark-list { list-style: none; }
#bookmark-list li {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
#bookmark-list li:hover { background: #f0f4ff; }
#bookmark-list li.active { background: #e0e8ff; }

.item-title { font-weight: 500; font-size: 0.92rem; line-height: 1.3; }
.item-domain { font-size: 0.78rem; color: #888; }
.item-date { font-size: 0.75rem; color: #aaa; }

.list-empty { padding: 2rem 1.25rem; color: #999; font-size: 0.9rem; text-align: center; }
.list-loading { padding: 2rem 1.25rem; color: #999; font-size: 0.9rem; text-align: center; }


/* --- Detail panel --- */

.detail {
  width: 65%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}
#detail-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.placeholder { color: #999; margin-top: 4rem; text-align: center; font-size: 0.95rem; }

.reader-bar {
  flex-shrink: 0;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #ddd;
  background: #fff;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.reader-title {
  flex: 1;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.mode-toggle {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}
.reader-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  flex-wrap: wrap;
}

#detail-frame {
  flex: 1;
  border: none;
  width: 100%;
  background: #fff;
}

.frame-fallback {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  background: #f5f5f5;
  color: #666;
}
.fallback-msg { font-size: 1rem; color: #888; }

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

.btn {
  padding: 0.6rem 1.5rem;
  border: none;
  border-radius: 6px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn-read { background: #dbeafe; color: #1d4ed8; }
.btn-read:hover { background: #bfdbfe; }
.btn-open { background: #d1fae5; color: #047857; }
.btn-open:hover { background: #a7f3d0; }
.btn-delete { background: #fee2e2; color: #b91c1c; }
.btn-delete:hover { background: #fecaca; }
.btn-yes { background: #fff; border: 2px solid currentColor; }
.btn-no { background: transparent; color: #666; border: 1px solid #ccc; }
.btn-save { background: #dbeafe; color: #1d4ed8; }
.btn-save:hover { background: #bfdbfe; }
.btn-cancel { background: #f3f4f6; color: #555; }
.btn-cancel:hover { background: #e5e7eb; }

.hidden { display: none !important; }

.confirm-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.88rem;
  width: 100%;
}
.confirm-delete { background: #fee2e2; color: #b91c1c; }

/* --- Form pages (add, settings) --- */

.form-page {
  padding: 2rem;
  max-width: 560px;
}
.form-page h2 { font-size: 1.3rem; margin-bottom: 1.5rem; }
.settings-section-title { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: #888; margin: 1.75rem 0 0.6rem; }

.card-form {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.form-field { margin-bottom: 1.25rem; }
.form-field:last-child { margin-bottom: 0; }
.field-label { font-weight: 600; font-size: 0.85rem; color: #555; margin-bottom: 0.3rem; display: block; }
.field-optional { font-weight: 400; color: #999; }
.field-hint { font-size: 0.82rem; color: #888; margin-bottom: 0.3rem; }

.form-input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 0.92rem;
  font-family: inherit;
  outline: none;
}
.form-input:focus { border-color: #93c5fd; }
.form-textarea { min-height: 90px; resize: vertical; }

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.radio-group { display: flex; gap: 1.5rem; }
.radio-label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.92rem; cursor: pointer; }

.filter-setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid #f0f0f0;
}
.filter-setting-row:last-child { border-bottom: none; }
.filter-setting-info { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; flex: 1; }
.filter-setting-name { font-weight: 500; font-size: 0.9rem; }
.filter-setting-query { font-size: 0.8rem; color: #555; background: #f3f4f6; padding: 0.1rem 0.4rem; border-radius: 3px; }
.filter-setting-badge { font-size: 0.75rem; color: #888; background: #f3f4f6; padding: 0.1rem 0.4rem; border-radius: 3px; }
.btn-sm { padding: 0.25rem 0.65rem; font-size: 0.8rem; }

.form-error {
  background: #fee2e2;
  color: #b91c1c;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.form-hint {
  font-size: 0.85rem;
  color: #777;
  margin-top: 0.75rem;
}

/* --- Reader loading spinner --- */

.reader-loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f5;
}
.reader-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #ddd;
  border-top-color: #1d4ed8;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Swipe transition animations --- */

@keyframes slide-in-from-right {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: none; }
}
@keyframes slide-in-from-left {
  from { opacity: 0; transform: translateX(-40px); }
  to   { opacity: 1; transform: none; }
}
.slide-in-right { animation: slide-in-from-right 0.22s ease; }
.slide-in-left  { animation: slide-in-from-left  0.22s ease; }

/* --- Swipe zones (sit over iframe to capture touch events) --- */

.swipe-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 28px;
  z-index: 200;
}
.swipe-zone-left  { left: 0; }
.swipe-zone-right { right: 0; }

/* --- Back button (mobile only) --- */

.back-btn {
  display: none;
  background: none;
  border: none;
  font-size: 1.3rem;
  color: #1d4ed8;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  flex-shrink: 0;
  line-height: 1;
}

/* --- Mobile icon bar buttons --- */

.icon-btn {
  background: none;
  border: none;
  padding: 0.55rem;
  color: #333;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { color: #1d4ed8; }
.icon-btn.icon-active { color: #1d4ed8; }
.icon-placeholder { color: #bbb; cursor: default; }

.mobile-menu-popup {
  position: absolute;
  bottom: 60px;
  right: 0.5rem;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.13);
  z-index: 160;
  min-width: 170px;
  overflow: hidden;
}
.menu-popup-item {
  display: block;
  width: 100%;
  padding: 0.8rem 1.1rem;
  background: none;
  border: none;
  border-bottom: 1px solid #f0f0f0;
  text-align: left;
  font-size: 0.92rem;
  font-family: inherit;
  cursor: pointer;
  color: #222;
}
.menu-popup-item:last-child { border-bottom: none; }
.menu-popup-item:active { background: #f0f4ff; }
#mb-read.icon-read svg circle { fill: currentColor; }
#mb-star.icon-starred { color: #f59e0b; }
#mb-star.icon-starred svg polygon { fill: currentColor; }

/* --- Mobile bars (hidden on desktop) --- */

.mobile-top-bar,
.mobile-bottom-bar { display: none; }

.mobile-top-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 48px;
  background: #fff;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0 0.5rem;
  z-index: 150;
  transition: transform 0.28s ease;
}

.mobile-bar-title {
  flex: 1;
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.mobile-bottom-bar {
  position: fixed;
  bottom: env(safe-area-inset-bottom, 0px);
  left: 0; right: 0;
  height: 44px;
  background: #fff;
  border-top: 1px solid #eee;
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 150;
  transition: transform 0.25s ease;
}


/* --- Mobile layout --- */

/* --- Tag editor sheet --- */

.tag-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 300;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.tag-sheet-backdrop.open { opacity: 1; }

.tag-sheet {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-radius: 16px 16px 0 0;
  z-index: 301;
  max-height: 80%;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.25s ease;
}
.tag-sheet.open { transform: translateY(0); }

.tag-sheet-handle {
  width: 36px; height: 4px;
  background: #ddd; border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}

.tag-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  padding-left: max(1.25rem, env(safe-area-inset-left));
  padding-right: max(1.25rem, env(safe-area-inset-right));
  border-bottom: 1px solid #eee;
  flex-shrink: 0;
}
.tag-sheet-title { font-weight: 600; font-size: 0.95rem; }
.tag-sheet-cancel {
  background: none; border: none; cursor: pointer;
  font-size: 0.95rem; font-family: inherit;
  color: #666; padding: 0.25rem 0;
}
.tag-sheet-done {
  background: none; border: none; cursor: pointer;
  font-size: 0.95rem; font-family: inherit;
  color: #1d4ed8; font-weight: 600; padding: 0.25rem 0;
}

.tag-sheet-body {
  overflow-y: auto;
  flex: 1;
  padding: 1rem 1.25rem;
  padding-left: max(1.25rem, env(safe-area-inset-left));
  padding-right: max(1.25rem, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tag-section-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #888;
}

.tag-pills-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-height: 1.5rem;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.3rem 0.5rem 0.3rem 0.75rem;
  background: rgba(29,78,216,0.1);
  color: #1d4ed8;
  border-radius: 16px;
  font-size: 0.85rem;
}
.tag-pill-remove {
  background: none; border: none; cursor: pointer;
  color: #1d4ed8; font-size: 1.1rem; line-height: 1;
  padding: 0; opacity: 0.6; display: flex; align-items: center;
}
.tag-pill-remove:active { opacity: 1; }

.tag-quick-pill {
  padding: 0.3rem 0.75rem;
  border-radius: 16px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid #bbb;
  background: none;
  color: #666;
}
.tag-quick-pill.selected {
  background: #1d4ed8;
  color: #fff;
  border-color: #1d4ed8;
}

.tag-input { margin-top: 0.25rem; }

.tag-suggestions {
  list-style: none;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  overflow-y: auto;
  max-height: 200px;
  margin-top: -0.25rem;
}
.tag-suggestions li {
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  font-size: 0.9rem;
  border-bottom: 1px solid #f0f0f0;
  color: #333;
}
.tag-suggestions li:last-child { border-bottom: none; }
.tag-suggestions li:active { background: #f0f4ff; }

.tag-empty { color: #bbb; font-size: 0.85rem; font-style: italic; }

/* --- Notes sheet --- */

.notes-sheet-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 1rem 1.25rem;
  padding-left: max(1.25rem, env(safe-area-inset-left));
  padding-right: max(1.25rem, env(safe-area-inset-right));
}

.notes-view {
  flex: 1;
  font-size: 0.95rem;
  line-height: 1.6;
  color: #222;
  min-height: 4rem;
}
.notes-view p { margin: 0.4em 0; }
.notes-view h1, .notes-view h2, .notes-view h3 { margin: 0.75em 0 0.35em; font-size: 1em; font-weight: 700; }
.notes-view ul, .notes-view ol { padding-left: 1.4em; }
.notes-view a { color: #1d4ed8; }
.notes-view code { background: #f3f4f6; border-radius: 3px; padding: 0.1em 0.35em; font-size: 0.88em; font-family: ui-monospace, monospace; }
.notes-view pre { background: #f3f4f6; border-radius: 5px; padding: 0.75rem; overflow-x: auto; }
.notes-view pre code { background: none; padding: 0; }
.notes-view blockquote { margin: 0; padding-left: 1rem; border-left: 3px solid #ddd; color: #666; }
.notes-empty { color: #bbb; font-size: 0.9rem; font-style: italic; }

.notes-textarea {
  flex: 1;
  min-height: 260px;
  resize: none;
  font-size: 0.95rem;
  line-height: 1.6;
  font-family: inherit;
}

@media (max-width: 700px) {
  nav { padding: 0.5rem 1rem; gap: 1rem; }
  nav .nav-brand { font-size: 1rem; }
  main { height: calc(100vh - 44px - env(safe-area-inset-top, 0px)); }

  .master-detail { flex-direction: column; }

  .master {
    width: 100%;
    height: 100%;
    border-right: none;
    border-bottom: 1px solid #ddd;
  }

  .detail {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background: #fff;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    z-index: 100;
  }

  /* Cover viewport below status bar when detail is open */
  .detail.mobile-open {
    position: fixed;
    top: env(safe-area-inset-top, 0px);
    left: 0;
    right: 0;
    bottom: 0;
    height: auto;
    transform: translateX(0);
  }

  /* Show mobile bars, hide desktop reader bar */
  .reader-bar { display: none; }
  .mobile-top-bar    { display: flex; }
  .mobile-bottom-bar { display: flex; }

  /* Offset content so it doesn't hide behind the fixed bars */
  #detail-content {
    padding-top: 48px;
    padding-bottom: calc(44px + env(safe-area-inset-bottom, 0px));  /* matches bottom bar height */
  }

  .back-btn { display: block; }

  .form-page { padding: 1.25rem; }
}
