/* Expeditioner Keep.
   Palette and fonts lifted from expeditioner.nl/themes/expeditioner/static/css/main.css, so
   this sits next to the other Expeditioner properties without arguing with them. */

@import url('https://fonts.googleapis.com/css2?family=Barlow:ital,wght@0,300;0,400;0,500;1,300;1,400&display=swap');

@font-face {
    font-family: 'Charcuterie';
    src: url('/fonts/CHARCUTERIE-BLOCK-W05-REGULAR.TTF') format('truetype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

:root {
    --navy: #0f1f35;
    --navy2: #162840;
    --navy3: #1c3050;
    --green: #4fc98a;
    --teal: #38bfbf;
    --violet: #8b7cf8;
    --amber: #c8a045;
    --rose: #e0596b;
    --frost: #ddeef5;
    --muted: #8ab0c0;
    --dim: #4a7a90;
    --rule: rgba(138, 176, 192, 0.18);

    --font-display: 'Charcuterie', Georgia, serif;
    --font-body: 'Barlow', 'Segoe UI', Arial, sans-serif;

    --topbar-h: 62px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--navy);
    color: var(--frost);
    font-family: var(--font-body);
    font-weight: 300;
    /* Respect the notch on an installed Android/iOS PWA. */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

button,
input,
textarea {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

/* ── Top bar ─────────────────────────────────────────────────────────────── */

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 14px;
    height: var(--topbar-h);
    padding: 0 16px;
    background: rgba(15, 31, 53, 0.86);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--rule);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--frost);
}

.brand-logo {
    height: 30px;
    width: auto;
}

.brand-name {
    font-family: var(--font-display);
    font-size: 20px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.search {
    position: relative;
    flex: 1;
    max-width: 620px;
    margin-left: auto;
}

.search-icon {
    position: absolute;
    top: 50%;
    left: 12px;
    transform: translateY(-50%);
    color: var(--dim);
    pointer-events: none;
}

.search input {
    width: 100%;
    padding: 10px 14px 10px 42px;
    background: var(--navy2);
    border: 1px solid var(--rule);
    border-radius: 8px;
    outline: none;
}

.search input:focus {
    border-color: var(--teal);
}

.logout-form {
    margin: 0 0 0 auto;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: none;
    border: none;
    border-radius: 8px;
    color: var(--muted);
    cursor: pointer;
}

.icon-btn:hover {
    background: var(--navy2);
    color: var(--green);
}

.icon-btn.is-on {
    color: var(--green);
}

.icon-btn[hidden] {
    display: none;
}

.menu-btn {
    display: none;
}

/* ── Shell ───────────────────────────────────────────────────────────────── */

.shell {
    display: flex;
    align-items: flex-start;
}

.sidebar {
    position: sticky;
    top: var(--topbar-h);
    width: 240px;
    flex: 0 0 240px;
    padding: 18px 10px;
    height: calc(100vh - var(--topbar-h));
    overflow-y: auto;
    border-right: 1px solid var(--rule);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 14px;
    margin-bottom: 2px;
    background: none;
    border: none;
    border-radius: 0 999px 999px 0;
    color: var(--muted);
    text-align: left;
    cursor: pointer;
}

.nav-item:hover {
    background: var(--navy2);
    color: var(--frost);
}

.nav-item.is-active {
    background: rgba(79, 201, 138, 0.12);
    color: var(--green);
}

.nav-count {
    margin-left: auto;
    font-size: 12px;
    color: var(--dim);
}

.nav-heading {
    margin: 18px 0 6px 14px;
    font-size: 11px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--dim);
}

.main {
    flex: 1;
    min-width: 0;
    padding: 24px 20px 80px;
}

.view-label {
    margin: 0 0 14px;
    font-size: 12px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--dim);
}

.bin-notice {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
    margin: 0 auto 28px;
    color: var(--muted);
    font-style: italic;
}

.bin-notice[hidden] {
    display: none;
}

.btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.card.is-binned {
    cursor: default;
}

/* ── Composer ────────────────────────────────────────────────────────────── */

.composer {
    max-width: 620px;
    margin: 0 auto 28px;
}

.composer-collapsed {
    width: 100%;
    padding: 14px 18px;
    background: var(--navy2);
    border: 1px solid var(--rule);
    border-radius: 10px;
    color: var(--muted);
    text-align: left;
    cursor: text;
}

.composer-collapsed:hover {
    border-color: var(--teal);
}

/* ── Note grid ───────────────────────────────────────────────────────────── */

/* Columns, not grid: cards are ragged-height like Keep's, and CSS columns give that for
   free. The trade is that order flows down each column before across, which for a notebook
   nobody reads in strict order is a price worth paying. */
.grid {
    column-width: 260px;
    column-gap: 16px;
}

.card {
    display: block;
    width: 100%;
    margin: 0 0 16px;
    padding: 14px 16px;
    background: var(--card, var(--navy2));
    border: 1px solid var(--rule);
    border-radius: 10px;
    text-align: left;
    cursor: pointer;
    break-inside: avoid;
    -webkit-column-break-inside: avoid;
}

.card:hover {
    border-color: rgba(138, 176, 192, 0.4);
}

.card-title {
    margin: 0 0 6px;
    font-family: var(--font-display);
    font-size: 15px;
    letter-spacing: 1px;
    color: var(--frost);
}

.card-body {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* Markdown formatting in the editor (markdown.js). Every line is a .lp-line; the one being
   edited is .is-active and shows its raw text, so its list and task decorations are off. */
.lp-line {
    position: relative;
    min-height: 1.6em;
}

.lp-h1,
.lp-h2,
.lp-h3,
.lp-h4,
.lp-h5,
.lp-h6 {
    color: var(--frost);
    font-weight: 500;
    line-height: 1.4;
}

.lp-h1 { font-size: 1.35em; }
.lp-h2 { font-size: 1.2em; }
.lp-h3 { font-size: 1.08em; }

.lp-li:not(.is-active) {
    padding-left: 1.3em;
}

.lp-bullet:not(.is-active)::before {
    content: "•";
    position: absolute;
    left: 0.35em;
    color: var(--dim);
}

.lp-task:not(.is-active) {
    padding-left: 0;
}

.lp-check {
    margin: 0 8px 0 0;
    vertical-align: -2px;
    accent-color: var(--green);
    cursor: pointer;
}

.lp-quote {
    padding-left: 10px;
    border-left: 3px solid var(--rule);
    color: var(--dim);
}

.lp-code,
.lp-fence {
    padding: 0 8px;
    background: rgba(0, 0, 0, 0.25);
    font-family: ui-monospace, 'SF Mono', Consolas, monospace;
    font-size: 0.9em;
}

.lp-fence {
    color: var(--dim);
}

.lp-hr:not(.is-active) {
    min-height: 0;
    height: 1px;
    margin: 0.8em 0;
    background: var(--rule);
}

.editor-body strong,
.item-text strong {
    color: var(--frost);
    font-weight: 500;
}

.editor-body a,
.item-text a {
    color: var(--teal);
    cursor: pointer;
}

.editor-body code,
.item-text code {
    padding: 1px 5px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 4px;
    font-family: ui-monospace, 'SF Mono', Consolas, monospace;
    font-size: 0.9em;
}

.card-items {
    margin: 0;
    padding: 0;
    list-style: none;
}

.card-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 3px 0;
    font-size: 14px;
    color: var(--muted);
}

.card-item.is-checked {
    color: var(--dim);
    text-decoration: line-through;
}

.card-item input {
    margin: 3px 0 0;
    accent-color: var(--green);
}

.card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.chip {
    padding: 2px 9px;
    border: 1px solid var(--rule);
    border-radius: 999px;
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--muted);
}

.card-pin {
    float: right;
    color: var(--green);
}

/* Hover toolbar. It keeps its space when hidden, so hovering never makes the grid jump. */
.card-bar {
    display: flex;
    gap: 2px;
    margin: 8px -8px -8px;
    opacity: 0;
    transition: opacity 0.12s ease;
}

.card:hover .card-bar,
.card:focus-within .card-bar,
.card.has-popover .card-bar {
    opacity: 1;
}

.card-bar .icon-btn {
    width: 32px;
    height: 32px;
}

.card-bar svg {
    width: 18px;
    height: 18px;
}

/* No hover on a touch screen, so the bar is simply always there. */
@media (hover: none) {
    .card-bar {
        opacity: 1;
    }
}

/* The card menu and colour palette float over the grid, next to the button that opened them. */
.popover {
    position: fixed;
    z-index: 40;
    background: var(--navy3);
    border: 1px solid var(--rule);
    border-radius: 8px;
    box-shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
}

/* Otherwise the display below wins over the hidden attribute. */
.popover[hidden] {
    display: none;
}

.card-menu {
    min-width: 180px;
    padding: 6px 0;
}

.menu-item {
    display: block;
    width: 100%;
    padding: 8px 16px;
    background: none;
    border: none;
    color: var(--frost);
    font-size: 14px;
    text-align: left;
    cursor: pointer;
}

.menu-item:hover {
    background: var(--navy2);
    color: var(--green);
}

.card-colours {
    display: flex;
    gap: 6px;
    padding: 8px;
}

/* Section headings above the pinned band and the rest, as Keep has. */
.grid-label {
    margin: 0 0 10px;
    font-size: 11px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--dim);
}

#grid-pinned {
    margin-bottom: 26px;
}

/* The "N completed items" toggle: done items are collapsed, not gone. */
.card-toggle {
    display: block;
    margin-top: 8px;
    padding: 2px 0;
    background: none;
    border: none;
    color: var(--dim);
    font-size: 12px;
    cursor: pointer;
}

.card-toggle::before {
    content: "+ ";
}

.card-toggle.is-open::before {
    content: "- ";
}

.card-toggle:hover {
    color: var(--green);
}

/* Dragging */
.card.is-dragging,
.editor-item.is-dragging {
    opacity: 0.45;
}

.card[draggable="true"] {
    cursor: grab;
}

.item-grip {
    color: var(--dim);
    cursor: grab;
    user-select: none;
}

/* Label picker, Keep-style: filter, then every label with a checkbox. */
.label-popover {
    position: absolute;
    z-index: 10;
    width: 260px;
    padding: 12px;
    background: var(--navy3);
    border: 1px solid var(--rule);
    border-radius: 8px;
    box-shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
}

.label-popover-title {
    margin: 0 0 8px;
    font-size: 12px;
    letter-spacing: 1px;
    color: var(--muted);
}

.label-filter {
    width: 100%;
    padding: 6px 8px;
    margin-bottom: 8px;
    background: var(--navy);
    border: none;
    border-bottom: 1px solid var(--rule);
    outline: none;
}

.label-list {
    max-height: 210px;
    overflow-y: auto;
}

.label-row {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 5px 2px;
    font-size: 14px;
    color: var(--frost);
    cursor: pointer;
}

.label-row:hover {
    color: var(--green);
}

.label-row input {
    accent-color: var(--green);
}

.label-create {
    display: block;
    width: 100%;
    padding: 7px 2px;
    margin-top: 6px;
    background: none;
    border: none;
    border-top: 1px solid var(--rule);
    color: var(--teal);
    text-align: left;
    cursor: pointer;
}

.label-create:hover {
    color: var(--green);
}

/* ── Editor dialog ───────────────────────────────────────────────────────── */

.editor {
    width: min(620px, calc(100vw - 32px));
    /* 80%, so there is always backdrop left to click to close it. */
    max-height: 80dvh;
    padding: 0;
    background: var(--card, var(--navy2));
    border: 1px solid var(--rule);
    border-radius: 12px;
    color: var(--frost);
}

.editor::backdrop {
    background: rgba(8, 16, 35, 0.72);
}

.editor-form {
    position: relative; /* the label popover anchors to this */
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* The dialog's height minus its border, so the body or list shrinks instead of the bar
       being pushed off screen. */
    max-height: calc(80dvh - 2px);
    padding: 18px;
}

.editor-title,
.editor-body {
    width: 100%;
    background: none;
    border: none;
    outline: none;
}

.editor-title {
    font-family: var(--font-display);
    font-size: 18px;
    letter-spacing: 1px;
}

/* Grows with the text until the dialog reaches its height, then scrolls inside. */
.editor-body {
    position: relative;
    flex: 0 1 auto;
    min-height: 4lh;
    overflow-y: auto;
    color: var(--muted);
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    cursor: text;
}

/* The same note as plain markdown source, growing like the formatted view. */
.editor-source {
    flex: 0 1 auto;
    min-height: 4lh;
    field-sizing: content;
    overflow-y: auto;
    resize: none;
    padding: 0;
    background: none;
    border: none;
    outline: none;
    color: var(--muted);
    font-family: ui-monospace, 'SF Mono', Consolas, monospace;
    font-size: 0.9em;
    line-height: 1.7;
}

.editor-body.is-empty::before {
    content: attr(data-placeholder);
    position: absolute;
    color: var(--dim);
    pointer-events: none;
}

.editor-items {
    flex: 0 1 auto;
    min-height: 0;
    overflow-y: auto;
    margin: 0;
    padding: 0;
    list-style: none;
}

.editor-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 0;
}

.editor-item input[type="checkbox"] {
    accent-color: var(--green);
}

.item-text {
    flex: 1;
    min-width: 0;
    border-bottom: 1px solid transparent;
    outline: none;
    color: var(--muted);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    cursor: text;
}

.item-text:focus {
    border-bottom-color: var(--rule);
}

.item-text:empty::before {
    content: attr(data-placeholder);
    color: var(--dim);
}

.editor-item.is-checked .item-text {
    color: var(--dim);
    text-decoration: line-through;
}

/* Ticked items are hidden until the "N completed items" toggle expands them. */
.editor-items:not(.show-done) .editor-item.is-checked {
    display: none;
}

.editor-toggle {
    list-style: none;
    margin: 4px 0;
}

.editor-additem,
.item-remove {
    background: none;
    border: none;
    color: var(--dim);
    cursor: pointer;
}

.editor-additem {
    align-self: flex-start;
    padding: 4px 0;
}

.editor-additem:hover,
.item-remove:hover {
    color: var(--green);
}

.editor-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.editor-tags .chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: default;
}

.editor-tags .chip button {
    background: none;
    border: none;
    color: var(--dim);
    cursor: pointer;
}

.editor-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding-top: 8px;
    border-top: 1px solid var(--rule);
}

.colours {
    display: flex;
    gap: 6px;
}

.swatch {
    width: 22px;
    height: 22px;
    background: var(--swatch);
    border: 1px solid var(--rule);
    border-radius: 50%;
    cursor: pointer;
}

.swatch.is-active {
    border-color: var(--green);
    box-shadow: 0 0 0 2px rgba(79, 201, 138, 0.3);
}

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

.btn {
    padding: 9px 18px;
    background: none;
    border: 1px solid var(--rule);
    border-radius: 8px;
    color: var(--frost);
    cursor: pointer;
}

.btn-primary {
    border-color: rgba(79, 201, 138, 0.5);
    background: rgba(79, 201, 138, 0.14);
    color: var(--green);
}

.btn-primary:hover {
    background: rgba(79, 201, 138, 0.22);
}

.btn-danger {
    border-color: rgba(224, 89, 107, 0.5);
    color: var(--rose);
}

/* ── Version history ─────────────────────────────────────────────────────── */

.history {
    width: min(1100px, calc(100vw - 32px));
}

.history-inner {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: calc(80dvh - 2px);
    padding: 18px;
}

.history-heading {
    margin: 0;
    font-size: 12px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--dim);
}

.history-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 16px;
    min-height: 0;
}

.history-list {
    margin: 0;
    padding: 0;
    list-style: none;
    overflow-y: auto;
    border-right: 1px solid var(--rule);
}

.history-entry {
    display: block;
    width: 100%;
    padding: 8px 10px;
    background: none;
    border: none;
    border-radius: 6px;
    text-align: left;
    cursor: pointer;
}

.history-entry:hover {
    background: rgba(138, 176, 192, 0.08);
}

.history-entry.is-active {
    background: rgba(79, 201, 138, 0.12);
}

.history-when {
    display: block;
    font-size: 13px;
    color: var(--frost);
}

.history-entry.is-active .history-when {
    color: var(--green);
}

.history-gist {
    display: block;
    overflow: hidden;
    font-size: 12px;
    color: var(--dim);
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Side by side: the selected version left, the note as it is now right. */
.history-preview {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
    gap: 16px;
    min-height: 120px;
    overflow-y: auto;
}

.diff-col {
    min-width: 0;
}

.diff-label {
    margin: 0 0 8px;
    font-size: 11px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--dim);
}

.diff-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 1px 6px;
    border-radius: 4px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.diff-row.card-title {
    margin: 0 0 6px;
    color: var(--frost);
}

.diff-row input {
    margin: 5px 0 0;
    accent-color: var(--green);
}

.diff-row.is-checked span {
    color: var(--dim);
    text-decoration: line-through;
}

.diff-row.is-removed {
    background: rgba(224, 89, 107, 0.16);
    color: #f0a0aa;
}

.diff-row.is-added {
    background: rgba(79, 201, 138, 0.16);
    color: #9fe3bf;
}

@media (max-width: 820px) {
    .history-preview {
        grid-template-columns: 1fr;
    }

    .history-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(0, 1fr);
    }

    .history-list {
        max-height: 35dvh;
        border-right: none;
        border-bottom: 1px solid var(--rule);
    }
}

/* ── Login ───────────────────────────────────────────────────────────────── */

.login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.login-card {
    width: min(380px, 100%);
    padding: 34px 30px;
    background: var(--navy2);
    border: 1px solid var(--rule);
    border-radius: 12px;
    text-align: center;
}

.login-logo {
    width: 84px;
    height: auto;
    filter: drop-shadow(0 4px 24px rgba(79, 201, 138, 0.25));
}

.login-title {
    margin: 12px 0 2px;
    font-family: var(--font-display);
    font-size: 28px;
    letter-spacing: 3px;
    text-transform: uppercase;
}

.login-sub {
    margin: 0 0 22px;
    font-style: italic;
    color: var(--muted);
}

.login-error {
    margin: 0 0 16px;
    padding: 8px 12px;
    background: rgba(224, 89, 107, 0.12);
    border: 1px solid rgba(224, 89, 107, 0.4);
    border-radius: 8px;
    color: var(--rose);
    font-size: 14px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    text-align: left;
}

.field span {
    display: block;
    margin-bottom: 5px;
    font-size: 11px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--dim);
}

.field input {
    width: 100%;
    padding: 10px 12px;
    background: var(--navy);
    border: 1px solid var(--rule);
    border-radius: 8px;
    outline: none;
}

.field input:focus {
    border-color: var(--teal);
}

.check {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 14px;
    color: var(--muted);
}

.check input {
    accent-color: var(--green);
}

/* ── Bits ────────────────────────────────────────────────────────────────── */

.empty {
    margin-top: 60px;
    text-align: center;
    color: var(--dim);
    font-style: italic;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    z-index: 50;
    transform: translateX(-50%);
    padding: 11px 18px;
    background: var(--navy3);
    border: 1px solid var(--rule);
    border-radius: 8px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
    font-size: 14px;
}

/* ── Phone ───────────────────────────────────────────────────────────────── */

@media (max-width: 820px) {
    .menu-btn {
        display: inline-flex;
    }

    .brand-name {
        display: none;
    }

    .sidebar {
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        z-index: 25;
        background: var(--navy);
        transform: translateX(-100%);
        transition: transform 0.18s ease;
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .main {
        padding: 16px 12px 90px;
    }

    .grid {
        column-width: 160px;
        column-gap: 12px;
    }
}
