/* ── Reset & base ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #f5f5f5;
    color: #1a1a1a;
    font-size: 15px;
    line-height: 1.6;
}

a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ───────────────────────────────────────── */
.navbar {
    background: #1e293b;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: 52px;
}
.navbar .brand { color: #fff; font-weight: 700; font-size: 1.1rem; }
.navbar .nav-links { display: flex; gap: 1.5rem; }
.navbar .nav-links a { color: #cbd5e1; font-size: 0.9rem; }
.navbar .nav-links a:hover { color: #fff; text-decoration: none; }

/* ── Container ────────────────────────────────────── */
.container { max-width: 1000px; margin: 2rem auto; padding: 0 1rem; }

/* ── Login ────────────────────────────────────────── */
body.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: #1e293b;
}
.login-box {
    background: #fff; border-radius: 10px; padding: 2.5rem 2rem;
    width: 100%; max-width: 380px; box-shadow: 0 8px 32px rgba(0,0,0,.3);
}
.login-box h1 { font-size: 1.8rem; margin-bottom: 0.25rem; text-align: center; }
.login-box .subtitle { text-align: center; color: #64748b; margin-bottom: 1.5rem; }

/* ── Alerts ───────────────────────────────────────── */
.alert {
    padding: .75rem 1rem; border-radius: 6px; margin-bottom: 1rem;
}
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }

/* ── Forms ────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .75rem; }
.form-group label { font-size: .8rem; font-weight: 600; color: #475569; text-transform: uppercase; letter-spacing: .03em; }
.form-group input, .form-group textarea, .form-group select {
    padding: .5rem .7rem; border: 1px solid #cbd5e1; border-radius: 6px;
    font-size: .95rem; width: 100%; background: #fff;
    transition: border-color .15s;
}
.form-group input:focus, .form-group textarea:focus {
    outline: none; border-color: #2563eb; box-shadow: 0 0 0 2px #bfdbfe;
}
.form-group small.muted { font-size: .78rem; color: #94a3b8; }
textarea { resize: vertical; }

.form-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .75rem; }

.color-row { display: flex; gap: .5rem; align-items: center; }
.color-row input[type=color] { width: 42px; height: 36px; padding: 2px; cursor: pointer; border-radius: 4px; }

/* ── Quiz options ─────────────────────────────────── */
.quiz-option-label { cursor: default; }
.quiz-option-input { display: flex; align-items: center; gap: .5rem; }
.quiz-option-input input[type=radio] { margin: 0; cursor: pointer; accent-color: #16a34a; flex: 0 0 auto; width: 18px; height: 18px; }
.quiz-option-input input[type=text] { flex: 1 1 auto; }
.quiz-option-correct .quiz-option-input input[type=text],
.quiz-option-correct .quiz-option-input input:not([type=radio]) { background: #dcfce7; border-color: #86efac; }
.quiz-option-correct .quiz-option-label { color: #166534; }

/* ── Buttons ──────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .45rem .9rem; border-radius: 6px; font-size: .9rem;
    border: none; cursor: pointer; font-weight: 500; white-space: nowrap;
    transition: filter .15s;
}
.btn:hover { filter: brightness(.92); text-decoration: none; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-secondary { background: #e2e8f0; color: #1e293b; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }
.btn-lg { padding: .6rem 1.4rem; font-size: 1rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Page header ─────────────────────────────────── */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.5rem;
}
.page-header h2 { font-size: 1.4rem; }

/* ── Section card ────────────────────────────────── */
.section-card {
    background: #fff; border-radius: 8px; padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem; box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.section-card h3 { font-size: 1rem; margin-bottom: 1rem; color: #0f172a; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }

/* ── Route cards ─────────────────────────────────── */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.card {
    background: #fff; border-radius: 8px; overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    display: flex; flex-direction: column;
}
.card-body { padding: 1rem; flex: 1; }
.card-body h3 { margin-bottom: .25rem; }
.card-actions { padding: .75rem 1rem; background: #f8fafc; display: flex; gap: .5rem; }

/* ── Book grid ───────────────────────────────────── */
.book-grid {
    display: flex; flex-direction: column; gap: .5rem;
    max-width: 480px;
}
.book-card {
    position: relative;
    display: flex; align-items: center; gap: .85rem;
    background: #fff; border-radius: 8px; padding: .5rem .75rem;
    box-shadow: 0 1px 4px rgba(0,0,0,.08); text-decoration: none; color: inherit;
    transition: background .12s;
}
.book-edit-btn {
    position: absolute; top: .35rem; right: .35rem;
    padding: .15rem .4rem; font-size: .85rem; line-height: 1;
    opacity: .7;
}
.book-edit-btn:hover { opacity: 1; }
.book-card:hover { background: #f1f5f9; text-decoration: none; }
.book-thumb {
    width: 156px; height: 114px; object-fit: cover;
    border-radius: 4px; flex-shrink: 0;
}
.book-thumb-empty {
    width: 156px; height: 114px; background: #e2e8f0;
    border-radius: 4px; display: flex; align-items: center;
    justify-content: center; font-size: 1.3rem; flex-shrink: 0;
}
.book-card-body { flex: 1; min-width: 0; }
.book-card-name { font-weight: 600; font-size: .95rem; }
.book-card-desc { font-size: .8rem; color: #64748b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-grid-footer { margin-top: 1rem; max-width: 480px; }

/* ── Stop / quiz cards ───────────────────────────── */
details.stop-card {
    border: 1px solid #e2e8f0; border-radius: 6px; margin-bottom: .75rem;
}
details.stop-card summary {
    padding: .6rem 1rem; cursor: pointer; font-weight: 600;
    background: #f8fafc; border-radius: 6px; list-style: none;
    user-select: none;
}
details.stop-card summary::before { content: "▶ "; font-size: .75rem; }
details[open].stop-card summary::before { content: "▼ "; }
.stop-body { padding: 1rem; border-top: 1px solid #e2e8f0; }
.stop-actions { display: flex; justify-content: flex-end; margin-top: .5rem; }

/* ── Form actions ────────────────────────────────── */
.form-actions {
    display: flex; gap: .75rem; flex-wrap: wrap;
    margin-top: 1rem; padding-bottom: 2rem;
}

/* ── Image grid ──────────────────────────────────── */
.image-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem;
}
.image-card {
    background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px;
    overflow: hidden; display: flex; flex-direction: column; align-items: center;
}
.image-card img {
    width: 100%; height: 120px; object-fit: cover; display: block;
}
.image-name {
    font-size: .72rem; color: #475569; padding: .3rem .5rem;
    word-break: break-all; text-align: center;
}
.image-card form { padding: .3rem .5rem .5rem; }

/* ── Misc ────────────────────────────────────────── */
.muted { color: #94a3b8; }
.meta { font-size: .8rem; color: #64748b; margin-top: .25rem; }

/* ── Stop image row ──────────────────────────────── */
.stop-image-row {
    display: flex; align-items: flex-start; gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e2e8f0;
}

.stop-image-preview {
    width: 140px; flex-shrink: 0;
}
.stop-image-preview img {
    width: 140px; height: 94px;
    object-fit: cover; border-radius: 8px;
    display: block; border: 1px solid #e2e8f0;
}
.stop-image-empty {
    width: 140px; height: 94px;
    background: #f1f5f9; border: 2px dashed #cbd5e1;
    border-radius: 8px; display: flex;
    align-items: center; justify-content: center;
    font-size: .75rem; color: #94a3b8;
}

.stop-image-upload { display: flex; flex-direction: column; gap: .4rem; justify-content: center; }
.stop-image-filename { font-size: .75rem; color: #64748b; word-break: break-all; }

.upload-label {
    cursor: pointer; display: inline-flex; align-items: center; gap: .3rem;
}
.upload-label input[type=file] { display: none; }

/* ── Auto-save indicator ─────────────────────────── */
.save-indicator {
    position: fixed; bottom: 1.25rem; right: 1.5rem;
    padding: .4rem .9rem; border-radius: 20px;
    font-size: .82rem; font-weight: 600;
    pointer-events: none; z-index: 900;
    transition: opacity .4s;
    opacity: 1;
}
.save-indicator.saving { background: #fef9c3; color: #713f12; }
.save-indicator.saved  { background: #dcfce7; color: #166534; }
.save-indicator.error  { background: #fee2e2; color: #991b1b; }

/* ── Preview panel (draggable, floating) ─────────── */
.preview-panel {
    position: fixed;
    top: 80px; right: 24px;
    z-index: 500;
    width: 326px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    filter: drop-shadow(0 12px 40px rgba(0,0,0,.45));
}

.preview-panel-titlebar {
    width: 100%;
    background: #1e293b;
    color: #fff;
    display: flex; align-items: center; justify-content: space-between;
    padding: .45rem .85rem;
    border-radius: 10px 10px 0 0;
    cursor: grab;
    user-select: none;
    font-size: .85rem; font-weight: 600;
    gap: .5rem;
}
.preview-panel-titlebar:active { cursor: grabbing; }

.phone-frame {
    position: relative;
    width: 320px;
    height: 693px;
    background: #1c1c1e;
    border-radius: 0 0 44px 44px;
    box-shadow: 0 0 0 2px #3a3a3c, 0 0 0 5px #1c1c1e;
    overflow: hidden;
    display: flex; flex-direction: column;
}

.phone-notch {
    position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 96px; height: 26px;
    background: #1c1c1e; border-radius: 0 0 18px 18px;
    z-index: 10;
}

.phone-screen {
    flex: 1;
    background: #f2f2f7;
    overflow-y: auto;
    border-radius: 0 0 40px 40px;
    margin: 3px;
    margin-top: 0;
    -webkit-overflow-scrolling: touch;
}

.preview-close {
    background: rgba(255,255,255,.15); border: none;
    color: #fff; width: 26px; height: 26px;
    border-radius: 50%; font-size: .85rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    line-height: 1;
}
.preview-close:hover { background: rgba(255,255,255,.3); }

/* ── Phone screen content (mirrors MAUI DetailPage) ─ */
.pp-hero {
    width: 100%; height: 240px;
    background-size: cover; background-position: center;
    border-radius: 46px 46px 0 0;
    flex-shrink: 0;
}
.pp-hero-empty { display: flex; align-items: center; justify-content: center; font-size: 4rem; }

.pp-content {
    padding: 1rem 1.1rem 2rem;
}

.pp-header {
    display: flex; align-items: center; flex-wrap: wrap; gap: .45rem;
    margin-bottom: .6rem;
}

.pp-number {
    color: #fff; font-size: .72rem; font-weight: 700;
    padding: .2rem .55rem; border-radius: 20px;
    line-height: 1.4;
}

.pp-icon { font-size: 1.4rem; }

.pp-name {
    font-size: 1.25rem; font-weight: 700;
    color: #1c1c1e; flex: 1; min-width: 120px;
    line-height: 1.25;
}

.pp-year {
    font-size: .75rem; color: #6e6e73;
    background: #e5e5ea; padding: .15rem .55rem; border-radius: 12px;
    white-space: nowrap;
}

.pp-short {
    font-size: .9rem; color: #3c3c43; font-style: italic;
    margin-bottom: .75rem; line-height: 1.5;
}

.pp-divider {
    height: 1px; background: #d1d1d6; margin: .6rem 0 .9rem;
}

.pp-body {
    font-size: .88rem; color: #1c1c1e; line-height: 1.65;
}

/* ── Section header with action button ───────────── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .75rem;
}
.section-header h3 { margin: 0; }

/* ── History modal ────────────────────────────────── */
.history-modal {
    position: fixed; inset: 0; z-index: 1100;
    background: rgba(0,0,0,.45);
    display: flex; align-items: center; justify-content: center;
}
.history-modal-content {
    background: #fff; border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,.25);
    width: min(92vw, 820px); max-height: 80vh;
    display: flex; flex-direction: column;
}
.history-modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: .75rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    font-weight: 600; font-size: .95rem;
}
.history-modal-body {
    overflow-y: auto; padding: 1rem;
}
.history-empty { color: #888; font-style: italic; }
.history-table {
    width: 100%; border-collapse: collapse; font-size: .83rem;
}
.history-table th {
    text-align: left; background: #f1f5f9;
    padding: .4rem .6rem; border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
}
.history-table td {
    padding: .35rem .6rem; border-bottom: 1px solid #f1f5f9;
    vertical-align: top; max-width: 220px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.history-table tr:last-child td { border-bottom: none; }
.pp-body p { margin-bottom: .6rem; }

.pp-row {
    display: flex; align-items: flex-start; gap: .4rem;
    font-size: .82rem; color: #3c3c43; margin-top: .75rem;
}

.pp-direction {
    margin-top: .75rem; padding: .6rem .8rem;
    background: #e5f0ff; border-radius: 8px;
    font-size: .83rem; color: #1d3461; line-height: 1.45;
}

/* ── User table ──────────────────────────────────── */
.user-table {
    width: 100%; border-collapse: collapse; font-size: .9rem;
}
.user-table th {
    text-align: left; padding: .5rem .75rem;
    border-bottom: 2px solid #e2e8f0;
    font-size: .75rem; text-transform: uppercase;
    letter-spacing: .04em; color: #64748b;
}
.user-table td {
    padding: .55rem .75rem; border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}
.user-table tr:last-child td { border-bottom: none; }

.badge {
    display: inline-block; padding: .15rem .55rem;
    border-radius: 20px; font-size: .72rem; font-weight: 700;
}
.badge-admin  { background: #fef3c7; color: #92400e; }
.badge-editor { background: #e0f2fe; color: #075985; }
.badge-self   { background: #f1f5f9; color: #64748b; margin-left: .3rem; }

.inline-form { display: flex; gap: .4rem; align-items: center; }
.pw-input {
    padding: .3rem .55rem; border: 1px solid #cbd5e1;
    border-radius: 6px; font-size: .85rem; width: 160px;
}
.pw-input:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 2px #bfdbfe; }
