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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
    min-height: 100vh;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.left-menu {
    width: 280px;
    background: #1f2937;
    color: #f9fafb;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.menu-brand h1 {
    font-size: 20px;
    margin-bottom: 4px;
}

.menu-brand p {
    color: #9ca3af;
    font-size: 13px;
}

.menu-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.menu-item {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.2);
    color: inherit;
    border-radius: 10px;
    padding: 16px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.menu-item .menu-title {
    font-weight: 600;
    font-size: 15px;
}

.menu-item .menu-caption {
    color: #9ca3af;
    font-size: 12px;
}

.menu-item.active,
.menu-item:hover {
    background: rgba(59,130,246,0.15);
    border-color: #3b82f6;
}

.feature-content {
    flex: 1;
    width: 100%;
    padding: 32px;
    overflow-y: auto;
}

.feature-section {
    display: none;
    animation: fadeIn 0.2s ease;
}

.feature-section.active {
    display: block;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 20px;
}

.section-header h2 {
    margin-bottom: 8px;
    color: #111827;
}

.section-header p {
    color: #6b7280;
    font-size: 14px;
}

.info-banner {
    background: #ecfdf5;
    border: 1px solid #6ee7b7;
    color: #065f46;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 13px;
    margin-bottom: 16px;
}

.btn-link {
    background: transparent;
    border: none;
    color: #2563eb;
    cursor: pointer;
    font-weight: 600;
}

.card {
    background: white;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 10px 20px rgba(15,23,42,0.06);
    border: 1px solid #e5e7eb;
}

.form-card {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    color: #1f2937;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    font-size: 14px;
}

.form-group small {
    display: block;
    margin-top: 6px;
    color: #6b7280;
    font-size: 12px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
}

.results-card.hidden {
    display: none;
}

.results-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.results-block {
    background: #f9fafb;
    border-radius: 12px;
    padding: 16px;
    border: 1px solid #e5e7eb;
}

.results-block h4 {
    margin-bottom: 8px;
    font-size: 14px;
    color: #111827;
}

.results-block ul {
    list-style: none;
    max-height: 200px;
    overflow-y: auto;
}

.results-block li {
    font-size: 12px;
    color: #374151;
    margin-bottom: 6px;
}

.results-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.summary-chip {
    background: #eef2ff;
    border-radius: 10px;
    padding: 12px;
    border: 1px solid #c7d2fe;
    text-align: center;
}

.summary-chip span {
    display: block;
    font-size: 12px;
    color: #4c1d95;
}

.summary-chip strong {
    font-size: 20px;
    color: #312e81;
}

.hidden {
    display: none !important;
}

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

.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 20px;
}

header {
    background: white;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

header h1 {
    font-size: 28px;
    margin-bottom: 5px;
    color: #2c3e50;
}

header p {
    color: #7f8c8d;
    font-size: 14px;
}

.main-content {
    display: flex;
    gap: 20px;
    height: calc(100vh - 180px);
    min-height: 700px;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.upload-section {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e0e0e0;
}

.upload-section h2 {
    font-size: 18px;
    margin-bottom: 15px;
    color: #2c3e50;
}

.upload-area {
    border: 2px dashed #bdc3c7;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    margin-bottom: 10px;
}

.upload-area:hover {
    border-color: #3498db;
    background: #f8f9fa;
}

.upload-area.dragover {
    border-color: #3498db;
    background: #e3f2fd;
}

.upload-placeholder svg {
    color: #95a5a6;
    margin-bottom: 10px;
}

.upload-placeholder p {
    color: #7f8c8d;
    font-size: 14px;
    margin: 5px 0;
}

.upload-hint {
    font-size: 12px;
    color: #95a5a6;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s;
}

.btn-primary {
    background: #3498db;
    color: white;
    width: 100%;
}

.btn-primary:hover:not(:disabled) {
    background: #2980b9;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #7f8c8d;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.image-list-section {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.image-list-section h2 {
    font-size: 18px;
    margin-bottom: 15px;
    color: #2c3e50;
}

.image-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.image-item {
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    background: #fafafa;
}

.image-item:hover {
    border-color: #3498db;
    background: #f0f7ff;
}

.image-item.active {
    border-color: #3498db;
    background: #e3f2fd;
}

.image-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.image-item-name {
    font-size: 13px;
    font-weight: 500;
    color: #2c3e50;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.image-item-badge {
    background: #27ae60;
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 8px;
}

.image-item-size {
    font-size: 11px;
    color: #7f8c8d;
}

.empty-state {
    text-align: center;
    color: #95a5a6;
    padding: 40px 20px;
    font-size: 14px;
}

/* Canvas Area */
.canvas-area {
    flex: 1;
    background: white;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.canvas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e0e0e0;
}

.canvas-header h2 {
    font-size: 20px;
    color: #2c3e50;
}

.canvas-controls {
    display: flex;
    gap: 8px;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: white;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-icon:hover:not(:disabled) {
    background: #f3f4f6;
    border-color: #9ca3af;
    color: #374151;
}

.btn-icon:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-icon-primary {
    background: #3498db;
    border-color: #3498db;
    color: white;
}

.btn-icon-primary:hover:not(:disabled) {
    background: #2980b9;
    border-color: #2980b9;
    color: white;
}

.btn-icon svg {
    display: block;
}

.canvas-container {
    flex: 1;
    position: relative;
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 600px;
    height: calc(100vh - 250px);
    padding: 10px;
}

.canvas-placeholder {
    text-align: center;
    color: #95a5a6;
    padding: 40px;
}

#displayImage {
    max-width: 98%;
    max-height: 98%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.image-stage {
    position: relative;
    display: inline-block;
    max-width: 100%;
    max-height: 100%;
}

.image-stage img {
    display: block;
    max-width: 100%;
    max-height: 100%;
}

.bbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 2;
}

.bbox-rect {
    position: absolute;
    border: 2px solid rgba(39, 174, 96, 0.8);
    background: rgba(39, 174, 96, 0.15);
    border-radius: 4px;
    pointer-events: auto;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.bbox-rect:hover,
.bbox-rect:focus-visible {
    border-color: #1e8449;
    background: rgba(30, 132, 73, 0.2);
}

.bbox-rect.highlight-same-ayah {
    border-color: #1e8449 !important;
    background: rgba(30, 132, 73, 0.3) !important;
    z-index: 10;
}

.bbox-rect:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(39, 174, 96, 0.3);
}

.bbox-tooltip {
    position: absolute;
    left: 0;
    top: 0;
    transform: translateY(calc(-100% - 6px));
    background: rgba(17, 24, 39, 0.85);
    color: #fff;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: normal;
    max-width: 300px;
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
    z-index: 1000;
}

.bbox-tooltip ul {
    margin: 4px 0;
    padding-left: 20px;
    font-size: 11px;
}

.bbox-tooltip li {
    margin: 2px 0;
}

.bbox-rect:hover .bbox-tooltip,
.bbox-rect:focus-visible .bbox-tooltip {
    opacity: 1;
}

.loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px;
    color: #7f8c8d;
}

.loading-indicator p {
    margin: 0;
    font-size: 14px;
}

.bbox-info-section {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
    max-height: 180px;
    overflow-y: auto;
}

.bbox-info-section h3 {
    font-size: 16px;
    margin-bottom: 15px;
    color: #2c3e50;
}

.bbox-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bbox-item {
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 12px;
    font-size: 13px;
}

.bbox-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.bbox-item-id {
    font-weight: 600;
    color: #2c3e50;
}

.bbox-confidence {
    font-size: 11px;
    color: #27ae60;
    font-weight: 500;
}

.bbox-item-props {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    font-size: 12px;
}

.bbox-prop {
    display: flex;
    justify-content: space-between;
}

.bbox-prop-label {
    color: #7f8c8d;
}

.bbox-prop-value {
    font-weight: 500;
    color: #2c3e50;
}

/* Scrollbar styling */
.image-list::-webkit-scrollbar,
.bbox-info-section::-webkit-scrollbar,
.canvas-container::-webkit-scrollbar {
    width: 8px;
}

.image-list::-webkit-scrollbar-track,
.bbox-info-section::-webkit-scrollbar-track,
.canvas-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.image-list::-webkit-scrollbar-thumb,
.bbox-info-section::-webkit-scrollbar-thumb,
.canvas-container::-webkit-scrollbar-thumb {
    background: #bdc3c7;
    border-radius: 4px;
}

.image-list::-webkit-scrollbar-thumb:hover,
.bbox-info-section::-webkit-scrollbar-thumb:hover,
.canvas-container::-webkit-scrollbar-thumb:hover {
    background: #95a5a6;
}

/* Loading indicator */
.loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Full-screen loading overlay */
#fullScreenLoadingOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 10000;
    color: white;
    font-size: 16px;
}

#fullScreenLoadingOverlay .loading {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

#fullScreenLoadingMessage {
    text-align: center;
    font-weight: 500;
}

/* Modal styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #e5e7eb;
}

.modal-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: #111827;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    color: #6b7280;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: #f3f4f6;
    color: #111827;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 20px 24px;
    border-top: 1px solid #e5e7eb;
}

.modal-image-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 400px;
    overflow-y: auto;
}

.modal-image-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.modal-image-item:hover {
    background: #f9fafb;
    border-color: #d1d5db;
}

.modal-image-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #3b82f6;
}

.modal-image-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.modal-image-item-name {
    font-weight: 500;
    color: #111827;
    font-size: 14px;
}

.modal-image-item-details {
    font-size: 12px;
    color: #6b7280;
}

.modal-image-item-badge {
    display: inline-block;
    background: #dbeafe;
    color: #1e40af;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    margin-left: 8px;
}

.btn-danger {
    background: #ef4444;
    color: white;
    border: none;
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

.btn-danger:disabled {
    background: #fca5a5;
    cursor: not-allowed;
    opacity: 0.6;
}

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

