/* ============================================================
   CyberData Document Library — Stylesheet v3.6
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary:      #2563eb;
    --primary-dark: #1d4ed8;
    --danger:       #dc2626;
    --success:      #16a34a;
    --bg:           #f1f5f9;
    --surface:      #ffffff;
    --border:       #e2e8f0;
    --text:         #1e293b;
    --muted:        #64748b;
    --radius:       8px;
    --shadow:       0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

body { font-family: system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; }

.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem 1rem; border-radius: var(--radius); border: none; cursor: pointer; font-size: .9rem; font-weight: 500; text-decoration: none; transition: background .15s, opacity .15s; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-outline   { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: #f8fafc; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-block     { width: 100%; justify-content: center; padding: .75rem; font-size: 1rem; }
.btn-sm        { padding: .3rem .7rem; font-size: .82rem; }
.btn:disabled  { opacity: .6; cursor: not-allowed; }

.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; }
.alert-error   { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }

/* ============================================================ Login */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-container { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-md); padding: 2.5rem; width: 100%; max-width: 420px; }
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo h1 { font-size: 1.4rem; color: var(--primary); margin-bottom: .3rem; }
.login-logo p  { color: var(--muted); font-size: .9rem; }
.login-form .form-group { margin-bottom: 1.2rem; }
.login-form label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .4rem; color: var(--muted); }
.login-form input { width: 100%; padding: .65rem .85rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: .95rem; }
.login-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.login-form .btn-block { margin-top: .5rem; }

/* ============================================================ Header */
.header { background: var(--surface); border-bottom: 1px solid var(--border); padding: .85rem 1.5rem; display: flex; align-items: center; justify-content: space-between; box-shadow: var(--shadow); position: sticky; top: 0; z-index: 100; }
.header h1 { font-size: 1.1rem; color: var(--primary); }
.title-link { color: var(--primary); text-decoration: none; }
.title-link:hover { text-decoration: underline; opacity: .85; }

/* AI status pill */
.ai-status {
    display: flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: 99px;
    font-size: .75rem; font-weight: 500;
    border: 1px solid transparent; transition: all .3s;
    white-space: nowrap;
}
.ai-status-dot {
    width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.ai-status.connected {
    background: #f0fdf4; border-color: #bbf7d0; color: #16a34a;
}
.ai-status.connected .ai-status-dot { background: #16a34a; }
.ai-status.checking {
    background: #fefce8; border-color: #fde68a; color: #92400e;
}
.ai-status.checking .ai-status-dot { background: #f59e0b; }
.ai-status.unavailable {
    background: #fef2f2; border-color: #fecaca; color: #dc2626;
}
.ai-status.unavailable .ai-status-dot { background: #dc2626; }
.title-link:hover { text-decoration: underline; opacity: .85; }
.header-right { display: flex; align-items: center; gap: .6rem; }
.user-badge { font-size: .85rem; color: var(--muted); padding: .3rem .6rem; background: var(--bg); border-radius: 99px; }

/* ============================================================ Layout */
.chat-page { min-height: 100vh; display: flex; flex-direction: column; }
.chat-layout { display: grid; grid-template-columns: 380px 1fr; gap: 1.5rem; padding: 1.5rem; flex: 1; max-width: 1400px; margin: 0 auto; width: 100%; min-width: 0; }

/* ============================================================ Search panel */
.search-panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; align-self: start; position: sticky; top: 72px; max-height: calc(100vh - 90px); overflow-y: auto; }
.search-panel h2 { font-size: 1rem; margin-bottom: 1.2rem; }
.step { margin-bottom: 1.4rem; }
.step-label { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .6rem; }
.hint-text { font-size: .8rem; color: var(--muted); margin-bottom: .5rem; line-height: 1.4; }
#product-query { width: 100%; padding: .65rem .85rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: .9rem; margin-bottom: .5rem; }
#product-query:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.search-dropdown { display: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); margin-top: -.4rem; margin-bottom: .5rem; max-height: 220px; overflow-y: auto; }
.dropdown-item { padding: .6rem .85rem; cursor: pointer; font-size: .88rem; border-bottom: 1px solid #f1f5f9; transition: background .1s; }
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover { background: #eff6ff; }
.dropdown-item.muted { color: var(--muted); cursor: default; }
.browse-btn { margin-top: .25rem; width: 100%; justify-content: center; }
.browse-list { margin-top: .75rem; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; max-height: 300px; overflow-y: auto; }
.browse-list-header { display: flex; align-items: center; justify-content: space-between; padding: .6rem .85rem; background: #f8fafc; border-bottom: 1px solid var(--border); font-size: .82rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; position: sticky; top: 0; }
.browse-item { display: flex; align-items: baseline; gap: .75rem; padding: .55rem .85rem; cursor: pointer; border-bottom: 1px solid #f1f5f9; transition: background .1s; font-size: .87rem; }
.browse-item:last-child { border-bottom: none; }
.browse-item:hover { background: #eff6ff; }
.browse-pn { font-weight: 700; color: var(--primary); white-space: nowrap; min-width: 60px; }
.browse-desc { color: var(--text); }
.selected-product { background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: var(--radius); padding: .65rem .85rem; font-size: .88rem; margin-bottom: .5rem; display: flex; align-items: center; flex-wrap: wrap; gap: .3rem; }
.search-panel textarea { width: 100%; padding: .65rem .85rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: .9rem; resize: vertical; font-family: inherit; }
.search-panel textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

/* ============================================================ Results panel */
.results-panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; min-height: 400px; position: relative; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
#loading-overlay { display: none; flex-direction: column; align-items: center; justify-content: center; position: absolute; inset: 0; background: var(--surface); border-radius: var(--radius); z-index: 10; gap: 1.5rem; }
#loading-video { width: 60%; max-width: 380px; border-radius: 12px; box-shadow: var(--shadow-md); }
.loading-text { font-size: 1rem; color: var(--muted); font-weight: 500; animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }
#results-content { flex: 1; min-width: 0; width: 100%; }
.result-header { border-bottom: 1px solid var(--border); padding-bottom: 1rem; margin-bottom: 1.2rem; }
.result-header h2 { font-size: 1rem; margin-bottom: .5rem; }
.result-context { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .5rem; }
.tag { background: #eff6ff; color: var(--primary); font-size: .78rem; padding: .2rem .6rem; border-radius: 99px; font-weight: 500; }
.result-question { font-size: .88rem; color: var(--muted); }
.result-body { font-size: .93rem; line-height: 1.8; word-wrap: break-word; }
.photo-result { display: flex; flex-direction: column; align-items: flex-start; gap: .75rem; padding: .5rem 0; }
.photo-hint { font-size: .78rem; color: var(--muted); }

/* ============================================================ PDF.js viewer */
.pdf-viewer-wrap {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: #525659;  /* dark background like Acrobat */
}

.pdf-toolbar {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .5rem .85rem;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
}

.pdf-canvas-wrap {
    overflow-y: auto;
    max-height: 620px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#pdf-canvas {
    display: none;
    max-width: 100%;
    box-shadow: 0 2px 8px rgba(0,0,0,.4);
    border-radius: 2px;
}

/* Related docs section below answer */
.related-docs { margin-top: 1.5rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.related-docs-title { font-size: .82rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .75rem; }

/* ============================================================ Setup guide */
.guide-list { display: flex; flex-direction: column; gap: .75rem; margin-top: .5rem; }
.guide-item { display: flex; align-items: center; gap: 1rem; padding: .85rem 1rem; border: 1px solid var(--border); border-radius: var(--radius); background: #f8fafc; flex-wrap: wrap; }
.guide-icon { font-size: 1.8rem; flex-shrink: 0; }
.guide-info { flex: 1; min-width: 0; }
.guide-name { font-weight: 600; font-size: .92rem; }
.guide-filename { font-size: .78rem; color: var(--muted); word-break: break-all; }

/* Empty state */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 300px; text-align: center; color: var(--muted); }
.empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h3 { font-size: 1.1rem; margin-bottom: .5rem; color: var(--text); }
.empty-state p { font-size: .9rem; max-width: 320px; }

/* ============================================================ Lightbox */
.lightbox { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 1000; align-items: center; justify-content: center; padding: 1.5rem; }
.lightbox-inner { background: var(--surface); border-radius: 12px; padding: 1.5rem; position: relative; max-width: 900px; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 1rem; box-shadow: 0 25px 60px rgba(0,0,0,.4); max-height: 90vh; }
.lightbox-close { position: absolute; top: .75rem; right: .75rem; background: #f1f5f9; border: none; border-radius: 50%; width: 32px; height: 32px; font-size: 1rem; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.lightbox-close:hover { background: #e2e8f0; }
#lightbox-img { max-width: 100%; max-height: calc(90vh - 120px); object-fit: contain; border-radius: var(--radius); border: 1px solid var(--border); display: block; }
.lightbox-footer { display: flex; gap: 1rem; }

/* ============================================================ Admin */
.admin-page { min-height: 100vh; display: flex; flex-direction: column; }
.admin-layout { padding: 1.5rem; max-width: 1100px; margin: 0 auto; width: 100%; }
.admin-section { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; margin-bottom: 1.5rem; }
.admin-section h2 { font-size: 1rem; margin-bottom: 1rem; padding-bottom: .5rem; border-bottom: 1px solid var(--border); }
.admin-section h3 { font-size: .9rem; margin: 1.2rem 0 .6rem; }
.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.data-table th { text-align: left; padding: .5rem .75rem; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 1px solid var(--border); }
.data-table td { padding: .5rem .75rem; border-bottom: 1px solid #f1f5f9; }
.data-table input[type="text"] { width: 100%; padding: .35rem .5rem; border: 1px solid var(--border); border-radius: 4px; font-size: .85rem; }
.data-table input[type="text"]:focus { outline: none; border-color: var(--primary); }
.role-badge { font-size: .75rem; padding: .2rem .6rem; border-radius: 99px; font-weight: 600; }
.role-admin    { background: #fef3c7; color: #92400e; }
.role-customer { background: #dbeafe; color: #1e40af; }
.inline-form { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.inline-form input, .inline-form select { padding: .5rem .75rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: .88rem; }
.product-toolbar { display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem; }
.save-status { font-size: .85rem; }
.save-status.success { color: var(--success); }
.save-status.error   { color: var(--danger); }
.add-user-form { margin-top: 1.2rem; }
.muted { color: var(--muted); font-size: .85rem; }

/* ============================================================ Responsive */
@media (max-width: 900px) {
    .chat-layout { grid-template-columns: 1fr; }
    .search-panel { position: static; max-height: none; }
    .pdf-canvas-wrap { max-height: 400px; }
}
@media (max-width: 768px) {
    #loading-video { width: 85%; }
    .pdf-canvas-wrap { max-height: 300px; }
}
