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

body {
    direction: rtl;
    font-family: 'David', 'Noto Sans Hebrew', 'Segoe UI', sans-serif;
    background: #f5f5f5;
    color: #222;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header / Search Bar */
#search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: #fff;
    border-bottom: 1px solid #ddd;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

#search-input {
    flex: 1;
    max-width: 500px;
    padding: 10px 16px;
    font-size: 18px;
    border: 2px solid #ccc;
    border-radius: 6px;
    direction: rtl;
    font-family: inherit;
}

#search-input:focus {
    outline: none;
    border-color: #4a90d9;
}

#search-btn {
    padding: 10px 24px;
    font-size: 16px;
    background: #4a90d9;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
}

#search-btn:hover {
    background: #3a7bc8;
}

#gap-label {
    font-size: 13px;
    color: #666;
    display: flex;
    align-items: center;
    gap: 4px;
}

#gap-label input {
    padding: 4px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 13px;
    text-align: center;
}

#precision-label {
    font-size: 13px;
    color: #666;
    display: flex;
    align-items: center;
    gap: 6px;
}

#precision-slider {
    width: 80px;
    cursor: pointer;
}

#precision-value-display {
    min-width: 52px;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
    background: #e8e8e8;
}

/* Sort toggle */
.toggle-group {
    display: flex;
    gap: 0;
    border: 1px solid #ccc;
    border-radius: 4px;
    overflow: hidden;
}

.toggle-btn {
    padding: 5px 10px;
    font-size: 12px;
    border: none;
    background: #fff;
    cursor: pointer;
    font-family: inherit;
    color: #555;
    border-right: 1px solid #ccc;
}

.toggle-btn:last-child {
    border-right: none;
}

.toggle-btn.active {
    background: #4a90d9;
    color: #fff;
}

.toggle-btn:hover:not(.active) {
    background: #f0f0f0;
}

/* Confidence filter */
#confidence-filter-label {
    font-size: 13px;
    color: #666;
    display: flex;
    align-items: center;
    gap: 4px;
}

#confidence-filter-label input {
    padding: 4px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 12px;
    text-align: center;
}

#result-count {
    font-size: 14px;
    color: #666;
    margin-right: 10px;
}

/* Main content: split panel */
#content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Results panel (right side in RTL) */
#results-panel {
    width: 380px;
    min-width: 300px;
    overflow-y: auto;
    background: #fff;
    border-left: 1px solid #ddd;
}

#results-list {
    padding: 0;
}

.result-item {
    padding: 14px 18px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background 0.15s;
}

.result-item:hover {
    background: #f0f7ff;
}

.result-item.active {
    background: #e3f0ff;
    border-right: 3px solid #4a90d9;
}

.result-text {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 2px;
}

.result-selected {
    font-size: 14px;
    color: #888;
    margin-bottom: 4px;
}

.result-doc-name {
    font-size: 11px;
    color: #4a90d9;
    font-weight: 600;
    margin-bottom: 2px;
    padding: 1px 6px;
    background: #e8f0fe;
    border-radius: 3px;
    display: inline-block;
}

.result-meta {
    font-size: 13px;
    color: #888;
    margin-bottom: 6px;
}

.result-context {
    font-size: 14px;
    color: #444;
    line-height: 1.6;
}

.result-context .match-word {
    background: rgba(255, 255, 0, 0.4);
    padding: 1px 3px;
    border-radius: 2px;
    font-weight: bold;
}

.result-match-info {
    font-size: 12px;
    color: #999;
    margin-top: 4px;
}

/* Page viewer (left side in RTL) */
#page-viewer {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #e8e8e8;
}

#viewer-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #fff;
    border-bottom: 1px solid #ddd;
}

#viewer-toolbar button {
    padding: 4px 12px;
    font-size: 18px;
    border: 1px solid #ccc;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
}

#viewer-toolbar button:hover {
    background: #eee;
}

#page-label {
    font-size: 14px;
    color: #666;
}

#image-container {
    position: relative;
    display: inline-block;
    direction: ltr;
}

#page-image {
    display: block;
    transform-origin: top left;
}

#page-canvas {
    display: block;
    transform-origin: top left;
}

#highlight-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.highlight-rect {
    fill: rgba(255, 255, 0, 0.35);
    stroke: rgba(255, 140, 0, 0.9);
    stroke-width: 3;
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #999;
    font-size: 18px;
}

/* Loading indicator */
.loading {
    text-align: center;
    padding: 40px;
    color: #888;
    font-size: 16px;
}

/* Resize handle */
.resize-handle {
    width: 4px;
    background: #ddd;
    cursor: col-resize;
}

.resize-handle:hover {
    background: #aaa;
}

/* Debug panel */
#viewer-and-debug {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#viewer-and-debug > #image-scroll-container {
    flex: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    padding: 20px;
}

#debug-panel {
    border-top: 2px solid #b0b0b0;
    background: #fafafa;
    max-height: 45%;
    overflow-y: auto;
    direction: rtl;
}

#debug-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 14px;
    background: #eee;
    border-bottom: 1px solid #ddd;
    position: sticky;
    top: 0;
    z-index: 1;
}

#debug-header .debug-view-toggle {
    margin: 0;
}

#debug-header > #debug-close {
    margin-inline-start: auto;
}

#debug-title {
    font-size: 13px;
    font-weight: bold;
    color: #555;
}

#debug-close {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: #888;
    padding: 2px 6px;
}

#debug-close:hover {
    color: #333;
}

#debug-content {
    padding: 10px 14px;
}

/* Line words row */
.debug-line-words {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    direction: rtl;
}

.debug-word-chip {
    padding: 6px 12px;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.15s;
    position: relative;
}

.debug-word-chip:hover {
    background: #e8f0fe;
    border-color: #4a90d9;
}

.debug-word-chip.selected {
    background: #d0e4ff;
    border-color: #4a90d9;
    box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.3);
}

.debug-word-chip .chip-conf {
    font-size: 10px;
    color: #999;
    display: block;
    text-align: center;
}

/* Alternatives table */
.debug-alts-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
    font-size: 14px;
    direction: rtl;
}

.debug-alts-table th {
    background: #e8e8e8;
    padding: 6px 10px;
    text-align: right;
    font-weight: 600;
    border: 1px solid #ddd;
    font-size: 13px;
    color: #555;
}

.debug-alts-table td {
    padding: 5px 10px;
    border: 1px solid #eee;
    text-align: right;
}

.debug-alts-table tr:hover {
    background: #f5f9ff;
}

.debug-alts-table .alt-best {
    font-weight: bold;
    background: #fffde7;
}

.debug-alts-table .alt-selected {
    background: #e8f5e9;
    border-right: 3px solid #4caf50;
}

.debug-line-table .alt-selected {
    background: #e8f5e9 !important;
}

/* Full line table view */
.debug-line-table-container {
    overflow-x: auto;
    margin-top: 10px;
}

.debug-line-table {
    border-collapse: collapse;
    font-size: 14px;
    direction: rtl;
    min-width: 100%;
}

.debug-line-table th {
    background: #e8f0fe;
    padding: 8px 10px;
    text-align: center;
    font-weight: bold;
    font-size: 16px;
    border: 1px solid #ccc;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s;
}

.debug-line-table th:hover {
    background: #d0e4ff;
}

.debug-line-table th.selected {
    background: #d0e4ff;
    box-shadow: inset 0 -3px 0 #4a90d9;
}

.debug-line-table td {
    padding: 4px 8px;
    border: 1px solid #e0e0e0;
    text-align: center;
    white-space: nowrap;
    vertical-align: top;
}

.debug-line-table td.alt-cell {
    font-size: 13px;
}

.debug-line-table .conf-badge {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 11px;
    margin-right: 4px;
}

.conf-high { background: #c8e6c9; color: #2e7d32; }
.conf-mid  { background: #fff9c4; color: #f57f17; }
.conf-low  { background: #ffcdd2; color: #c62828; }

/* Debug mode: make image clickable */
.debug-mode #highlight-overlay {
    pointer-events: auto;
    cursor: crosshair;
}

/* Line highlight in debug mode */
.debug-line-rect {
    fill: rgba(100, 149, 237, 0.15);
    stroke: rgba(100, 149, 237, 0.6);
    stroke-width: 1;
    cursor: pointer;
    transition: fill 0.15s;
}

.debug-line-rect:hover {
    fill: rgba(100, 149, 237, 0.3);
}

.debug-line-rect.active {
    fill: rgba(100, 149, 237, 0.25);
    stroke: rgba(30, 90, 200, 0.9);
    stroke-width: 2;
}

/* View toggle buttons */
.debug-view-toggle {
    display: flex;
    gap: 4px;
}

.debug-view-toggle button {
    padding: 3px 10px;
    font-size: 12px;
    border: 1px solid #ccc;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
}

.debug-view-toggle button.active {
    background: #4a90d9;
    color: #fff;
    border-color: #4a90d9;
}

/* Document selector */
#doc-selector {
    padding: 8px 12px;
    font-size: 14px;
    border: 1px solid #ccc;
    border-radius: 6px;
    background: #fff;
    font-family: inherit;
    max-width: 220px;
    cursor: pointer;
}

#doc-selector:focus {
    outline: none;
    border-color: #4a90d9;
}

/* Upload button in header */
#upload-btn {
    padding: 8px 16px;
    font-size: 14px;
    background: #5cb85c;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    margin-inline-start: auto;
}

#upload-btn:hover {
    background: #4cae4c;
}

/* Upload modal overlay */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: #fff;
    border-radius: 10px;
    padding: 30px;
    width: 440px;
    max-width: 90vw;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    direction: ltr;
}

.modal-content h2 {
    margin-bottom: 20px;
    font-size: 20px;
    color: #333;
}

.upload-field {
    display: block;
    margin-bottom: 16px;
    font-size: 14px;
    color: #555;
}

.upload-field input[type="file"],
.upload-field input[type="text"] {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

.upload-field input[type="text"]:focus {
    outline: none;
    border-color: #4a90d9;
}

#upload-progress {
    margin: 12px 0;
    background: #eee;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    height: 28px;
}

#upload-progress-bar {
    height: 100%;
    width: 0%;
    background: #4a90d9;
    transition: width 0.3s;
}

#upload-progress-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: #333;
}

#upload-error {
    color: #c62828;
    font-size: 13px;
    margin-bottom: 8px;
    padding: 8px;
    background: #ffebee;
    border-radius: 4px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-actions button {
    padding: 10px 24px;
    font-size: 15px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-family: inherit;
}

.modal-actions button[type="submit"] {
    background: #4a90d9;
    color: #fff;
}

.modal-actions button[type="submit"]:hover {
    background: #3a7bc8;
}

.modal-actions button[type="submit"]:disabled {
    background: #aaa;
    cursor: not-allowed;
}

.modal-actions button[type="button"] {
    background: #eee;
    color: #333;
}

.modal-actions button[type="button"]:hover {
    background: #ddd;
}

/* No-documents empty state */
#no-docs-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
}

.no-docs-card {
    text-align: center;
    padding: 50px 40px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.no-docs-card h2 {
    font-size: 22px;
    color: #555;
    margin-bottom: 10px;
}

.no-docs-card p {
    font-size: 15px;
    color: #888;
    margin-bottom: 24px;
}

.primary-btn {
    padding: 12px 32px;
    font-size: 16px;
    background: #4a90d9;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
}

.primary-btn:hover {
    background: #3a7bc8;
}

/* Match type badges for Hebrew search results */
.match-type-badge {
    display: inline-block;
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 3px;
    margin-inline-start: 6px;
    font-weight: 600;
    vertical-align: middle;
}

.match-type-normalized { background: #dcedc8; color: #558b2f; }
.match-type-prefix { background: #fff9c4; color: #f57f17; }
.match-type-variant { background: #ffe0b2; color: #e65100; }
.match-type-hebrew { background: #e1bee7; color: #6a1b9a; }
.match-type-morphological { background: #ffccbc; color: #bf360c; }
