:root {
    --color-bg: #faf8f4;
    --color-panel: #ffffff;
    --color-border: #ddd6c9;
    --color-text: #2e2a24;
    --color-muted: #8a8377;
    --color-accent: #7a5c3e;
    --color-accent-dark: #5e4630;
    --color-error: #b3402c;
    --color-error-bg: #fbeae6;
    --color-success: #3f7a4a;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Georgia, 'Times New Roman', serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--color-panel);
    border-bottom: 1px solid var(--color-border);
}

header h1 {
    margin: 0;
    font-size: 1.4rem;
    letter-spacing: 0.02em;
}

main {
    max-width: 760px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

.panel {
    background: var(--color-panel);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

h2 { margin-top: 0; }

label {
    display: block;
    font-weight: bold;
    margin-top: 1rem;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
}

input[type="text"],
input[type="number"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 1rem;
    background: #fffdfa;
}

textarea { resize: vertical; }

.char-count {
    font-size: 0.8rem;
    color: var(--color-muted);
    text-align: right;
}

button {
    background: var(--color-accent);
    color: #fff;
    border: none;
    padding: 0.55rem 1.1rem;
    border-radius: 4px;
    font-size: 0.95rem;
    cursor: pointer;
    margin-top: 1rem;
}
button:hover { background: var(--color-accent-dark); }
button.secondary {
    background: transparent;
    color: var(--color-accent);
    border: 1px solid var(--color-accent);
}
button.secondary:hover { background: #f2ece3; }

.error-box {
    background: var(--color-error-bg);
    color: var(--color-error);
    border: 1px solid var(--color-error);
    border-radius: 4px;
    padding: 0.75rem 1rem;
    margin-top: 1rem;
    font-size: 0.9rem;
}

.save-status {
    font-size: 0.85rem;
    color: var(--color-muted);
    margin-top: 0.5rem;
}
.save-status.saved { color: var(--color-success); }
.save-status.error { color: var(--color-error); }

ul.card-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
ul.card-list li {
    padding: 0.75rem;
    border-bottom: 1px solid var(--color-border);
}
ul.card-list li:last-child { border-bottom: none; }
ul.card-list a {
    color: var(--color-accent-dark);
    text-decoration: none;
    font-weight: bold;
}
ul.card-list a:hover { text-decoration: underline; }
ul.card-list .meta {
    color: var(--color-muted);
    font-size: 0.85rem;
}
ul.card-list button {
    margin-top: 0.4rem;
    margin-left: 0;
    display: block;
}

/* ---------------------------------------------------------------
   Detail list (Nautilus-style sortable/searchable table)
   --------------------------------------------------------------- */

.dl-wrap { width: 100%; }

.dl-toolbar {
    margin-bottom: 0.75rem;
}
.dl-search {
    width: 100%;
    max-width: 320px;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.9rem;
    background: #fffdfa;
}

table.detail-list {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

table.detail-list thead th {
    text-align: left;
    padding: 0.5rem 0.6rem;
    border-bottom: 2px solid var(--color-border);
    color: var(--color-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
table.detail-list thead th:hover { color: var(--color-accent-dark); }
table.detail-list thead th.dl-sort-active { color: var(--color-accent-dark); }

table.detail-list tbody tr.dl-row {
    cursor: pointer;
    border-bottom: 1px solid var(--color-border);
}
table.detail-list tbody tr.dl-row:hover { background: #f7f2ea; }
table.detail-list tbody tr.dl-row:last-child { border-bottom: none; }

table.detail-list td {
    padding: 0.5rem 0.6rem;
    vertical-align: middle;
    color: var(--color-text);
}

.dl-name-cell { padding-left: var(--dl-indent, 10px) !important; }
.dl-name-inner {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.dl-caret {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 12px;
    height: 12px;
    color: var(--color-muted);
    flex-shrink: 0;
    transition: transform 0.12s ease;
}
.dl-caret-open { transform: rotate(90deg); }
.dl-caret-spacer { visibility: hidden; }

.dl-icon {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

.dl-title {
    font-weight: bold;
    color: var(--color-accent-dark);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dl-empty-row td {
    color: var(--color-muted);
    font-style: italic;
    padding: 1rem 0.6rem;
}

table.detail-list tbody tr.dl-row[draggable="true"] { cursor: grab; }
table.detail-list tbody tr.dl-row.dl-drop-target {
    background: #f2ece3;
    outline: 2px dashed var(--color-accent);
    outline-offset: -2px;
}
table.detail-list tbody tr.dl-row-expanded { background: #fbf8f2; }

tr.dl-action-row {
    cursor: pointer;
    border-bottom: 1px solid var(--color-border);
}
tr.dl-action-row:hover { background: #f7f2ea; }
tr.dl-action-row td { padding: 0.45rem 0.6rem; }
.dl-action-label {
    color: var(--color-accent);
    font-style: italic;
    font-size: 0.88rem;
}

tr.dl-preview-row td, tr.dl-error-row td {
    padding: 0.5rem 0.6rem 0.9rem;
    border-bottom: 1px solid var(--color-border);
}
.dl-inline-preview {
    min-height: 0;
    margin: 0;
    font-size: 0.9rem;
}
.dl-preview-loading { color: var(--color-muted); font-style: italic; }
.dl-preview-error { color: var(--color-error); font-size: 0.85rem; }
.dl-caret-loading { color: var(--color-muted); font-size: 0.7rem; }

.admin-actions-cell { white-space: nowrap; }

.internal-link {
    color: var(--color-accent-dark);
    text-decoration: underline;
    font-weight: bold;
}

.external-link {
    color: #2a6fa8;
    text-decoration: underline dotted;
}
.external-link::after {
    content: " ↗";
    font-size: 0.8em;
}

.body-editor {
    width: 100%;
    min-height: 260px;
    padding: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 1rem;
    background: #fffdfa;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-y: auto;
}
.body-editor:focus { outline: 2px solid var(--color-accent); outline-offset: -1px; }

.link-chip {
    display: inline;
    padding: 0.1em 0.4em;
    border-radius: 3px;
    font-weight: bold;
    cursor: default;
    user-select: none;
}
.link-chip.type-list   { background: #e6dcf5; color: #5b3a8e; }
.link-chip.type-memory { background: #dcf0df; color: #2c6e37; }
.link-chip.type-link   { background: #dce9f7; color: #1f5a92; }

.link-chip.type-image  { background: #f5e6dc; color: #8e5b3a; padding: 0.1em; position: relative; }
.image-thumb-chip img {
    height: 1.4em;
    vertical-align: middle;
    border-radius: 2px;
    display: inline-block;
}
.image-missing { color: var(--color-muted); font-style: italic; }

/* "x" to remove a chip from this memory's text only - never touches
   the underlying image (that's the gallery's separate, permanent
   Delete). Sits inline after the "[image removed]" placeholder text,
   or as a small overlay on a real thumbnail chip. */
.chip-remove-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.2em;
    height: 1.2em;
    margin-left: 0.3em;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(46, 42, 36, 0.55);
    color: #fff;
    font-size: 0.85em;
    line-height: 1;
    cursor: pointer;
    vertical-align: middle;
}
.chip-remove-btn:hover { background: var(--color-error); }
.image-thumb-chip .chip-remove-btn {
    position: absolute;
    top: -0.4em;
    right: -0.4em;
    margin-left: 0;
}

.body-image-link {
    display: inline-block;
    margin: 0.35rem 0.6rem 0.35rem 0;
}
.body-image-thumb {
    display: block;
    max-width: 220px;
    max-height: 220px;
    width: auto;
    height: auto;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    cursor: zoom-in;
}
.body-image-thumb:hover { opacity: 0.9; }

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.image-thumb {
    border: 1px solid var(--color-border);
    border-radius: 4px;
    overflow: hidden;
    background: #fffdfa;
}
.image-thumb img {
    width: 100%;
    height: 90px;
    object-fit: cover;
    display: block;
}
.image-thumb-actions {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.4rem;
}
.image-thumb-actions button {
    margin-top: 0;
    font-size: 0.8rem;
    padding: 0.3rem 0.5rem;
}

.image-upload-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}
.image-upload-form button { margin-top: 0; }

.image-dropzone {
    border: 2px dashed var(--color-border);
    border-radius: 6px;
    padding: 1rem;
    text-align: center;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.image-dropzone.drag-over {
    border-color: var(--color-accent);
    background: #faf3ea;
}
.image-dropzone-text {
    margin: 0 0 0.6rem;
    color: var(--color-muted);
    font-size: 0.88rem;
}
.image-dropzone .image-upload-form {
    justify-content: center;
}

.chip-legend {
    display: inline-flex;
    gap: 0.4rem;
    margin: 0 0.5rem;
}
.chip-legend .link-chip {
    font-size: 0.75rem;
    padding: 0 0.35em;
}

.body-toolbar {
    display: flex;
    gap: 0.5rem;
    margin: 0.75rem 0;
}

.body-preview {
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 0.75rem;
    background: #fffdfa;
    min-height: 200px;
    white-space: normal;
}

.hidden { display: none !important; }

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: var(--color-panel);
    border-radius: 6px;
    padding: 1.5rem;
    width: 90%;
    max-width: 480px;
    max-height: 80vh;
    overflow-y: auto;
}
.modal h3 { margin-top: 0; }

.modal-results {
    list-style: none;
    padding: 0;
    margin: 0.75rem 0 0 0;
    max-height: 320px;
    overflow-y: auto;
}
.modal-results li {
    padding: 0.6rem 0.4rem;
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
}
.modal-results li:hover { background: #f2ece3; }

.modal-divider {
    text-align: center;
    color: var(--color-muted);
    font-size: 0.85rem;
    margin: 1rem 0 0.5rem 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
}

.breadcrumbs {
    font-size: 0.9rem;
    color: var(--color-muted);
    margin-bottom: 1rem;
}
.breadcrumbs a { color: var(--color-accent-dark); }

.nav-bar {
    position: sticky;
    top: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--color-panel);
    border-bottom: 1px solid var(--color-border);
    padding: 0.5rem 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
.nav-bar:empty { display: none; }

.nav-arrow {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    width: 1.9rem;
    height: 1.9rem;
    line-height: 1;
    font-size: 1rem;
    color: var(--color-accent-dark);
    cursor: pointer;
    flex-shrink: 0;
}
.nav-arrow:hover:not(:disabled) { background: #f2ece3; }
.nav-arrow:disabled { color: var(--color-border); cursor: default; }

.nav-breadcrumbs {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.3rem;
    font-size: 0.92rem;
    min-width: 0;
}
.nav-breadcrumbs a { color: var(--color-accent-dark); white-space: nowrap; }
.nav-breadcrumbs .nav-sep { color: var(--color-muted); }
.nav-breadcrumbs .nav-current {
    font-weight: bold;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

nav.top-actions { display: flex; gap: 0.5rem; align-items: center; }
nav.top-actions span { color: var(--color-muted); font-size: 0.9rem; }
nav.top-actions a.nav-link {
    color: var(--color-accent-dark);
    text-decoration: none;
    font-weight: bold;
    margin-right: 0.5rem;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
}
nav.top-actions a.nav-link:hover { background: #f2ece3; }

/* ---------------------------------------------------------------
   Row action ("kebab" ⋮) menus - used on the sharing panel and the
   Manage Users table. Rules are prefixed with .menu-wrap throughout
   so they reliably beat the older `ul.card-list button` rule above
   when a menu is nested inside a card-list (the sharing panel case).
   --------------------------------------------------------------- */
.menu-wrap { position: relative; display: inline-block; flex-shrink: 0; }

.menu-wrap .kebab-btn {
    background: none;
    border: none;
    width: 2rem;
    height: 2rem;
    margin: 0;
    padding: 0;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-muted);
}
.menu-wrap .kebab-btn:hover { background: #f2ece3; color: var(--color-accent-dark); }

.menu-wrap .dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 2.3rem;
    background: var(--color-panel);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(46, 42, 36, 0.16);
    min-width: 170px;
    z-index: 30;
    overflow: hidden;
}
.menu-wrap .dropdown-menu.open { display: block; }
.menu-wrap .dropdown-menu button {
    display: block;
    width: 100%;
    text-align: left;
    margin: 0;
    padding: 0.55rem 0.9rem;
    border: none;
    border-radius: 0;
    background: none;
    color: var(--color-text);
    font-size: 0.88rem;
    cursor: pointer;
}
.menu-wrap .dropdown-menu button:hover { background: #f2ece3; }
.menu-wrap .dropdown-menu button.danger { color: var(--color-error); }
.menu-wrap .dropdown-menu button.danger:hover { background: var(--color-error-bg); }
.menu-wrap .dropdown-menu hr { border: none; border-top: 1px solid var(--color-border); margin: 0; }

/* Sharing panel: puts the name/permission text and the kebab menu
   on one row. Scoped to this class so it doesn't touch card-list's
   other use in commentsPanel.js, which needs its stacked layout. */
ul.card-list li.sharing-grant-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

/* Scrollable container for flat lists once they pass ~10 entries,
   applied conditionally from JS based on actual row count. */
.scroll-limit {
    max-height: 22rem;
    overflow-y: auto;
}
.scroll-limit table.detail-list thead th {
    position: sticky;
    top: 0;
    background: var(--color-panel);
    z-index: 1;
}

/* A little more colour: status pills on Manage Users, reusing the
   same hue family as the body-text link chips elsewhere in the app. */
.status-pill {
    display: inline-block;
    font-size: 0.78rem;
    font-weight: bold;
    padding: 0.15em 0.65em;
    border-radius: 999px;
    white-space: nowrap;
}
.status-active      { background: #dcf0df; color: #2c6e37; }
.status-invited     { background: #dce9f7; color: #1f5a92; }
.status-pending     { background: #ede7db; color: var(--color-muted); }
.status-expired     { background: #f5e6dc; color: #8e5b3a; }
.status-revoked     { background: #fbeae6; color: var(--color-error); }
.status-deactivated { background: #ede7db; color: var(--color-muted); }

/* Login: username prefilled after activating an invite */
input.field-prefilled {
    border-color: var(--color-accent);
    background: #faf3ea;
}

.success-box {
    background: #e9f5ec;
    color: var(--color-success);
    border: 1px solid var(--color-success);
    border-radius: 4px;
    padding: 0.75rem 1rem;
    margin-top: 1rem;
    font-size: 0.9rem;
}

/* ---------------------------------------------------------------
   Global Search
   --------------------------------------------------------------- */

.search-form {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    flex-wrap: wrap;
}
.search-form input[type="text"] { flex: 1 1 260px; margin-top: 0; }
.search-form select { flex: 0 0 auto; width: auto; margin-top: 0; }
.search-form button { margin-top: 0; }

.search-results-list { margin-top: 0.5rem; }
.search-results-list h3 { margin-bottom: 0.4rem; }

li.search-result-row {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    cursor: pointer;
}
li.search-result-row:hover { background: #faf6ee; }

.search-result-body { flex: 1; min-width: 0; }
.search-result-title {
    font-weight: bold;
    color: var(--color-accent-dark);
    text-decoration: none;
}
.search-result-title:hover { text-decoration: underline; }

.search-snippet {
    font-size: 0.88rem;
    color: var(--color-text);
    margin-top: 0.15rem;
}
.search-snippet mark,
.search-result-title mark {
    background: #f5e6a8;
    color: inherit;
    padding: 0 0.1em;
    border-radius: 2px;
}

/* Reuses the same List/Memory hues as the dashboard's row icons
   (see detailList.js ICONS) so a search result reads consistently
   with the rest of the app. */
.type-pill {
    display: inline-block;
    flex: 0 0 auto;
    font-size: 0.72rem;
    font-weight: bold;
    padding: 0.2em 0.55em;
    border-radius: 999px;
    white-space: nowrap;
    margin-top: 0.15rem;
}
.type-pill-list   { background: #ece5f7; color: #5b3a8e; }
.type-pill-memory { background: #dcf0df; color: #2c6e37; }
