/* ============================================================
   Take notes — stylesheet
   Accent: blue JL gradient
   ============================================================ */
:root {
    --blue-1: #1256d6;
    --blue-2: #3f8cff;
    --grad: linear-gradient(135deg, var(--blue-1) 0%, var(--blue-2) 100%);
    --blue-solid: #1e66f5;
    --bg: #f4f6fb;
    --card: #ffffff;
    --text: #1b2430;
    --muted: #7a8699;
    --border: #e4e8f0;
    --danger: #e5484d;
    --ok: #22a06b;
    --magenta: #e5009c;
    --shadow: 0 2px 10px rgba(20, 40, 90, 0.08);
    --radius: 16px;
}

* { box-sizing: border-box; }

/* The HTML [hidden] attribute must always win over element display rules. */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; cursor: pointer; }

/* ---------- Buttons ---------- */
.btn-primary {
    display: inline-flex; align-items: center; justify-content: center;
    width: 100%;
    border: none; color: #fff; background: var(--grad);
    padding: 15px 18px; border-radius: 14px;
    font-size: 17px; font-weight: 600;
    box-shadow: 0 4px 14px rgba(30, 102, 245, 0.35);
    transition: transform .08s ease, box-shadow .2s ease;
}
.btn-primary:active { transform: translateY(1px) scale(.995); }

.btn-cancel {
    display: block; width: 100%; margin-top: 10px;
    background: transparent; border: none; color: var(--muted);
    padding: 10px; font-size: 15px;
}

/* ============================================================
   Auth pages (login / setup)
   ============================================================ */
.auth-body {
    min-height: 100dvh; display: flex; align-items: center; justify-content: center;
    padding: 24px; background: var(--grad);
}
.auth-card {
    width: 100%; max-width: 380px; background: var(--card);
    border-radius: 20px; padding: 28px 24px; box-shadow: var(--shadow);
    text-align: center;
}
.auth-logo { width: 72px; height: 72px; border-radius: 18px; }
.auth-card h1 { font-size: 22px; margin: 12px 0 20px; }
.auth-card form { text-align: left; }
.auth-card label {
    display: block; font-size: 13px; color: var(--muted);
    margin-bottom: 14px; font-weight: 500;
}
.auth-card label.checkbox {
    display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 15px;
}
.auth-card input[type=text],
.auth-card input[type=password] {
    width: 100%; margin-top: 6px; padding: 12px 14px;
    border: 1px solid var(--border); border-radius: 12px;
    font-size: 16px; background: #fbfcfe;
}
.auth-card input:focus { outline: 2px solid var(--blue-solid); border-color: transparent; }
.auth-card .btn-primary { margin-top: 8px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 16px; }

.flash { padding: 10px 12px; border-radius: 10px; font-size: 14px; margin: 0 0 14px; }
.flash-err { background: #fdecec; color: var(--danger); }
.flash-ok  { background: #e8f7f0; color: var(--ok); }

/* ============================================================
   App shell
   ============================================================ */
/* Header stays at the top of the document but is NOT fixed/sticky.
   Transparent (no white bar), logo centered and slightly larger. */
.app-header {
    display: flex; align-items: center; justify-content: center;
    padding: 16px 16px 0; padding-top: max(16px, env(safe-area-inset-top));
    background: transparent; border-bottom: none;
}
.app-logo { width: 56px; height: 56px; border-radius: 12px; }

/* Logout button, centered at the very bottom of the app. */
.logout-wrap { display: flex; justify-content: center; margin: 32px 0 8px; }
.logout-btn {
    display: inline-flex; align-items: center; gap: 8px;
    text-decoration: none; color: var(--muted); background: var(--card);
    border: 1px solid var(--border); border-radius: 12px;
    padding: 10px 18px; font-size: 15px; font-weight: 600;
}
.logout-btn:active { background: var(--bg); color: var(--danger); }

.app-main {
    max-width: 640px; margin: 0 auto;
    /* top padding == header top padding, so logo→textarea gap == top→logo gap */
    padding: 16px 16px calc(40px + env(safe-area-inset-bottom));
}

/* ---------- Big add button ---------- */
.add-wrap { display: flex; justify-content: center; margin: 18px 0 30px; }
.add-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
    width: 168px; height: 168px; border-radius: 50%;
    border: none; color: #fff; background: var(--grad);
    box-shadow: 0 10px 28px rgba(30, 102, 245, 0.4);
    font-size: 16px; font-weight: 600;
    transition: transform .1s ease;
}
.add-btn:active { transform: scale(.96); }

/* ---------- Composer ---------- */
.composer { margin-bottom: 26px; }
.note-text-wrap { position: relative; }
.note-text {
    display: block; width: 100%; height: 34vh; min-height: 100px; resize: none;
    border: 1px solid var(--border); border-radius: 10px;
    padding: 12px 12px 30px; font-size: 15px; line-height: 1.45;
    background: var(--card); box-shadow: var(--shadow);
}
.note-text:focus { outline: 2px solid var(--blue-solid); border-color: transparent; }

/* Custom, touch-friendly resize handle (bottom-right). */
.resize-handle {
    position: absolute; right: 8px; bottom: 8px;
    width: 42px; height: 21px;
    display: flex; align-items: center; justify-content: center;
    border: none; border-radius: 7px;
    background: rgba(30, 102, 245, .10); color: var(--blue-solid);
    cursor: ns-resize; touch-action: none; -webkit-user-select: none; user-select: none;
}
.resize-handle:active { background: rgba(30, 102, 245, .22); }

.composer-actions {
    margin: 10px 0; display: flex; align-items: center;
    justify-content: flex-end; gap: 10px;
}
.btn-attach {
    display: inline-flex; align-items: center; gap: 8px;
    background: var(--card); color: var(--blue-solid);
    border: 1px solid var(--border); border-radius: 12px;
    padding: 10px 14px; font-size: 15px; font-weight: 600;
}
.btn-attach:active { background: var(--bg); }

/* "Important" toggle button — vivid magenta star. */
.btn-important {
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; flex: 0 0 auto;
    border: 1.5px solid var(--magenta); border-radius: 12px;
    background: var(--card); color: var(--magenta);
    transition: background .12s ease, color .12s ease;
}
.btn-important svg polygon { transition: fill .12s ease; }
.btn-important.active {
    background: var(--magenta); color: #fff;
}
.btn-important.active svg polygon { fill: #fff; }
.btn-important:active { transform: translateY(1px); }
.btn-validate { width: auto; margin-top: 0; padding: 12px 26px; }

.attach-previews { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.attach-thumb {
    position: relative; width: 68px; height: 68px; border-radius: 10px;
    overflow: hidden; border: 1px solid var(--border);
}
.attach-thumb img { width: 100%; height: 100%; object-fit: cover; }
.attach-thumb .remove {
    position: absolute; top: 2px; right: 2px;
    width: 20px; height: 20px; border-radius: 50%;
    background: rgba(0,0,0,.6); color: #fff; border: none;
    font-size: 13px; line-height: 20px; text-align: center; padding: 0;
}

/* ---------- Notes list ---------- */
.notes-heading { font-size: 15px; color: var(--muted); font-weight: 600; margin: 0 0 12px; }
.notes-list { display: flex; flex-direction: column; gap: 12px; }
.notes-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 20px; }

.note-item {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 14px 16px;
}
/* Important notes get a 3px magenta border (same colour as the button). */
.note-item.important {
    border: 3px solid var(--magenta);
}
/* Header row: date, time and the two buttons all on one line, with a light
   grey separator underneath. */
.note-meta {
    display: flex; align-items: center; gap: 8px;
    font-size: 12px; color: var(--muted);
    margin-bottom: 12px; padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}
.note-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--muted); }

/* Actions on the right of the header: Archiver (left) then Copier (right). */
.note-actions {
    margin-left: auto; display: flex; flex-direction: row;
    align-items: center; gap: 2px;
}
.note-actions .archive-btn,
.note-actions .copy-btn {
    background: transparent; border: none;
    color: var(--muted); display: inline-flex; align-items: center; gap: 5px;
    font-size: 13px; padding: 4px 6px; border-radius: 8px;
}
.note-actions .archive-btn:active { background: var(--bg); color: var(--danger); }
.note-actions .copy-btn:active { background: var(--bg); color: var(--blue-solid); }
.note-actions .copy-btn.copied { color: var(--ok); }

.note-content {
    width: 100%;
    font-size: 16px; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
    overflow: hidden;
}
.note-content.clamped {
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
}
.note-toggle {
    display: block; width: 100%; text-align: right;
    background: none; border: none; color: var(--blue-solid);
    font-size: 14px; font-weight: 600; padding: 6px 0 0; margin-top: 2px;
}

/* attachments inside a note */
.note-atts {
    display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px;
    justify-content: flex-end;
}
.note-att {
    width: 56px; height: 56px; border-radius: 10px; overflow: hidden;
    border: 1px solid var(--border); padding: 0; background: var(--bg);
}
.note-att img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ============================================================
   Lightbox
   ============================================================ */
.lightbox {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(8, 12, 20, .94);
    display: flex; align-items: center; justify-content: center;
}
/* The [hidden] attribute must win over the display:flex above. */
.lightbox[hidden] { display: none; }
.lb-stage {
    max-width: 100vw; max-height: 100dvh; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    touch-action: none;
}
#lb-img {
    max-width: 96vw; max-height: 88dvh;
    transform-origin: center center; transition: transform .05s linear;
    user-select: none; -webkit-user-drag: none;
}
.lb-close {
    position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 14px;
    width: 44px; height: 44px; border-radius: 50%;
    background: rgba(255,255,255,.14); color: #fff; border: none; font-size: 20px;
}
.lb-nav {
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 48px; height: 64px; border: none; color: #fff; font-size: 40px;
    background: rgba(255,255,255,.10);
}
.lb-prev { left: 6px; border-radius: 0 12px 12px 0; }
.lb-next { right: 6px; border-radius: 12px 0 0 12px; }
.lb-zoom {
    position: absolute; bottom: calc(18px + env(safe-area-inset-bottom));
    left: 50%; transform: translateX(-50%);
    display: flex; gap: 10px;
}
.lb-zoom button {
    width: 46px; height: 46px; border-radius: 50%;
    background: rgba(255,255,255,.16); color: #fff; border: none; font-size: 22px;
}
.lb-nav:disabled { opacity: .25; }

@media (min-width: 720px) {
    .note-att { width: 64px; height: 64px; }
}
