:root {
  color-scheme: light;
  font-family: "Segoe UI", Tahoma, sans-serif;
  color: #1A2B3C;
  background: #F4F7FB;
  --pb-primary: #0064B0;
  --pb-primary-dark: #003F73;
  --pb-primary-light: #E6F0F8;
  --pb-accent: #0078D4;
  --pb-border: #d0dbe6;
  --pb-text-muted: #5a7080;
}
* { box-sizing: border-box; }
body { margin: 0; }
header, .pb-header { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 24px 4%; color: white; background: linear-gradient(135deg, var(--pb-primary), var(--pb-primary-dark)); }
h1 { margin: 0; font-size: 1.8rem; } header p, .pb-header p { margin-bottom: 0; }
#appVersion { color: #b8d4ee; font-size: .8rem; white-space: nowrap; }
#engine { max-width: 420px; font-size: .9rem; }
main { max-width: 1400px; margin: auto; padding: 24px; }
nav, .actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
section { margin-top: 20px; padding: 24px; background: white; border: 1px solid var(--pb-border); border-radius: 12px; }
button { cursor: pointer; background: white; color: var(--pb-primary-dark); border: 1px solid var(--pb-border); border-radius: 6px; padding: 10px 16px; font: inherit; }
button:hover { background: var(--pb-primary-light); }
button.primary { background: var(--pb-primary); color: white; border-color: var(--pb-primary); }
button.primary:hover { background: var(--pb-primary-dark); }
button:disabled { opacity: .55; cursor: wait; }
input, textarea, select { width: 100%; font: inherit; padding: 9px; border: 1px solid var(--pb-border); border-radius: 5px; background: white; color: #1A2B3C; }
input:focus, textarea:focus, select:focus { border-color: var(--pb-accent); box-shadow: 0 0 0 0.2rem rgba(0,120,212,0.18); outline: none; }
textarea { min-height: 72px; resize: vertical; }
label { display: block; margin: 12px 0; font-weight: 600; } label input, label select, label textarea { margin-top: 5px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: normal; }
.check input { width: auto; margin: 0; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.muted, small { color: var(--pb-text-muted); } p { line-height: 1.55; }
.small { font-size: 0.85rem; }
#message { position: sticky; top: 8px; z-index: 5; background: var(--pb-primary-light); border: 1px solid #99c2e0; padding: 14px; border-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
#message.error { background: #fff0ee; border-color: #c27063; color: #7d2418; }
#dropZone { padding: 30px; border: 2px dashed #8ab4d8; border-radius: 8px; display: flex; flex-direction: column; align-items: center; gap: 12px; background: #f0f6fc; }
#dropZone.over { background: var(--pb-primary-light); border-color: var(--pb-primary); }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 18px; flex-wrap: wrap; }
#workbookPath { overflow-wrap: anywhere; }
summary { cursor: pointer; font-weight: 650; padding: 6px; }
.warning { background: #fff7dd; color: #6f5011; padding: 10px; overflow-wrap: anywhere; }
.image-error { color: #9b2a18; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 350px; overflow: auto; font-family: Tahoma, sans-serif; line-height: 1.8; }
progress { width: 100%; height: 22px; margin-top: 15px; }
dialog { border: 1px solid var(--pb-border); border-radius: 12px; max-width: 650px; padding: 26px; }
dialog::backdrop { background: #00284855; }
#cameraDialog { width: min(850px, 94vw); max-width: 850px; max-height: 92vh; overflow-y: auto; }
#cameraPreview { display: block; width: 100%; max-height: 50vh; background: #1A2B3C; object-fit: contain; }
#workbookList button { display: block; text-align: left; width: 100%; margin: 8px 0; overflow-wrap: anywhere; }
.workbook-list-row { display: flex; gap: 8px; align-items: center; }
.workbook-list-row > button:first-child { flex: 1; margin: 8px 0; }
.workbook-list-row > .btn-small { flex-shrink: 0; white-space: nowrap; }
.path-bar { display: flex; align-items: center; gap: 10px; }
.path-bar input { flex: 1; min-width: 0; }
.path-bar button { flex-shrink: 0; }
.workspace-tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--pb-border); margin: 20px 0; padding-bottom: 10px; }
.workspace-tabs [aria-selected="true"] { background: var(--pb-primary); color: white; }
.badge { display: inline-block; min-width: 25px; border-radius: 20px; padding: 2px 7px; background: var(--pb-primary-light); color: #1A2B3C; font-size: .85rem; margin-left: 5px; }
#imageQueue { padding-left: 22px; } #imageQueue li { margin: 10px 0; overflow-wrap: anywhere; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; min-width: 1600px; }
th, td { text-align: left; vertical-align: top; padding: 12px 10px; border-bottom: 1px solid var(--pb-border); }
th { background: #edf2f8; }
td input { min-width: 150px; } td:nth-child(3) input { min-width: 200px; }
td:nth-child(5) input, td:nth-child(6) input { min-width: 100px; }
td:nth-child(8), td:nth-child(9) { min-width: 70px; }
td a { display: block; margin: 4px 0 10px; color: var(--pb-accent); overflow-wrap: anywhere; }
td small { display: block; margin-top: 5px; }
td .warning { margin-top: 10px; font-size: .85rem; min-width: 160px; max-width: 280px; }
td .warning p { margin: 8px 0; }
#recordEditor { width: min(850px, 94vw); max-width: 850px; max-height: 90vh; overflow-y: auto; }
td a.source-icon { display: inline-flex; align-items: center; justify-content: center; padding: 6px; margin: 0 5px 5px 0; border: 1px solid var(--pb-border); border-radius: 6px; background: white; }
.source-icon img { display: block; width: 28px; height: 28px; object-fit: contain; }
.source-icon:hover { background: var(--pb-primary-light); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #c28424; outline-offset: 3px; }
@media (max-width: 850px) {
  header, .pb-header { flex-direction: column; align-items: flex-start; }
  main { padding: 12px; } section { padding: 16px; }
  .fields { grid-template-columns: minmax(0, 1fr); }
  .path-bar { flex-wrap: wrap; } .path-bar input { flex-basis: 100%; }
}

.source-badge { display: inline-block; padding: 3px 8px; border-radius: 12px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.source-badge.openlibrary { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }
.source-badge.alalc { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.source-badge.googlebooks { background: #f3e8ff; color: #6b21a8; border: 1px solid #e9d5ff; }
.source-badge.ketab { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.btn-small { padding: 4px 8px; font-size: 0.85rem; border-radius: 4px; margin: 2px; }
.barcode-alert { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; padding: 12px; border-radius: 8px; margin: 12px 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.camera-mode-bar { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 10px 14px; margin: 10px 0; }
.book-search { padding: 16px; border: 1px solid #d7e4de; border-radius: 10px; background: #f6faf7; }
.book-search h3 { margin: 0 0 10px; }
.book-search select { width: auto; flex-shrink: 0; }
#bookSearchStatus { margin: 10px 0 0; }
#bookSearchStatus.error { color: #9b2a18; }
#bookSearchStatus.loading::before { content: ""; display: inline-block; width: .85em; height: .85em; margin-right: .55em; vertical-align: -.1em; border: 2px solid #a7beb5; border-top-color: #215c54; border-radius: 50%; animation: book-search-spin .7s linear infinite; }
@keyframes book-search-spin { to { transform: rotate(360deg); } }
.book-results { list-style: none; margin: 12px 0 0; padding: 0; max-height: 460px; overflow-y: auto; border-top: 1px solid #d7e4de; }
.book-results li { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 12px 4px; border-bottom: 1px solid #d7e4de; }
.book-results .result-info { min-width: 0; flex: 1; }
.book-results .result-title { font-weight: 650; overflow-wrap: anywhere; }
.book-results .result-meta { margin-top: 4px; font-size: .9rem; color: var(--pb-text-muted); overflow-wrap: anywhere; }
.book-results .result-meta a { color: var(--pb-accent); margin-left: 8px; }
.book-results .result-actions { display: flex; flex-wrap: wrap; gap: 6px; flex-shrink: 0; align-items: center; }
.book-results .result-added { color: #166534; font-weight: 600; font-size: .9rem; }
.link-button { background: none; border: none; padding: 0; color: var(--pb-accent); text-decoration: underline; cursor: pointer; font: inherit; }
@media (max-width: 850px) { .book-results li { flex-direction: column; } }
button.btn-danger {
  color: #9b2a18;
  border-color: #c27063;
}
button.btn-danger:hover {
  background: #fff0ee;
}

/* ── Login & Settings pages ── */
.login-page { background: var(--pb-primary-light); min-height: 100vh; display: flex; flex-direction: column; }
.login-main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { background: white; border: 1px solid var(--pb-border); border-radius: 14px; box-shadow: 0 4px 24px rgba(0,64,111,0.1); padding: 32px; max-width: 420px; width: 100%; }
.login-card h2 { margin: 0 0 8px; color: var(--pb-primary-dark); }
.login-card label { font-weight: 600; margin: 14px 0 6px; }
.login-card input { border: 1px solid var(--pb-border); border-radius: 8px; padding: 10px 12px; }
.login-card button.primary { width: 100%; margin-top: 20px; padding: 12px; border-radius: 8px; font-size: 1rem; }
.login-alert { background: #fff0ee; border: 1px solid #c27063; color: #7d2418; padding: 12px; border-radius: 8px; margin-bottom: 16px; }
.btn-secondary { background: white; color: var(--pb-text-muted); border: 1px solid var(--pb-border); border-radius: 6px; padding: 8px 16px; cursor: pointer; }
.btn-secondary:hover { background: #f0f4f8; }

/* ── User/settings dropdown (header) ── */
.header-right { display: flex; align-items: center; gap: 8px; }
.user-dropdown { position: relative; }
.user-dropdown-btn { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.25); border-radius: 8px; padding: 6px 14px; color: white; cursor: pointer; font-size: 0.875rem; font-family: inherit; }
.user-dropdown-btn:hover { background: rgba(255,255,255,0.25); }
.user-avatar { width: 22px; height: 22px; border-radius: 50%; background: rgba(255,255,255,0.3); display: inline-flex; align-items: center; justify-content: center; font-size: 0.7rem; font-weight: 700; color: white; }
.user-dropdown-menu { position: absolute; right: 0; top: 100%; margin-top: 6px; background: white; border: 1px solid var(--pb-border); border-radius: 10px; box-shadow: 0 4px 24px rgba(0,64,111,0.12); min-width: 180px; z-index: 100; display: none; }
.user-dropdown-menu.open { display: block; }
.user-dropdown-menu a, .user-dropdown-menu button { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 10px 16px; border: none; background: none; color: var(--pb-primary-dark); font-size: 0.875rem; cursor: pointer; border-radius: 0; }
.user-dropdown-menu a:hover, .user-dropdown-menu button:hover { background: var(--pb-primary-light); }
.user-dropdown-menu hr { border: none; border-top: 1px solid var(--pb-border); margin: 4px 0; }
.user-dropdown-menu .signout-btn { color: #9b2a18; }

/* For settings.html header */
.user-badge { width: 24px; height: 24px; border-radius: 50%; background: rgba(255,255,255,0.3); display: inline-flex; align-items: center; justify-content: center; font-size: 0.7rem; font-weight: 700; color: white; }
.user-name { color: white; font-size: 0.875rem; }
