:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-alt: #faf9f6;
  --text: #1f2421;
  --muted: #5c635e;
  --border: #e2dfd7;
  --accent: #2f5d50;
  --accent-soft: #e6f0ed;
  --danger: #b43c3c;
  --danger-soft: #fceaea;
  --warn-bg: #fff6e0;
  --warn-text: #8a5a00;
  --warn-border: #f0d58c;
  --highlight: #ffe58f;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] {
  --bg: #141716;
  --surface: #1d2220;
  --surface-alt: #232927;
  --text: #eef1ef;
  --muted: #9ea8a2;
  --border: #2f3734;
  --accent: #5fa893;
  --accent-soft: #1f352f;
  --danger: #e06c6c;
  --danger-soft: #3a2020;
  --warn-bg: #332914;
  --warn-text: #f3c96b;
  --warn-border: #59461c;
  --highlight: #755b14;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

/* Non-sticky compact top header */
.top-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.top-header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

button.btn,
a.btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  padding: 5px 9px;
  border-radius: 7px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
  font-family: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
button.btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
button.btn.active,
button.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button.btn.primary:hover {
  filter: brightness(1.06);
}
button.btn.danger {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}
button.btn.danger:hover {
  background: var(--danger-soft);
}
button.btn.danger-solid {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
button.btn.sm {
  padding: 3px 7px;
  font-size: 0.75rem;
}
button.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.admin-only {
  display: none !important;
}
body.is-admin .admin-only {
  display: inline-flex !important;
}

/* Export dropdown */
.dropdown {
  position: relative;
  display: inline-block;
}
.dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 170px;
  z-index: 40;
  padding: 4px;
}
.dropdown.open .dropdown-menu {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dropdown-item {
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: pointer;
  font-family: inherit;
}
.dropdown-item:hover {
  background: var(--accent-soft);
}

/* Slim single-row sticky search & filter bar */
.sticky-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.sticky-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 8px 14px;
}
.controls {
  display: flex;
  gap: 8px;
  align-items: center;
}
.search-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}
.search-wrap input {
  width: 100%;
  padding: 7px 30px 7px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}
.search-wrap input:focus {
  border-color: var(--accent);
  background: var(--surface);
}
.clear-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 5px;
  display: none;
}
.clear-btn.visible { display: block; }

select.shelf-select {
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
  flex: 0 0 auto;
  max-width: 135px;
}
select.shelf-select:focus {
  border-color: var(--accent);
}

.count-badge {
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 9px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}

/* Optional collapsible pills drawer */
.shelf-pills-wrap {
  display: none;
  padding-top: 8px;
  margin-top: 8px;
  border-top: 1px dashed var(--border);
}
.shelf-pills-wrap.open {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.pill {
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.pill:hover {
  border-color: var(--accent);
  color: var(--text);
}
.pill.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

main {
  max-width: 1120px;
  margin: 14px auto 60px;
  padding: 0 14px;
}

.shelf-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.shelf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 14px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.shelf-card.collapsed .shelf-header {
  border-bottom: none;
}
.shelf-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.95rem;
}
.shelf-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.shelf-badge {
  background: var(--accent);
  color: #fff;
  padding: 1px 8px;
  border-radius: 5px;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}
.shelf-count {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 500;
}
.chevron {
  color: var(--muted);
  transition: transform 0.2s;
  font-size: 0.85rem;
}
.shelf-card.collapsed .chevron {
  transform: rotate(-90deg);
}
.shelf-card.collapsed .shelf-body {
  display: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
th {
  text-align: left;
  padding: 7px 12px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-alt); }

.col-br {
  width: 52px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.col-autor {
  width: 28%;
  font-weight: 500;
}
.col-naslov {
  width: auto;
}
.col-actions {
  width: 155px;
  text-align: right;
  white-space: nowrap;
}
th.col-actions {
  text-align: right;
}
body:not(.is-admin) .col-actions {
  display: none;
}

.row-actions {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.note-tag {
  display: inline-block;
  margin-top: 3px;
  padding: 1px 7px;
  border-radius: 5px;
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid var(--warn-border);
  font-size: 0.76rem;
}
mark {
  background: var(--highlight);
  color: inherit;
  padding: 0 2px;
  border-radius: 3px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal-backdrop.open {
  display: flex;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal.wide {
  max-width: 560px;
}
.modal-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.modal-header h2 {
  margin: 0;
  font-size: 1rem;
}
.modal-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.15rem;
  cursor: pointer;
  padding: 2px 6px;
}
.modal-body {
  padding: 14px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--surface-alt);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: 10px;
}
.form-field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}
.form-field input,
.form-field select,
.form-field textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  border-color: var(--accent);
  background: var(--surface);
}
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}
.form-error {
  color: var(--danger);
  font-size: 0.82rem;
  display: none;
}
.form-error.visible {
  display: block;
}

/* Shelves manager list */
.shelf-mgr-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.shelf-mgr-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
}
.shelf-mgr-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.shelf-mgr-name {
  font-weight: 600;
  font-size: 0.9rem;
}
.shelf-mgr-count {
  font-size: 0.78rem;
  color: var(--muted);
}
.shelf-mgr-btns {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.inline-add-shelf {
  display: flex;
  gap: 8px;
}
.inline-add-shelf input {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.88rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
  box-shadow: var(--shadow);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 680px) {
  .count-badge {
    padding: 4px 7px;
    font-size: 0.74rem;
  }
  select.shelf-select {
    max-width: 105px;
    font-size: 0.82rem;
    padding: 7px 6px;
  }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
  }
  td {
    padding: 1px 0;
    border: none;
  }
  .col-br {
    display: inline-block;
    width: auto;
    margin-right: 6px;
    font-size: 0.8rem;
  }
  .col-autor {
    display: inline;
    width: auto;
    color: var(--accent);
    font-weight: 600;
  }
  .col-naslov {
    display: block;
    margin-top: 2px;
  }
  .col-actions {
    width: 100%;
    text-align: left;
    margin-top: 6px;
  }
}
