/* Ms. Tilds — plain CSS. Turquoise sidebar (complements the logo blue),
   white content. */

:root {
    --turq:        #d39626;  /* accent: dates, buttons, focus, active states */
    --turq-dark:   #a3751e;  /* accent hover */
    --turq-active: #d39626;
    --board:        #2f3438;  /* sidebar bg — overridable live via the color picker */
    --nav-text:     #ffffff;
    --nav-text-dim: #d7dbdf;
    --nav-hover:    rgba(255,255,255,0.12);
    --nav-border:   rgba(255,255,255,0.18);
    --logo-blue:   #b22121;  /* from the logo circle */
    --green:       #0da483;  /* apple/accent from logo */
    --ink:         #371f1f;  /* header color */
    --ink-soft:    #5b6470;
    --surface:     #ffffff;
    --bg-soft:     #f5f7f8;
    --border:      #e2e6e9;
    --border-faint:#eef1f2;
    --radius:      8px;
    --sans:    "Raleway", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --display: "Cabin Sketch", sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body { font-family: var(--sans); color: var(--ink); background: var(--bg-soft); }

/* ---- Shell -------------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; align-items: flex-start; background: var(--surface); }

.sidebar {
    --nav-overhang: 30px;   /* extend the nav up off-screen so the shadow reaches the top edge */
    width: 240px;
    flex-shrink: 0;
    background: var(--board);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: calc(1.25rem + var(--nav-overhang)) 0 1.25rem;
    margin-top: calc(-1 * var(--nav-overhang));
    position: relative;
    z-index: 1;
    /* Drop shadow around the whole bookmark silhouette (ribbon + tail) onto the page. */
    filter: drop-shadow(4px 6px 6px rgba(0, 0, 0, 0.5));
}

/* Bookmark curls over the top edge: a soft shadow at the top fading downward */
.sidebar::before {
    content: "";
    position: absolute;
    top: var(--nav-overhang);   /* sit at the visible top, not the off-screen extension */
    left: 0;
    right: 0;
    height: 32px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.25), rgba(0, 0, 0, 0));
    pointer-events: none;
    z-index: 3;
}

/* Book fore-edge on the RIGHT of the content — content reads as the (left) page,
   with the stacked pages + rounded cover edge beyond its outer edge.
   Order left→right: page · stacked fore-edge · rounded cover */

/* Stacked page fore-edge: cream block with fine vertical striations (~half inch) */
.main::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    right: 12px;
    width: 44px;
    z-index: 2;
    background:
        repeating-linear-gradient(90deg,
            #ece4d5 0, #ece4d5 2px,
            #d0c6b1 2px, #d0c6b1 3px);
    /* pages recede into shadow toward the cover (right side) */
    box-shadow: inset -14px 0 14px -8px rgba(0, 0, 0, 0.4);
}

/* Rounded dark cover edge, casting the shadow leftward onto the page */
.main::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    width: 12px;
    z-index: 2;
    background: linear-gradient(90deg, #20252a 0, #3d444a 50%, #20252a 100%);
    box-shadow:
        inset 3px 0 5px rgba(0, 0, 0, 0.5),
        inset -3px 0 5px rgba(0, 0, 0, 0.5),
        -8px 0 48px 0 rgba(0, 0, 0, 0.6);
}

/* Bookmark tail: the nav ribbon comes to a downward point below its content.
   White page shows around it (shell bg); drop-shadow falls left onto that page.
   Tucked a few px up under the ribbon so its top edge/shadow doesn't show as a line. */
.nav-tail {
    position: absolute;
    top: calc(100% - 2px);   /* overlap the square part so the seam is solid, no white gap */
    left: 0;
    right: 0;
    height: 46px;
    background: var(--board);
    /* Straight full-width shoulders (6px) then taper to the point: the seam falls
       inside the straight section, so it stays edge-aligned even with the overlap. */
    clip-path: polygon(0 0, 100% 0, 100% 6px, 50% 100%, 0 6px);
    /* shadow handled by the parent .sidebar filter so the whole nav casts as one shape */
    z-index: 1;
}

.sidebar-logo { display: block; padding: 0 1rem 1.25rem; margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--nav-border); }
.sidebar-logo-img { width: 80%; max-width: 250px; height: auto; display: block; margin: 0 auto; }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 0 0.75rem; }
.nav-link {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.6rem 0.85rem;
    color: var(--nav-text-dim);
    text-decoration: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    transition: background 0.12s;
}
.nav-link:hover { background: var(--nav-hover); color: var(--nav-text); }
.nav-link.active { background: var(--turq); color: #fff; font-weight: 600; }
.nav-ico { opacity: 0.9; width: 1.2em; text-align: center; font-size: 1.05rem; flex-shrink: 0; }

.nav-header {
    font-family: var(--display); font-weight: 700;
    font-size: 1.3rem; color: var(--nav-text); opacity: 0.9;
    padding: 0.85rem 0.85rem 0.15rem;
}
.nav-divider {
    border: 0; border-top: 1px solid var(--nav-border);
    margin: 0.55rem 0.85rem;
}

.sidebar-foot {
    padding: 0 0.75rem;
    margin-top: 0.6rem;
    display: flex; flex-direction: column; gap: 0.5rem;
}
/* Shortened, centered divider (replaces the full-width border-top) */
.sidebar-foot::before {
    content: "";
    height: 1px;
    background: var(--nav-border);
    margin: 0 0.85rem 0.7rem;   /* match .nav-divider inset */
}
.foot-row { display: flex; align-items: center; gap: 0.5rem; }
.link-edit-btn {
    flex: 1;
    background: var(--nav-hover);
    color: var(--nav-text); border: 0; border-radius: var(--radius);
    padding: 0.5rem; cursor: pointer; font-size: 0.85rem;
}
.link-edit-btn:hover { filter: brightness(1.3); }
.color-pick {
    position: relative; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: var(--radius);
    background: var(--nav-hover); color: var(--nav-text); cursor: pointer;
}
.color-pick:hover { filter: brightness(1.3); }
.color-pick input[type="color"] {
    position: absolute; inset: 0; opacity: 0; border: 0; padding: 0; cursor: pointer;
}
.admin-flag { font-size: 0.72rem; letter-spacing: 0.04em; text-transform: uppercase;
    color: var(--nav-text); opacity: 0.7; }
.switch-login {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.5rem 0.85rem;
    color: var(--nav-text-dim); opacity: 0.85; text-decoration: none; font-size: 0.82rem;
}
.switch-login .ti { width: 1.2em; text-align: center; font-size: 1.05rem; flex-shrink: 0; }
.switch-login:hover { opacity: 1; text-decoration: underline; color: var(--nav-text); }

/* ---- Content ------------------------------------------------------------ */
.content { flex: 1; align-self: stretch; display: flex; flex-direction: column; min-width: 0; }

.main {
    flex: 1;
    position: relative;
    background: var(--surface);
    padding: 2rem clamp(1.25rem, 4vw, 3rem);
    padding-right: calc(clamp(1.25rem, 4vw, 3rem) + 60px);
    max-width: 1100px;
    width: 100%;
}

/* ---- Messages ----------------------------------------------------------- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.section-head h2 { font-family: var(--display); font-weight: 700; font-size: 1.85rem; color: var(--ink); }
.section-head h2 .ti { margin-right: 0.25rem; color: inherit; vertical-align: -0.05em; opacity: 0.9; }

.message {
    border: 1px solid var(--turq);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    margin-bottom: 1rem;
    background: #fff;
    position: relative;
}
.message-date { font-size: 1.0rem; color: var(--turq); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.message-body { margin-top: 0.5rem; line-height: 1.6; color: var(--ink); }
.message-body p { margin-bottom: 0.75rem; }
.message-body p:last-child { margin-bottom: 0; }
.message-actions { position: absolute; top: 0.75rem; right: 0.85rem; display: flex; gap: 0.35rem; }

/* ---- Calendar ----------------------------------------------------------- */
.cal-wrap { display: flex; flex-direction: column; gap: 2rem; margin-top: 0.5rem; }

.cal-title { font-family: var(--display); font-weight: 700; font-size: 1.5rem; color: var(--ink); margin-bottom: 0.6rem; }
.cal-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.cal-dow {
    text-align: center; font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
    color: var(--ink-soft); padding-bottom: 2px;
}
.cal-cell {
    min-height: 160px;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px;
    background: #fff;
    display: flex; flex-direction: column; gap: 4px;
}
.cal-cell.empty { background: var(--bg-soft); border-style: dashed; }
body[data-admin] .cal-cell:not(.empty) { cursor: pointer; }
body[data-admin] .cal-cell:not(.empty):hover { border-color: var(--turq); }
.cal-cell.today { border-color: var(--logo-blue); box-shadow: inset 0 0 0 1px var(--logo-blue); }
.cal-num { font-size: 0.78rem; color: var(--ink-soft); font-weight: 600; }

.cal-ev {
    display: flex; align-items: center; gap: 4px; width: 100%; text-align: left;
    border: 0; border-radius: 4px;
    padding: 2px 5px; font-size: 0.72rem; line-height: 1.3;
    color: #fff; cursor: pointer;
}
.cal-ev .ti { font-size: 0.8rem; flex-shrink: 0; }
.cal-ev-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-holiday { background: #868d96; }  /* muted gray — intentionally low-key */
.ev-event   { background: var(--green); }  /* green */
.ev-essay   { background: #8867bc; }  /* purple */
.ev-binder  { background: #e8893b; }  /* orange */
.ev-test    { background: #df3a2e; }  /* red */
.ev-journal { background: #1f99cd; }  /* teal-green */
.ev-project { background: #8867bc; }  /* logo blue */
.ev-other   { background: #6b7280; }  /* gray fallback */

/* ---- Static page body --------------------------------------------------- */
.page-body { line-height: 1.65; color: var(--ink); }
.page-body p { margin-bottom: 0.85rem; }

/* Rich-text output (pages + messages). The global reset zeroed these. */
.page-body ul, .page-body ol, .message-body ul, .message-body ol { margin: 0 0 0.85rem 1.5rem; }
.page-body li, .message-body li { margin-bottom: 0.25rem; }
.page-body a, .message-body a { color: var(--turq); text-decoration: underline; }
.page-body h3, .message-body h3 { font-family: var(--display); font-weight: 700; margin: 0.6rem 0 0.4rem; }
.page-body blockquote, .message-body blockquote {
    border-left: 3px solid var(--border); padding-left: 0.85rem;
    color: var(--ink-soft); margin: 0 0 0.85rem;
}

/* Rich-text editor (admin) */
.rte { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.rte-toolbar {
    display: flex; flex-wrap: wrap; gap: 2px; padding: 4px;
    background: var(--bg-soft); border-bottom: 1px solid var(--border);
}
.rte-btn {
    width: 30px; height: 30px; border: 0; background: transparent; border-radius: 5px;
    cursor: pointer; color: var(--ink-soft);
    display: inline-flex; align-items: center; justify-content: center; font-size: 0.95rem;
}
.rte-btn:hover { background: #e3e7ea; color: var(--ink); }
.rte-btn.active { background: var(--turq); color: #fff; }
.rte-btn.active:hover { background: var(--turq-dark); color: #fff; }
.rte-size {
    height: 30px; border: 1px solid var(--border); border-radius: 5px;
    background: #fff; color: var(--ink-soft); cursor: pointer;
    font-size: 0.8rem; padding: 0 0.3rem;
}
.rte-dd { position: relative; display: inline-flex; }
.rte-dd-trig {
    height: 30px; padding: 0 4px; border: 0; background: transparent; border-radius: 5px;
    cursor: pointer; color: var(--ink-soft);
    display: inline-flex; align-items: center; gap: 1px; font-size: 0.95rem;
}
.rte-dd-trig:hover { background: #e3e7ea; color: var(--ink); }
.rte-caret { font-size: 0.65rem; opacity: 0.7; }
.rte-menu {
    position: absolute; top: 100%; left: 0; z-index: 10; margin-top: 2px;
    display: none; gap: 2px; padding: 3px;
    background: #fff; border: 1px solid var(--border); border-radius: 6px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.12);
}
.rte-dd.open .rte-menu { display: flex; }
.rte-dd-size .rte-dd-trig { min-width: 70px; justify-content: space-between; }
.rte-size-label { font-size: 0.8rem; }
.rte-menu-size { flex-direction: column; min-width: 120px; }
.rte-size-opt {
    display: block; width: 100%; text-align: left; white-space: nowrap;
    background: transparent; border: 0; border-radius: 5px; cursor: pointer;
    padding: 0.35rem 0.6rem; font-size: 0.85rem; color: var(--ink);
}
.rte-size-opt:hover { background: #e3e7ea; }
.rte-size-opt.active { background: var(--turq); color: #fff; }
.rte-editor {
    min-height: 170px; max-height: 48vh; overflow-y: auto;
    padding: 0.7rem 0.8rem; font-size: 0.92rem; line-height: 1.55; outline: none;
}
.rte-editor ul, .rte-editor ol { margin-left: 1.4rem; }
.rte-editor h3 { font-family: var(--display); font-weight: 700; margin: 0.3rem 0; }

/* ---- Photo pages -------------------------------------------------------- */
#photo-page { margin-top: 1.5rem; }
.photo-drop {
    display: flex; flex-direction: column; align-items: center; gap: 0.35rem;
    border: 2px dashed var(--border); border-radius: var(--radius);
    padding: 1.25rem; margin-bottom: 1rem; cursor: pointer;
    color: var(--ink-soft); font-size: 0.9rem; text-align: center;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.photo-drop .ti { font-size: 1.5rem; }
.photo-drop:hover { border-color: var(--turq); color: var(--turq); }
.photo-drop.over { border-color: var(--turq); background: #e8f7f6; color: var(--turq); }
.photo-loading { color: var(--ink-soft); font-size: 0.85rem; padding: 0.5rem 0; }

.photo-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 700px) { .photo-grid { grid-template-columns: repeat(3, 1fr); } }
.photo-thumb {
    position: relative; aspect-ratio: 1; border-radius: 6px; overflow: hidden;
    cursor: pointer; background: var(--bg-soft);
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity 0.12s; }
.photo-thumb:hover img { opacity: 0.88; }
.photo-del {
    position: absolute; top: 5px; right: 5px; display: none;
    width: 26px; height: 26px; border: 0; border-radius: 50%;
    background: rgba(180, 0, 0, 0.78); color: #fff; cursor: pointer;
    font-size: 1.1rem; line-height: 1; align-items: center; justify-content: center;
}
.photo-thumb:hover .photo-del { display: flex; }
.photo-del:hover { background: rgba(180, 0, 0, 0.95); }

.lightbox {
    position: fixed; inset: 0; z-index: 800; background: rgba(0, 0, 0, 0.9);
    display: flex; align-items: center; justify-content: center;
}
.lightbox .lb-img {
    max-width: 88vw; max-height: 88vh; object-fit: contain;
    border-radius: 6px; box-shadow: 0 12px 60px rgba(0, 0, 0, 0.6);
}
.lb-nav, .lb-close {
    position: absolute; border: 0; cursor: pointer; color: #fff;
    background: rgba(255, 255, 255, 0.15); border-radius: 50%;
    display: flex; align-items: center; justify-content: center; backdrop-filter: blur(4px);
}
.lb-nav { top: 50%; transform: translateY(-50%); width: 46px; height: 46px; font-size: 1.3rem; }
.lb-prev { left: 1.25rem; }
.lb-next { right: 1.25rem; }
.lb-close { top: 1rem; right: 1rem; width: 38px; height: 38px; font-size: 1.1rem; }
.lb-nav:hover, .lb-close:hover { background: rgba(255, 255, 255, 0.3); }
.lb-counter {
    position: absolute; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.65); font-size: 0.85rem;
}

/* ---- Buttons ------------------------------------------------------------ */
.btn {
    display: inline-flex; align-items: center; gap: 0.4rem;
    border: 0; border-radius: var(--radius);
    padding: 0.5rem 0.9rem; font-size: 0.88rem; cursor: pointer;
    font-family: var(--sans);
}
.btn-primary { background: var(--turq); color: #fff; }
.btn-primary:hover { background: var(--turq-dark); }
.btn-ghost { background: var(--bg-soft); color: var(--ink); border: 1px solid var(--border); }
.btn-ghost:hover { background: #eceff1; }
.btn-danger { background: #fff; color: #c0392b; border: 1px solid #e7b9b3; }
.btn-danger:hover { background: #fdecea; }
.btn-icon { background: var(--bg-soft); border: 1px solid var(--border); border-radius: 6px;
    width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--ink-soft); font-size: 0.85rem; }
.btn-icon:hover { background: #eceff1; color: var(--ink); }

/* ---- Modal -------------------------------------------------------------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(15,23,32,0.45);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 8vh 1rem; z-index: 50;
}
.modal {
    background: #fff; border-radius: 12px; width: 100%; max-width: 460px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25); overflow: hidden;
    display: flex; flex-direction: column; max-height: 84vh; /* fits inside the backdrop's 8vh top/bottom padding */
}
.modal-head { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border-faint);
    display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-size: 1.05rem; }
.modal-body { padding: 1.25rem; display: flex; flex-direction: column; gap: 0.85rem;
    flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.modal-foot { padding: 1rem 1.25rem; border-top: 1px solid var(--border-faint);
    display: flex; justify-content: space-between; gap: 0.5rem; }
.modal-foot .spacer { flex: 1; }

.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field label { font-size: 0.78rem; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; }
.field-input, .field-area, .field-select {
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 0.55rem 0.7rem; font-size: 0.92rem; font-family: var(--sans); width: 100%;
}
.field-area { min-height: 140px; resize: vertical; line-height: 1.5; }
.field-hint { font-size: 0.76rem; color: var(--ink-soft); line-height: 1.4; }
.field-hint a { color: var(--turq); }
.field-input:focus, .field-area:focus, .field-select:focus { outline: 2px solid var(--turq); border-color: var(--turq); }

.close-x { background: none; border: 0; font-size: 1.3rem; cursor: pointer; color: var(--ink-soft); line-height: 1; }

/* ---- Gate --------------------------------------------------------------- */
.gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--board); }
.gate-card { text-align: center; width: 100%; max-width: 320px; padding: 2rem 1.5rem; transform: translateY(-20vh); }
.gate-logo { width: 180px; height: auto; margin-bottom: 1.5rem; }
.gate-form { display: flex; flex-direction: column; gap: 0.75rem; }
.gate-input {
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 0.7rem 0.9rem; font-size: 1rem; text-align: center; font-family: var(--sans);
}
.gate-input:focus { outline: 2px solid var(--turq); border-color: var(--turq); }
.gate-btn { background: var(--turq); color: #fff; border: 0; border-radius: var(--radius);
    padding: 0.7rem; font-size: 1rem; cursor: pointer; }
.gate-btn:hover { background: var(--turq-dark); }
.gate-error { color: #c0392b; font-size: 0.88rem; }

/* ---- Link manager rows -------------------------------------------------- */
.link-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.25rem;
    border-bottom: 1px solid var(--border-faint); background: #fff; border-radius: 6px; }
.link-row .grip { color: var(--ink-soft); cursor: grab; font-size: 1.05rem; }
.link-row .grip:active { cursor: grabbing; }
.link-row.dragging { opacity: 0.5; background: var(--bg-soft); }
.link-row .lbl { flex: 1; font-size: 0.9rem; }
.link-row .kind-tag { font-size: 0.68rem; text-transform: uppercase; color: var(--ink-soft);
    background: var(--bg-soft); padding: 1px 6px; border-radius: 4px; }
