/* ============================================================
   Moleskill modern UI — custom layer on top of Bootstrap 5.
   System font stack, no web fonts. ~9 KB.
   ============================================================ */

:root {
    --ms-ink: #0f172a;
    --ms-muted: #64748b;
    --ms-bg: #f8fafc;
    --ms-card: #ffffff;
    --ms-line: #e2e8f0;
    --ms-indigo: #4f46e5;
    --ms-violet: #7c3aed;
    --ms-ok: #059669;
    --ms-wait: #d97706;
    --ms-fail: #dc2626;
}

html { scroll-behavior: smooth; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    color: var(--ms-ink);
    background: var(--ms-bg);
    -webkit-font-smoothing: antialiased;
}

.minw-0 { min-width: 0; }

.text-gradient {
    background: linear-gradient(92deg, var(--ms-indigo), var(--ms-violet));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

/* ---------- brand ---------- */
.brand-mark {
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.55em; height: 1.55em; margin-right: .45em;
    border-radius: 8px; vertical-align: -.35em;
    background: linear-gradient(135deg, var(--ms-indigo), var(--ms-violet));
    color: #fff; font-family: Georgia, serif; font-size: .95em; line-height: 1;
}

/* ---------- app navbar ---------- */
.app-nav {
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--ms-line);
}
.app-nav .nav-link { color: var(--ms-muted); font-weight: 500; border-radius: 8px; }
.app-nav .nav-link:hover,
.app-nav .nav-link.active { color: var(--ms-indigo); }
.app-nav .nav-link:focus-visible,
.btn:focus-visible, .form-control:focus-visible {
    outline: 3px solid rgba(79, 70, 229, .45); outline-offset: 2px;
}
.nav-user .btn-user {
    border: 1px solid var(--ms-line); background: #fff;
    color: var(--ms-ink); border-radius: 999px; padding: .25rem .75rem .25rem .3rem;
}
.avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 50%;
    background: linear-gradient(135deg, var(--ms-indigo), var(--ms-violet));
    color: #fff; font-size: .85rem; font-weight: 600; margin-right: .4rem;
}

/* ---------- buttons ---------- */
.btn-cta {
    background: linear-gradient(135deg, var(--ms-indigo), var(--ms-violet));
    border: none; box-shadow: 0 6px 16px rgba(79, 70, 229, .28);
}
.btn-cta:hover { filter: brightness(1.07); transform: translateY(-1px); }
.btn-cta { transition: transform .15s ease, filter .15s ease; }

/* ---------- hero ---------- */
.hero {
    padding: clamp(3rem, 7vw, 5.5rem) 0 clamp(3rem, 6vw, 5rem);
    background:
        radial-gradient(38rem 20rem at 12% -10%, rgba(124, 58, 237, .14), transparent 60%),
        radial-gradient(34rem 18rem at 95% 8%, rgba(79, 70, 229, .13), transparent 60%),
        var(--ms-bg);
}
.hero-badge {
    display: inline-block; padding: .4rem .9rem; border-radius: 999px;
    background: #eef2ff; color: var(--ms-indigo);
    font-size: .82rem; font-weight: 600; letter-spacing: .02em;
    border: 1px solid #e0e7ff;
}
.hero-title { font-size: clamp(2.4rem, 5.4vw, 3.7rem); font-weight: 800; letter-spacing: -.02em; }
.hero-lead { font-size: 1.15rem; color: var(--ms-muted); max-width: 34rem; }

.flow-card {
    background: var(--ms-card); border: 1px solid var(--ms-line);
    border-radius: 20px; padding: 1.6rem 1.4rem;
    box-shadow: 0 18px 40px rgba(15, 23, 42, .08);
}
.flow-caption { color: var(--ms-muted); font-size: .72rem; letter-spacing: .12em; }
.flow-steps {
    list-style: none; display: flex; align-items: stretch; gap: .6rem;
    margin: 0; padding: 0; flex-wrap: wrap; justify-content: center;
}
.flow-step {
    flex: 1 1 8rem; max-width: 11rem; text-align: center;
    border: 1px solid var(--ms-line); border-radius: 14px; padding: 1rem .6rem;
    background: #fafbff;
}
.flow-step-accent { background: #f5f3ff; border-color: #ddd6fe; }
.flow-num {
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.5rem; height: 1.5rem; border-radius: 50%;
    background: var(--ms-indigo); color: #fff; font-size: .78rem; font-weight: 700;
}
.flow-name { display: block; font-weight: 700; margin-top: .45rem; }
.flow-desc { display: block; font-size: .78rem; color: var(--ms-muted); margin-top: .15rem; }
.flow-arrow { align-self: center; color: #94a3b8; font-size: 1.3rem; font-weight: 700; }

/* ---------- sections ---------- */
.section { padding: clamp(3rem, 6vw, 4.5rem) 0; }
.section-tinted {
    background:
        radial-gradient(30rem 16rem at 90% 10%, rgba(79, 70, 229, .07), transparent 60%),
        #eef2ff;
}
.section-title { font-weight: 800; letter-spacing: -.01em; font-size: clamp(1.6rem, 3vw, 2.2rem); }
.section-sub { color: var(--ms-muted); font-size: 1.02rem; }

/* ---------- feature cards ---------- */
.feature-card {
    background: var(--ms-card); border: 1px solid var(--ms-line);
    border-radius: 16px; padding: 1.5rem 1.4rem;
    transition: transform .15s ease, box-shadow .15s ease;
}
.feature-card:hover { transform: translateY(-3px); box-shadow: 0 14px 30px rgba(15, 23, 42, .09); }
.feature-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; border-radius: 12px; margin-bottom: .9rem;
}
.fi-indigo  { background: #eef2ff; color: var(--ms-indigo); }
.fi-blue    { background: #eff6ff; color: #2563eb; }
.fi-emerald { background: #ecfdf5; color: var(--ms-ok); }
.fi-violet  { background: #f5f3ff; color: var(--ms-violet); }
.fi-amber   { background: #fffbeb; color: var(--ms-wait); }
.fi-rose    { background: #fff1f2; color: #e11d48; }
.feature-title { font-size: 1.06rem; font-weight: 700; }
.feature-text { color: var(--ms-muted); font-size: .93rem; margin-bottom: 0; }

/* ---------- chat demo ---------- */
.chat-demo {
    background: var(--ms-card); border: 1px solid var(--ms-line);
    border-radius: 16px; overflow: hidden; max-width: 40rem;
}
.chat-demo-head {
    display: flex; align-items: center; gap: .35rem;
    padding: .65rem .9rem; border-bottom: 1px solid var(--ms-line); background: #fbfcfe;
}
.dot { width: .65rem; height: .65rem; border-radius: 50%; display: inline-block; }
.dot-red { background: #f87171; } .dot-yellow { background: #fbbf24; } .dot-green { background: #34d399; }
.chat-demo-title { font-size: .8rem; color: var(--ms-muted); font-weight: 600; }
.chat-demo-body { padding: 1rem; }
.demo-msg { border-radius: 12px; padding: .7rem .9rem; font-size: .92rem; margin-bottom: .8rem; }
.demo-msg p:last-child, .demo-msg ul:last-child { margin-bottom: 0; }
.demo-user {
    background: linear-gradient(135deg, var(--ms-indigo), var(--ms-violet));
    color: #fff; max-width: 75%; margin-left: auto;
}
.demo-ai { background: var(--ms-bg); border: 1px solid var(--ms-line); max-width: 88%; }
.demo-ai p { margin-bottom: .35rem; }
.demo-ai ul { margin-bottom: 0; }

/* ---------- kindle section ---------- */
.kindle-split { display: grid; grid-template-columns: 1fr; gap: 2.5rem; align-items: center; }
@media (min-width: 992px) { .kindle-split { grid-template-columns: 1.15fr .85fr; } }
.check-list { list-style: none; padding: 0; margin: 0; }
.check-list li { padding-left: 1.7rem; position: relative; margin-bottom: .5rem; color: var(--ms-ink); }
.check-list li::before {
    content: "✓"; position: absolute; left: 0; top: 0;
    color: var(--ms-ok); font-weight: 800;
}
.kindle-device {
    display: inline-block; padding: 1rem 1rem 1.4rem;
    background: #232a33; border-radius: 18px;
    box-shadow: 0 24px 50px rgba(15, 23, 42, .25); max-width: 17.5rem; width: 100%;
}
.kindle-screen {
    background: #e8e6e1; border-radius: 6px; padding: 1rem;
    font-family: Georgia, serif; color: #1a1a1a;
}
.kd-brand { text-align: center; letter-spacing: .2em; font-weight: 700; margin-bottom: .4rem; }
.kindle-screen hr { border-top: 1px solid #b9b6ae; opacity: 1; margin: .5rem 0; }
.kd-line { text-align: center; font-size: .72rem; color: #444; margin: 0; }
.kd-item { border-bottom: 1px solid #cfccc4; padding: .45rem .2rem; margin: 0; font-size: .86rem; }
.kd-item:last-child { border-bottom: none; }

/* ---------- library preview on landing ---------- */
.lib-preview { background: var(--ms-card); border: 1px solid var(--ms-line); border-radius: 16px; overflow: hidden; }
.lib-row { padding: 1rem 1.2rem; border-bottom: 1px solid var(--ms-line); }
.lib-row:last-child { border-bottom: none; }
.lib-name { font-weight: 600; }
.lib-meta { font-size: .8rem; color: var(--ms-muted); }

/* ---------- status badges ---------- */
.badge-status {
    display: inline-block; padding: .28rem .7rem; border-radius: 999px;
    font-size: .74rem; font-weight: 700; white-space: nowrap;
}
.badge-ok   { background: #ecfdf5; color: var(--ms-ok); border: 1px solid #a7f3d0; }
.badge-ok-yes { background: #ecfdf5; color: var(--ms-ok); border: 1px solid #a7f3d0; }
.badge-ok-no{ background: #fffbeb; color: var(--ms-wait); border: 1px solid #fde68a; }
.badge-wait { background: #fffbeb; color: var(--ms-wait); border: 1px solid #fde68a; }
.badge-fail { background: #fef2f2; color: var(--ms-fail); border: 1px solid #fecaca; }

/* ---------- final CTA / footer ---------- */
.final-cta {
    background: linear-gradient(135deg, #1e1b4b, #312e81 55%, #4c1d95);
    color: #fff;
}
.final-title { font-weight: 800; font-size: clamp(1.6rem, 3.4vw, 2.4rem); }
.final-btn { font-weight: 700; color: #1e1b4b; }
.site-footer { border-top: 1px solid var(--ms-line); background: #fff; }

/* ---------- auth ---------- */
.auth-wrap { max-width: 26rem; margin: clamp(2.5rem, 8vh, 5rem) auto; padding: 0 1rem; }
.auth-card {
    background: var(--ms-card); border: 1px solid var(--ms-line);
    border-radius: 20px; padding: 2.2rem;
}
.auth-brand { font-weight: 800; font-size: 1.2rem; color: var(--ms-ink); text-decoration: none; }
.auth-brand:hover { color: var(--ms-indigo); }
.auth-title { font-weight: 800; margin-top: 1.2rem; }

/* ---------- app pages ---------- */
.app-page { padding: 2rem 1rem 3rem; max-width: 1140px; }
.app-narrow { max-width: 780px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.page-title { font-weight: 800; font-size: clamp(1.5rem, 3vw, 2rem); margin: 0; }

.stat-card {
    background: var(--ms-card); border: 1px solid var(--ms-line);
    border-radius: 14px; padding: 1.1rem 1.2rem; height: 100%;
}
.stat-num { font-size: 1.7rem; font-weight: 800; line-height: 1.1; }
.stat-label { color: var(--ms-muted); font-size: .84rem; margin-top: .2rem; }

.quick-action {
    display: block; height: 100%; text-decoration: none;
    background: linear-gradient(135deg, #eef2ff, #f5f3ff);
    border: 1px solid #e0e7ff; border-radius: 14px; padding: 1.1rem 1.2rem;
    transition: transform .15s ease, box-shadow .15s ease;
}
.quick-action:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(79, 70, 229, .12); }
.qa-title { display: block; font-weight: 700; color: var(--ms-indigo); }
.qa-sub { display: block; font-size: .84rem; color: var(--ms-muted); margin-top: .15rem; }

.panel {
    background: var(--ms-card); border: 1px solid var(--ms-line);
    border-radius: 16px; padding: 1.3rem 1.4rem;
}
.panel-warn { border-color: #fde68a; background: #fffdf5; }
.panel-title { font-size: 1.02rem; font-weight: 700; margin-bottom: .8rem; }

.row-list, .job-list { list-style: none; margin: 0; padding: 0; }
.row-item {
    display: flex; align-items: center; gap: .8rem;
    padding: .7rem 0; border-bottom: 1px solid var(--ms-line);
}
.row-item:last-child { border-bottom: none; }
.job-item { padding: .45rem 0; display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
.row-name { font-weight: 600; color: var(--ms-ink); text-decoration: none; }
a.row-name:hover { color: var(--ms-indigo); }
.row-meta { font-size: .8rem; color: var(--ms-muted); }
.job-error { font-size: .8rem; color: var(--ms-fail); word-break: break-word; }

/* ---------- library page ---------- */
.lib-toolbar .form-control, .lib-toolbar .form-select { background: var(--ms-card); }
.book-row { padding: .85rem .4rem; border-bottom: 1px solid var(--ms-line); }
.panel > .book-row:first-child { padding-top: .2rem; }
.book-row:last-of-type { border-bottom: none; }
.book-type {
    flex: 0 0 auto; width: 2.6rem; height: 2.6rem; border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .68rem; font-weight: 800; letter-spacing: .04em;
    background: #eef2ff; color: var(--ms-indigo);
}
.book-actions { flex: 0 0 auto; }
.empty-state { color: var(--ms-muted); }
.pagination .page-link { border-radius: 10px !important; margin: 0 .2rem; border-color: var(--ms-line); color: var(--ms-indigo); }

/* ---------- upload modes ---------- */
.mode-card {
    display: flex; gap: .8rem; align-items: flex-start;
    border: 1px solid var(--ms-line); border-radius: 12px;
    padding: .9rem 1rem; margin-bottom: .6rem; cursor: pointer; background: var(--ms-card);
}
.mode-card:has(input:checked) { border-color: var(--ms-indigo); background: #f5f6ff; }
.mode-card input { margin-top: .3rem; }
.mode-card label { cursor: pointer; }
.mode-name { display: block; font-weight: 700; }
.mode-desc { display: block; font-size: .86rem; color: var(--ms-muted); }

.settings-list div { display: flex; justify-content: space-between; gap: 1rem; padding: .5rem 0; border-bottom: 1px dashed var(--ms-line); }
.settings-list div:last-child { border-bottom: none; }
.settings-list dt { color: var(--ms-muted); font-weight: 500; }
.settings-list dd { margin: 0; font-weight: 600; text-align: right; word-break: break-all; }
.kindle-url code { user-select: all; word-break: break-all; }

/* ---------- error pages ---------- */
.error-wrap { padding: clamp(4rem, 12vh, 7rem) 1rem; position: relative; overflow: hidden; }
.error-code { font-size: clamp(4.5rem, 14vw, 8rem); font-weight: 800; line-height: 1; margin: 0; }
.error-title { font-weight: 800; }
.error-blob {
    position: absolute; inset: auto; top: -6rem; left: 50%;
    width: 30rem; height: 30rem; transform: translateX(-50%);
    background: radial-gradient(closest-side, rgba(124, 58, 237, .16), transparent);
    z-index: -1;
}

/* ============================================================
   AI Chat page
   ============================================================ */
.chat-container { max-width: 1400px; padding-inline: 1rem; }
.chat-layout {
    display: grid; grid-template-columns: 1fr;
    height: calc(100dvh - 64px); min-height: 480px;
    background: var(--ms-bg);
}
@media (min-width: 992px) { .chat-layout { grid-template-columns: 290px 1fr; } }

.chat-sidebar { background: #fff; border-right: 1px solid var(--ms-line); }
@media (min-width: 992px) { .chat-sidebar.offcanvas-lg { position: static; visibility: visible !important; transform: none; width: auto; } }

.conv-list { overflow-y: auto; }
.conv-item {
    display: flex; align-items: center; border-radius: 10px;
    margin-bottom: 2px; position: relative; padding-right: .3rem;
}
.conv-item:hover { background: var(--ms-bg); }
.conv-active { background: #eef2ff; }
.conv-active:hover { background: #eef2ff; }
.conv-link {
    flex: 1; min-width: 0; padding: .55rem .7rem;
    color: var(--ms-ink); text-decoration: none; font-size: .92rem;
}
.conv-link:hover { color: var(--ms-indigo); }
.conv-del {
    border: none; background: transparent; color: #94a3b8;
    font-size: 1.05rem; line-height: 1; padding: .2rem .45rem; border-radius: 6px;
}
.conv-del:hover { color: var(--ms-fail); background: #fee2e2; }

.chat-main { display: flex; flex-direction: column; min-width: 0; }
.chat-head {
    padding: .8rem 1.1rem; background: #fff; border-bottom: 1px solid var(--ms-line);
}
.chat-title { font-size: 1.05rem; font-weight: 700; }

.chat-messages { flex: 1; overflow-y: auto; padding: 1.2rem; }
.msg { display: flex; margin-bottom: 1rem; }
.msg-user { justify-content: flex-end; }
.msg-ai { justify-content: flex-start; }
.bubble { max-width: min(46rem, 92%); border-radius: 14px; padding: .75rem 1rem; }
.bubble-user {
    background: linear-gradient(135deg, var(--ms-indigo), var(--ms-violet));
    color: #fff; white-space: pre-wrap; word-wrap: break-word;
}
.bubble-ai { background: var(--ms-card); border: 1px solid var(--ms-line); }
.chat-empty { text-align: center; margin-top: 18vh; color: var(--ms-muted); }
.chat-empty .fs-4 { color: var(--ms-ink); }

.typing span {
    display: inline-block; width: .45rem; height: .45rem; margin-right: .25rem;
    border-radius: 50%; background: #94a3b8;
    animation: ms-blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes ms-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.msg-error {
    max-width: min(46rem, 92%); background: #fef2f2; border: 1px solid #fecaca;
    color: #991b1b; border-radius: 12px; padding: .7rem 1rem; margin-bottom: 1rem;
}

.save-book-form summary {
    cursor: pointer; font-size: .82rem; color: var(--ms-indigo);
    font-weight: 600; list-style-position: inside; margin-top: .5rem;
    user-select: none;
}
.save-details[open] summary { margin-bottom: .5rem; }
.save-body { display: flex; gap: .5rem; max-width: 26rem; }

.chat-input {
    display: flex; gap: .6rem; padding: .8rem 1rem;
    background: #fff; border-top: 1px solid var(--ms-line);
}
.chat-input textarea {
    resize: none; max-height: 9rem; border-radius: 12px;
}
.btn-send { border-radius: 12px; padding-inline: 1.3rem; }

/* markdown content inside bubbles */
.md-content h1, .md-content h2, .md-content h3 { font-size: 1.02rem; margin: .8rem 0 .4rem; font-weight: 700; }
.md-content h1:first-child, .md-content h2:first-child, .md-content h3:first-child { margin-top: 0; }
.md-content p { margin-bottom: .55rem; }
.md-content p:last-child { margin-bottom: 0; }
.md-content ul, .md-content ol { margin: .4rem 0 .6rem 1.2rem; padding: 0; }
.md-content pre {
    background: #0f172a; color: #e2e8f0; border-radius: 10px;
    padding: .7rem .9rem; font-size: .84rem; overflow-x: auto; margin: .55rem 0;
}
.md-content code { background: #f1f5f9; border-radius: 5px; padding: .1rem .32rem; font-size: .87em; }
.md-content pre code { background: transparent; padding: 0; }
.md-content blockquote { border-left: 3px solid #cbd5e1; margin: .55rem 0; padding: .15rem .9rem; color: var(--ms-muted); }
.md-content table { border-collapse: collapse; margin: .55rem 0; font-size: .88rem; max-width: 100%; display: block; overflow-x: auto; }
.md-content th, .md-content td { border: 1px solid var(--ms-line); padding: .3rem .6rem; }
.md-content a { color: var(--ms-indigo); }

/* small screens: keep book rows usable */
@media (max-width: 576px) {
    .book-row { flex-wrap: wrap; }
    .book-row .badge-status { order: 3; }
    .book-actions { margin-left: auto; }
    .stat-num { font-size: 1.35rem; }
}
