/* ============================================
   KDP PILOT — Main Stylesheet
   Light theme · Blue primary · Rounded · Soft shadows
   ============================================ */

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #dbeafe;
    --primary-soft: #eff6ff;

    --bg: #f6f8fa;
    --bg-card: #ffffff;
    --sidebar-bg: #ffffff;
    --sidebar-border: #e5e7eb;
    --navbar-bg: #ffffff;

    --text: #111827;
    --text-muted: #6b7280;
    --text-soft: #9ca3af;
    --border: #e5e7eb;
    --border-soft: #f3f4f6;

    --shadow-sm: 0 1px 2px rgba(13,38,76,.04);
    --shadow-md: 0 2px 8px rgba(13,38,76,.06);
    --shadow-lg: 0 6px 24px rgba(13,38,76,.08);

    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 18px;

    --sidebar-w: 260px;
    --navbar-h: 64px;

    --success: #10b981;
    --info: #06b6d4;
    --warning: #f59e0b;
    --danger: #ef4444;
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    font-family: 'Inter', -apple-system, 'Segoe UI', 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* ==== Layout ==== */
.app-wrapper { display: flex; min-height: 100vh; }

/* ==== Sidebar ==== */
.app-sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    position: fixed; top: 0; left: 0; bottom: 0;
    display: flex; flex-direction: column;
    z-index: 100;
    transition: transform .25s ease;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 18px 20px; display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--border-soft);
    position: sticky; top: 0; background: var(--sidebar-bg); z-index: 2;
}
.brand-link { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand-link:hover { color: var(--text); }
.brand-logo { height: 30px; }
.brand-text { font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; }

.sidebar-close { background: transparent; border: none; color: var(--text-muted); }

.sidebar-nav { padding: 12px 12px 24px; flex: 1; }
.nav-section { margin-bottom: 16px; }
.nav-section-title {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
    color: var(--text-soft); font-weight: 600;
    padding: 8px 12px 6px;
}
.app-sidebar .nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: var(--radius-sm);
    color: var(--text-muted); font-weight: 500;
    margin-bottom: 2px; transition: all .15s ease;
}
.app-sidebar .nav-link i:first-child { font-size: 1.1rem; width: 20px; text-align: center; flex-shrink: 0; }
.app-sidebar .nav-link span { flex: 1; font-size: .93rem; }
.app-sidebar .nav-link:hover {
    background: var(--primary-soft); color: var(--primary-dark);
}
.app-sidebar .nav-link.active {
    background: var(--primary); color: #fff !important;
}
.app-sidebar .nav-link.active i { color: #fff; }
.app-sidebar .nav-link.nav-disabled { opacity: .65; cursor: not-allowed; }
.app-sidebar .nav-link.nav-disabled:hover { background: transparent; color: var(--text-muted); }

/* ==== Main area ==== */
.app-main {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex; flex-direction: column; min-width: 0;
}

.app-navbar {
    position: sticky; top: 0; z-index: 50;
    height: var(--navbar-h); background: var(--navbar-bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.navbar-inner {
    display: flex; align-items: center; gap: 16px;
    height: 100%; padding: 0 24px;
}
.btn-icon {
    background: transparent; border: none; color: var(--text-muted);
    width: 38px; height: 38px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.15rem;
}
.btn-icon:hover { background: var(--border-soft); color: var(--text); }

.navbar-search { flex: 1; max-width: 480px; }
.search-box { position: relative; }
.search-box i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-soft); pointer-events: none; }
.search-box .form-control { padding-left: 35px; border-radius: var(--radius-sm); background: var(--bg); border-color: var(--border-soft); }
.search-box .form-control:focus { background: #fff; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.search-dropdown {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0;
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); max-height: 480px; overflow-y: auto;
    display: none; z-index: 70;
}
.search-dropdown.show { display: block; }
.search-group { padding: 8px 0; }
.search-group + .search-group { border-top: 1px solid var(--border-soft); }
.search-group-label { padding: 6px 16px; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-soft); font-weight: 600; }
.search-result { display: flex; align-items: center; gap: 12px; padding: 8px 16px; color: var(--text); cursor: pointer; }
.search-result:hover { background: var(--primary-soft); }
.search-result i { color: var(--text-muted); }
.search-empty { padding: 24px; text-align: center; color: var(--text-muted); font-size: .9rem; }

.navbar-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.nav-item-dropdown .notif-badge {
    position: absolute; top: 4px; right: 4px;
    background: var(--danger); color: #fff;
    font-size: .65rem; font-weight: 700;
    min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
}

.btn-user-menu { background: transparent; border: none; padding: 4px 8px; border-radius: var(--radius-sm); color: var(--text); }
.btn-user-menu:hover { background: var(--border-soft); }
.navbar-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--border); }
.user-name { font-size: .85rem; font-weight: 600; line-height: 1.1; text-align: left; }
.user-role { font-size: .7rem; color: var(--text-muted); line-height: 1.1; text-align: left; }

.user-dropdown { min-width: 240px; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 8px 0; }
.user-dropdown .dropdown-item { padding: 8px 16px; font-size: .9rem; }
.user-dropdown .dropdown-header { padding: 8px 16px; }

/* ==== Notifications dropdown ==== */
.notif-dropdown {
    width: 360px; max-width: 92vw;
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); padding: 0; overflow: hidden;
}
.notif-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border-soft); }
.notif-list { max-height: 380px; overflow-y: auto; }
.notif-item {
    display: flex; align-items: flex-start; gap: 10px; padding: 12px 16px;
    color: var(--text); border-bottom: 1px solid var(--border-soft); transition: background .15s ease;
}
.notif-item:hover { background: var(--primary-soft); }
.notif-item.unread { background: rgba(59,130,246,.04); border-left: 3px solid var(--primary); }
.notif-icon { width: 36px; height: 36px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.notif-body { flex: 1; min-width: 0; }
.notif-title { font-weight: 600; font-size: .9rem; }
.notif-msg { color: var(--text-muted); font-size: .82rem; }
.notif-time { color: var(--text-soft); font-size: .72rem; margin-top: 2px; }
.notif-footer { padding: 10px 16px; text-align: center; border-top: 1px solid var(--border-soft); }
.notif-footer a { font-size: .85rem; font-weight: 500; }
.notif-empty { padding: 32px 16px; text-align: center; color: var(--text-muted); }
.notif-empty i { font-size: 2rem; display: block; margin-bottom: 8px; color: var(--text-soft); }

/* ==== Content area ==== */
.app-content { flex: 1; padding: 24px; min-width: 0; }
.content-inner { max-width: 1400px; margin: 0 auto; }

.page-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-title { font-size: 1.5rem; font-weight: 700; margin: 0 0 4px; letter-spacing: -.01em; }
.page-subtitle { color: var(--text-muted); margin: 0; font-size: .92rem; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ==== Cards & components ==== */
.content-card, .stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}
.stat-card { display: flex; align-items: flex-start; gap: 14px; }
.stat-icon {
    width: 48px; height: 48px; border-radius: var(--radius-sm);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.4rem; flex-shrink: 0;
}
.stat-body { flex: 1; min-width: 0; }
.stat-label { font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; margin-top: 2px; letter-spacing: -.01em; }
.stat-meta { font-size: .76rem; color: var(--text-muted); margin-top: 4px; }
.storage-bar { height: 4px; background: var(--border-soft); border-radius: 999px; margin: 6px 0 4px; overflow: hidden; }
.storage-fill { height: 100%; background: linear-gradient(90deg, var(--warning), var(--danger)); border-radius: 999px; transition: width .3s ease; }

.card-header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 16px; }

/* Soft background utilities */
.bg-soft-primary { background: rgba(59,130,246,.12); }
.bg-soft-success { background: rgba(16,185,129,.12); }
.bg-soft-info    { background: rgba(6,182,212,.12); }
.bg-soft-warning { background: rgba(245,158,11,.14); }
.bg-soft-danger  { background: rgba(239,68,68,.12); }
.bg-soft-secondary { background: rgba(107,114,128,.12); }

/* Buttons */
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); }
.btn { border-radius: var(--radius-sm); font-weight: 500; }

/* Forms */
.form-control, .form-select { border-radius: var(--radius-sm); border-color: var(--border); }
.form-control:focus, .form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.input-group-text { background: var(--bg); border-color: var(--border); }
.form-label { font-weight: 500; font-size: .88rem; color: var(--text); margin-bottom: 6px; }

/* Tables */
.table { color: var(--text); }
.table > :not(caption) > * > * { padding: 12px 14px; vertical-align: middle; }
.table thead th { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; background: var(--bg); border-bottom: 1px solid var(--border); }
.table-hover tbody tr:hover { background: var(--primary-soft); }
.dataTables_wrapper .dataTables_filter input { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 10px; }
.dataTables_wrapper .dataTables_length select { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px 8px; }
.dataTables_wrapper .dataTables_paginate .paginate_button { border-radius: var(--radius-sm) !important; }

/* Tabs */
.nav-tabs-bordered { border-bottom: 1px solid var(--border); }
.nav-tabs-bordered .nav-link { border: none; color: var(--text-muted); font-weight: 500; padding: 10px 16px; border-bottom: 2px solid transparent; background: transparent; }
.nav-tabs-bordered .nav-link.active { color: var(--primary); border-bottom-color: var(--primary); background: transparent; }

/* Recent projects list */
.recent-projects { display: flex; flex-direction: column; gap: 8px; }
.recent-project-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    color: var(--text); border: 1px solid var(--border-soft);
    transition: all .15s ease;
}
.recent-project-item:hover { background: var(--primary-soft); border-color: var(--primary-light); color: var(--text); }
.rp-icon { width: 36px; height: 36px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.rp-body { flex: 1; min-width: 0; }
.rp-name { font-weight: 600; font-size: .92rem; }
.rp-meta { font-size: .75rem; color: var(--text-muted); display: flex; gap: 6px; align-items: center; }

/* Module cards (placeholders) */
.module-card { display: flex; gap: 12px; padding: 14px; border: 1px solid var(--border-soft); border-radius: var(--radius); background: var(--bg); height: 100%; color: var(--text); }
.module-card-live { transition: all .15s; cursor: pointer; }
.module-card-live:hover { border-color: var(--primary-light); box-shadow: var(--shadow-md); transform: translateY(-2px); color: var(--text); }
.module-card-live:hover .bi-arrow-right { color: var(--primary) !important; transform: translateX(3px); transition: transform .15s; }

/* Photo-style module cards */
.module-photo-card {
    position: relative;
    display: block;
    height: 450px;
    border-radius: var(--radius);
    overflow: hidden;
    background-size: cover;
    background-position: center 5%;
    background-color: var(--bg);
    border: 1px solid var(--border-soft);
    transition: all .2s ease;
}
.module-photo-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.module-photo-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(0,0,0,0) 40%, rgba(0,0,0,.75) 100%);
}
.module-photo-arrow {
    position: absolute;
    top: 12px; right: 12px;
    width: 32px; height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,.85);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    color: var(--text);
    font-size: .95rem;
    z-index: 2;
    transition: all .2s;
}
.module-photo-card:hover .module-photo-arrow { background: var(--primary); color: #fff; transform: translateX(2px); }

.module-photo-hover-btn {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%) scale(.85);
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 22px;
    border-radius: 999px;
    background: linear-gradient(135deg, #f97316, #f59e0b);
    color: #fff;
    font-weight: 700;
    font-size: .92rem;
    white-space: nowrap;
    box-shadow: 0 8px 20px rgba(249,115,22,.4);
    opacity: 0;
    visibility: hidden;
    transition: all .25s ease;
    z-index: 2;
}
.module-photo-card:hover .module-photo-hover-btn {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}
.module-photo-overlay {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    padding: 16px;
    z-index: 1;
}
.module-photo-title {
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    margin: 0 0 4px;
    text-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.module-photo-desc {
    color: rgba(255,255,255,.88);
    font-size: .8rem;
    margin: 0;
    line-height: 1.4;
    text-shadow: 0 1px 2px rgba(0,0,0,.4);
}
.module-icon { width: 44px; height: 44px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.3rem; flex-shrink: 0; }
.module-body { flex: 1; min-width: 0; }
.module-title { font-size: .98rem; font-weight: 600; }
.module-desc { font-size: .82rem; color: var(--text-muted); margin: 4px 0 10px; }

/* Activity */
.activity-list { display: flex; flex-direction: column; gap: 14px; }
.activity-item { display: flex; gap: 12px; }
.activity-dot { width: 8px; height: 8px; background: var(--primary); border-radius: 50%; margin-top: 8px; flex-shrink: 0; box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.activity-action { font-weight: 600; font-size: .88rem; }
.activity-desc { font-size: .82rem; color: var(--text-muted); }
.activity-time { font-size: .72rem; color: var(--text-soft); }

/* Empty state */
.empty-state { padding: 36px 16px; text-align: center; }
.empty-state i { font-size: 2.5rem; color: var(--text-soft); display: block; margin-bottom: 8px; }
.empty-state h6 { margin: 8px 0 4px; font-weight: 600; }

/* Profile */
.profile-avatar-wrap { text-align: center; padding: 10px 0; }
.profile-avatar { width: 120px; height: 120px; border-radius: 50%; object-fit: cover; margin-bottom: 12px; border: 4px solid #fff; box-shadow: 0 0 0 1px var(--border), var(--shadow-md); }
.info-list dt { font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; margin-top: 10px; }
.info-list dd { margin: 2px 0; font-weight: 500; }
.info-table td { padding: 8px 0; font-size: .9rem; }

/* Dropzone */
.dropzone-card {
    border: 2px dashed var(--border); background: var(--bg-card);
    border-radius: var(--radius); padding: 28px; text-align: center;
    transition: all .2s ease;
}
.dropzone-card.dragging { border-color: var(--primary); background: var(--primary-soft); }
.dropzone-inner i { font-size: 2.2rem; color: var(--primary); display: block; margin-bottom: 8px; }
.upload-progress { margin-top: 14px; max-width: 480px; margin-left: auto; margin-right: auto; }

/* Flash */
.alert { border-radius: var(--radius); border: none; }
.alert-success { background: rgba(16,185,129,.1); color: #047857; }
.alert-danger  { background: rgba(239,68,68,.1); color: #b91c1c; }
.alert-warning { background: rgba(245,158,11,.12); color: #92400e; }
.alert-info    { background: rgba(6,182,212,.1); color: #0e7490; }

/* Footer */
.app-footer {
    padding: 16px 24px; border-top: 1px solid var(--border);
    display: flex; justify-content: space-between;
    color: var(--text-muted); font-size: .82rem; background: var(--bg-card);
}

.sidebar-backdrop { display: none; }

/* ==== Mobile ==== */
@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); }
    .app-sidebar.open { transform: translateX(0); }
    .app-main { margin-left: 0; }
    .sidebar-backdrop {
        position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90;
        display: none;
    }
    .sidebar-backdrop.show { display: block; }
    .navbar-search { max-width: none; }
    .app-content { padding: 16px; }
    .page-header { flex-direction: column; align-items: stretch; }
    .user-name, .user-role { display: none !important; }
}

/* DataTables tweaks */
table.dataTable.no-footer { border-bottom: 1px solid var(--border-soft); }
.dataTables_info, .dataTables_length, .dataTables_filter { font-size: .85rem; color: var(--text-muted); }
.page-link { color: var(--primary); border-color: var(--border); }
.page-item.active .page-link { background: var(--primary); border-color: var(--primary); }

/* Misc */
code { background: var(--bg); padding: 2px 6px; border-radius: 4px; color: var(--primary-dark); font-size: .85em; }

/* ============================================
   BookForge — brand badge (used instead of an image logo)
   ============================================ */
.brand-badge {
    width: 34px; height: 34px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 1rem;
    flex-shrink: 0;
}
.brand-badge-lg { width: 46px; height: 46px; font-size: 1.3rem; border-radius: 12px; }
.navbar-brand-mini { gap: 10px; }

.navbar-avatar-fallback {
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--primary-soft); color: var(--primary);
    font-size: 1rem;
}

/* ============================================
   Auth pages (login/register/forgot/reset)
   ============================================ */
.auth-body {
    background: linear-gradient(160deg, var(--bg) 0%, var(--primary-soft) 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.auth-wrap { width: 100%; max-width: 420px; }
.auth-brand {
    display: flex; align-items: center; justify-content: center; gap: 12px;
    margin-bottom: 24px;
}
.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 32px;
}

/* ============================================
   Agent cards — "coming soon" state
   ============================================ */
.module-photo-card-soon { cursor: pointer; filter: grayscale(.35); }
.module-photo-card-soon:hover { transform: none; filter: grayscale(.15); }
.module-photo-soon-badge {
    position: absolute;
    top: 12px; right: 12px;
    background: rgba(0,0,0,.55);
    color: #fff;
    font-size: .72rem;
    font-weight: 700;
    padding: 5px 12px;
    border-radius: 999px;
    z-index: 2;
    backdrop-filter: blur(4px);
}

/* ============================================
   Navbar Credit Balance Badge
   ============================================ */
.navbar-credits-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    background: var(--primary-soft, #eef2ff);
    color: var(--primary, #4f46e5);
    border: 1px solid var(--primary-light, #818cf8);
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 700;
    text-decoration: none;
    transition: all .15s;
    white-space: nowrap;
}
.navbar-credits-badge:hover {
    background: var(--primary, #4f46e5);
    color: #fff;
    border-color: var(--primary, #4f46e5);
}
.navbar-credits-badge i {
    font-size: .8rem;
}
.navbar-credits-badge.low {
    background: #fee2e2;
    color: #dc2626;
    border-color: #fca5a5;
}
.navbar-credits-badge.low:hover {
    background: #dc2626;
    color: #fff;
}

/* ============================================
   Admin — Multi-Plan Checkbox UI
   ============================================ */
.plan-check-item {
    cursor: pointer;
    transition: all .15s;
    user-select: none;
}
.plan-check-item:hover {
    border-color: var(--primary) !important;
    background: var(--primary-soft);
}
.plan-check-item.border-primary {
    border-color: var(--primary) !important;
}
