/* ============================================================
   Commonplace — Custom Styles
   Minimal layer on top of Tailwind CSS
   ============================================================ */

/* ---------- Base & Typography ---------- */
html {
    scroll-behavior: smooth;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

::selection {
    background: #6366f1; /* indigo-500 */
    color: #ffffff;
}

/* ---------- Custom Scrollbar ---------- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9; /* slate-100 */
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1; /* slate-300 */
    border-radius: 3px;
    transition: background 0.2s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8; /* slate-400 */
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
}

/* ---------- Stat Cards (Dashboard) ---------- */
.stat-card {
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}

/* ---------- Review Card ---------- */
.review-card {
    animation: fadeInUp 0.35s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.review-quote {
    position: relative;
}

.review-quote p {
    line-height: 1.75;
    font-family: Georgia, "Times New Roman", Times, serif;
}

/* ── Mobile Highlight Cards ──────────────────────────── */
.source-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.5;
    white-space: nowrap;
}

.source-koreader {
    background: #d1fae5; /* emerald-100 */
    color: #065f46;       /* emerald-800 */
    border: 1px solid #a7f3d0; /* emerald-200 */
}

.source-readwise {
    background: #dbeafe; /* blue-100 */
    color: #1e40af;       /* blue-800 */
    border: 1px solid #bfdbfe; /* blue-200 */
}

.source-manual {
    background: #fef3c7; /* amber-100 */
    color: #92400e;       /* amber-800 */
    border: 1px solid #fde68a; /* amber-200 */
}

/* ---------- Tag Pills ---------- */
.tag-pill {
    display: inline-block;
    padding: 1px 8px;
    font-size: 0.65rem;
    font-weight: 500;
    color: #64748b;       /* slate-500 */
    background: #f1f5f9;  /* slate-100 */
    border-radius: 9999px;
    border: 1px solid #e2e8f0; /* slate-200 */
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease;
}

.tag-pill:hover {
    background: #e2e8f0;  /* slate-200 */
    color: #475569;       /* slate-600 */
}

/* ---------- Highlight Table Rows ---------- */
.highlight-row {
    transition: background-color 0.15s ease;
}

.highlight-detail {
    animation: fadeIn 0.25s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ---------- Keyboard Shortcut Keys ---------- */
.shortcut-key {
    display: inline-block;
    padding: 1px 6px;
    font-size: 0.65rem;
    font-weight: 600;
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
    color: #475569;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    min-width: 20px;
    text-align: center;
    box-shadow: 0 1px 0 #cbd5e1;
}

/* ---------- Form Elements ---------- */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #6366f1; /* indigo-500 */
    cursor: pointer;
    border: 2px solid #ffffff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
    transition: box-shadow 0.15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #6366f1;
    cursor: pointer;
    border: 2px solid #ffffff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

/* ---------- Table Styles ---------- */
table {
    border-collapse: separate;
    border-spacing: 0;
}

/* ---------- Utility: Smooth Transitions ---------- */
.transition-shadow {
    transition: box-shadow 0.2s ease;
}

.transition-colors {
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

/* ---------- Mobile Responsiveness Tweaks ---------- */
@media (max-width: 767px) {
    .review-card {
        padding: 1.25rem;
    }

    .review-quote p {
        font-size: 1.125rem; /* 18px */
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-card .text-3xl {
        font-size: 1.75rem;
    }

    /* Better touch targets for mobile */
    .review-btn {
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
    }

    .source-badge {
        font-size: 0.6rem;
        padding: 1px 8px;
    }

    /* Prevent horizontal scroll on tables */
    .overflow-x-auto {
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 639px) {
    main .max-w-6xl {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

/* ---------- Print ---------- */
@media print {
    #sidebar,
    #sidebar-toggle,
    #sidebar-overlay,
    #toast-container,
    #confirm-overlay {
        display: none !important;
    }

    main {
        margin-left: 0 !important;
        padding: 0 !important;
    }

    .no-print {
        display: none !important;
    }
}


/* ---------- Stat Card Hover Effect (top-line gradient) ---------- */
.stat-card {
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--color-accent), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
}
.stat-card:hover::before {
    opacity: 1;
}

/* ---------- Toast Animations ---------- */
#toast-container > div {
    will-change: transform, opacity;
}

/* ---------- Loading State ---------- */
.btn-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}
.btn-loading::after {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-left: 6px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
    vertical-align: middle;
}
@keyframes btn-spin {
    to { transform: rotate(360deg); }
}

/* ── Bottom Navigation ─────────────────────────────────── */
.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 6px 10px 4px;
    border-radius: 8px;
    color: var(--sidebar-muted);
    text-decoration: none;
    transition: color 0.15s, background 0.15s;
    min-width: 0;
    flex: 1;
}
.bottom-nav-item:hover,
.bottom-nav-item:active {
    color: var(--sidebar-active);
    background: var(--sidebar-hover);
}
.bottom-nav-active {
    color: var(--sidebar-active) !important;
}
.safe-area-pb {
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Mobile Highlight Cards ──────────────────────────── */
@media (max-width: 767px) {
    .hl-table-wrapper { display: none; }
    .hl-cards-wrapper { display: block; }
}

@media (min-width: 768px) {
    .hl-cards-wrapper { display: none; }
}

.hl-card {
    background: var(--bg-card, #ffffff);
    border: 1px solid var(--border-card, #e2e8f0);
    border-radius: 12px;
    padding: 14px 16px;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
    position: relative;
    overflow: hidden;
}

.hl-card:active {
    transform: scale(0.99);
}

.hl-card-text {
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--text-primary, #1e293b);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.hl-card-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-muted, #64748b);
    margin-top: 8px;
}

.hl-card-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-card, #e2e8f0);
}

.hl-card-detail {
    display: none;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-card, #e2e8f0);
    animation: fadeIn 0.2s ease-out;
}

.hl-card-detail.open { display: block; }

/* ── Swipe Actions ──────────────────────────────────── */
.hl-card-swipe-container {
    position: relative;
    overflow: hidden;
    touch-action: pan-y;
}

.hl-card-swipe-reveal {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    display: flex;
    align-items: stretch;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    z-index: 2;
}

.hl-card-swipe-reveal.open {
    transform: translateX(0);
}

.hl-card-swipe-reveal button,
.hl-card-swipe-reveal a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 64px;
    font-size: 0.65rem;
    font-weight: 600;
    gap: 2px;
    border: none;
    cursor: pointer;
    transition: filter 0.15s;
    color: #fff;
}

.hl-card-swipe-reveal button:active,
.hl-card-swipe-reveal a:active {
    filter: brightness(0.9);
}

.hl-card-swipe-reveal .swipe-fav {
    background: #f59e0b;
}
.hl-card-swipe-reveal .swipe-delete {
    background: #ef4444;
}
.hl-card-swipe-reveal .swipe-share {
    background: #6366f1;
}

/* ── Full-screen Mobile Modals ───────────────────────── */
@media (max-width: 767px) {
    #confirm-dialog {
        max-width: 100% !important;
        width: 100% !important;
        margin: 0 !important;
        border-radius: 16px 16px 0 0 !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 85vh;
        overflow-y: auto;
        transform: translateY(0);
        animation: slideUp 0.3s ease-out;
    }
    #confirm-overlay {
        align-items: flex-end !important;
    }
    #confirm-dialog .modal-drag-handle {
        display: block;
    }
}

.modal-drag-handle {
    display: none;
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: #cbd5e1;
    margin: 8px auto 4px;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* ── Review Mobile ──────────────────────────────────── */
@media (max-width: 767px) {
    .review-card {
        border-radius: 16px;
        padding: 1rem;
    }
    .review-card .grid.grid-cols-4 {
        gap: 8px;
    }
    .review-card .grid.grid-cols-4 button {
        padding: 14px 8px;
        border-radius: 12px;
        font-size: 0.7rem;
    }
    .review-card .grid.grid-cols-4 button .block.text-lg {
        font-size: 1.5rem;
    }
    .review-card .review-quote p {
        font-size: 1.05rem;
    }
    .review-secondary-actions {
        gap: 6px;
        flex-wrap: wrap;
    }
    .review-secondary-actions button,
    .review-secondary-actions a,
    .review-secondary-actions form {
        flex: 1;
        min-width: 0;
    }
    .review-secondary-actions button,
    .review-secondary-actions a {
        padding: 10px 6px !important;
        font-size: 0.7rem !important;
        border-radius: 10px !important;
        text-align: center;
        justify-content: center;
    }
}

/* ── Bottom Nav SVG Icons ────────────────────────────── */
.bottom-nav-icon {
    width: 22px;
    height: 22px;
    display: block;
}
.bottom-nav-icon path {
    stroke: currentColor;
    stroke-width: 1.8;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.bottom-nav-active .bottom-nav-icon path {
    stroke: var(--sidebar-active, #6366f1);
}

/* ── Safe area for bottom nav on notched phones ─────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    nav.fixed.bottom-0 {
        padding-bottom: env(safe-area-inset-bottom, 4px);
    }
}

/* ── Review Heatmap ─────────────────────────────────── */
.heatmap-cell {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    transition: transform 0.1s ease, opacity 0.1s ease;
    cursor: default;
}
.heatmap-cell:hover {
    transform: scale(1.4);
    z-index: 5;
    position: relative;
}
.heatmap-cell.level-0 { background: var(--page-alt, #f1f5f9); }
.heatmap-cell.level-1 { background: #bbf7d0; }
.heatmap-cell.level-2 { background: #4ade80; }
.heatmap-cell.level-3 { background: #16a34a; }
.heatmap-cell.level-4 { background: #15803d; }
/* Dark theme overrides */
[data-theme="dark"] .heatmap-cell.level-0 { background: #1e293b; }
[data-theme="dark"] .heatmap-cell.level-1 { background: #14532d; }
[data-theme="dark"] .heatmap-cell.level-2 { background: #166534; }
[data-theme="dark"] .heatmap-cell.level-3 { background: #15803d; }
[data-theme="dark"] .heatmap-cell.level-4 { background: #22c55e; }
