/* ============================================================
   meDDI OCR Labeling Tool — Styles
   ============================================================ */

:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: #1a2235;
    --bg-card-hover: #1e2a42;
    --bg-input: #0f1729;
    --bg-glass: rgba(26, 34, 53, 0.85);

    --text-primary: #f0f4ff;
    --text-secondary: #8b9cc7;
    --text-muted: #5a6a8a;

    --accent: #6366f1;
    --accent-light: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.25);

    --green: #10b981;
    --green-bg: rgba(16, 185, 129, 0.12);
    --yellow: #f59e0b;
    --yellow-bg: rgba(245, 158, 11, 0.12);
    --red: #ef4444;
    --red-bg: rgba(239, 68, 68, 0.12);
    --gray: #6b7280;
    --gray-bg: rgba(107, 114, 128, 0.12);

    --border: rgba(139, 156, 199, 0.1);
    --border-focus: rgba(99, 102, 241, 0.5);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 30px var(--accent-glow);

    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    font-size: 15px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ---- Header ---- */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1.5rem;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.logo {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.logo-accent {
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
}

.header-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.breadcrumb a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition);
}

.breadcrumb a:hover { color: var(--accent-light); }

.breadcrumb .sep {
    color: var(--text-muted);
    font-size: 0.7rem;
}

.breadcrumb .current {
    color: var(--text-primary);
    font-weight: 500;
}

/* ---- Main Content ---- */
#main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* ---- Dashboard ---- */
.dashboard-header {
    text-align: center;
    margin-bottom: 2rem;
}

.dashboard-header h2 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-light));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.dashboard-header p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Overall Progress */
.overall-progress {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.progress-bar-container {
    position: relative;
    height: 12px;
    background: var(--bg-input);
    border-radius: 6px;
    overflow: hidden;
    margin: 1rem 0;
}

.progress-bar {
    height: 100%;
    border-radius: 6px;
    transition: width 0.5s ease;
    background: linear-gradient(90deg, var(--accent), var(--green));
}

.progress-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.progress-stats .highlight {
    color: var(--text-primary);
    font-weight: 600;
}

/* Reviewer Cards */
.reviewer-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.2rem;
    margin-bottom: 2rem;
}

.reviewer-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}

.reviewer-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
    opacity: 0;
    transition: opacity var(--transition);
}

.reviewer-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent-glow);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.reviewer-card:hover::before { opacity: 1; }

.reviewer-card .card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.reviewer-card .reviewer-name {
    font-size: 1.1rem;
    font-weight: 600;
}

.reviewer-card .reviewer-badge {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    background: var(--accent-glow);
    color: var(--accent-light);
}

.card-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-top: 1rem;
}

.stat-item {
    text-align: center;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    background: var(--bg-input);
}

.stat-item .stat-value {
    font-size: 1.2rem;
    font-weight: 700;
}

.stat-item .stat-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-item.completed .stat-value { color: var(--green); }
.stat-item.pending .stat-value { color: var(--yellow); }
.stat-item.skipped .stat-value { color: var(--gray); }

/* ---- Image Grid ---- */
.grid-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.2rem;
    flex-wrap: wrap;
    gap: 0.8rem;
}

.grid-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
}

.grid-filters {
    display: flex;
    gap: 0.5rem;
}

.filter-btn {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.filter-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.filter-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
}

.image-card {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg-card);
}

.image-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent-glow);
}

.image-card img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    display: block;
}

.image-card .card-info {
    padding: 0.5rem 0.6rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.75rem;
}

.image-card .image-id {
    color: var(--text-secondary);
    font-weight: 500;
}

.status-badge {
    padding: 0.15rem 0.5rem;
    border-radius: 20px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.status-badge.pending { background: var(--yellow-bg); color: var(--yellow); }
.status-badge.completed { background: var(--green-bg); color: var(--green); }
.status-badge.skipped { background: var(--gray-bg); color: var(--gray); }

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

.pagination button {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
}

.pagination button:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--text-primary);
}

.pagination button:disabled { opacity: 0.3; cursor: not-allowed; }

.pagination .page-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 0 0.5rem;
}

/* ---- Editor ---- */
.editor-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.2rem;
    height: calc(100vh - 80px);
}

.editor-image-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.editor-image-panel .panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.panel-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.image-container {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: var(--bg-input);
}

/* Normal view: wrapper fills container, image uses object-fit: contain */
.image-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease-in-out;
}

.image-wrapper img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--radius-sm);
    cursor: zoom-in;
    transition: all 0.3s ease-in-out;
}

.image-container.zoomed {
    align-items: flex-start;
    justify-content: flex-start;
    cursor: grab;
}

.image-container.zoomed:active {
    cursor: grabbing;
}

/* Zoomed view: wrapper becomes inline-block so overlay matches image 1:1 */
.image-container.zoomed .image-wrapper {
    width: auto;
    height: auto;
    display: inline-block;
    line-height: 0;
}

.image-container.zoomed .image-wrapper img {
    max-width: none;
    max-height: none;
    object-fit: unset;
    cursor: zoom-out;
}

/* Disable transitions during cropping to avoid interference with Cropper.js */
.image-container.cropping-active .image-wrapper,
.image-container.cropping-active .image-wrapper img,
.cropper-container * {
    transition: none !important;
}

/* BBox Overlay — always matches the wrapper (= the image) */
.bbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.bbox-rect {
    position: absolute;
    border: 2px solid rgba(0, 200, 255, 0.7);
    background: rgba(0, 200, 255, 0.08);
    cursor: move;
    pointer-events: all;
    transition: border-color 0.15s;
    z-index: 6;
}

.bbox-rect:hover {
    border-color: rgba(255, 200, 0, 0.9);
    background: rgba(255, 200, 0, 0.1);
}

.bbox-label {
    position: absolute;
    top: -20px;
    left: 0;
    background: rgba(0, 200, 255, 0.85);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 3px;
    white-space: nowrap;
    pointer-events: none;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.bbox-rect:hover .bbox-label {
    background: rgba(255, 200, 0, 0.9);
    color: #000;
}

.bbox-handle {
    position: absolute;
    bottom: -4px;
    right: -4px;
    width: 10px;
    height: 10px;
    background: rgba(0, 200, 255, 0.9);
    border-radius: 2px;
    cursor: nwse-resize;
    pointer-events: all;
}

.bbox-rect:hover .bbox-handle {
    background: rgba(255, 200, 0, 0.95);
}

/* Small button variant */
.btn-sm {
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
}

#imageActionsNormal, #imageActionsCrop {
    display: flex;
    align-items: center;
    gap: 6px;
}

.editor-form-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.editor-form-panel .panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.form-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* Form Fields */
.form-section {
    margin-bottom: 1.2rem;
}

.form-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent-light);
    margin-bottom: 0.6rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.form-section-title::before {
    content: '';
    width: 3px;
    height: 12px;
    background: var(--accent);
    border-radius: 2px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
    margin-bottom: 0.6rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.form-group input,
.form-group textarea,
.form-group select {
    padding: 0.45rem 0.6rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
    transition: border-color var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group textarea {
    resize: vertical;
    min-height: 50px;
}

/* Medicine List */
.medicine-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.medicine-item {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.8rem;
    position: relative;
}

.medicine-item .med-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.medicine-item .med-number {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--accent-light);
}

.medicine-item .med-remove {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--red-bg);
    color: var(--red);
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all var(--transition);
}

.medicine-item .med-remove:hover {
    background: var(--red);
    color: white;
}

.medicine-item .med-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.medicine-item .med-raw {
    grid-column: 1 / -1;
}

.add-medicine-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    padding: 0.5rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
}

.add-medicine-btn:hover {
    border-color: var(--accent);
    color: var(--accent-light);
}

/* Action Bar */
.action-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    gap: 0.5rem;
}

.action-bar .nav-actions {
    display: flex;
    gap: 0.4rem;
}

.action-bar .main-actions {
    display: flex;
    gap: 0.4rem;
}

.btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover { color: var(--text-primary); border-color: var(--text-secondary); }

.btn-primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.btn-primary:hover { background: var(--accent-light); }

.btn-success {
    background: var(--green);
    color: white;
    border-color: var(--green);
}

.btn-success:hover { background: #059669; }

.btn-warning {
    background: transparent;
    color: var(--yellow);
    border-color: var(--yellow);
}

.btn-warning:hover { background: var(--yellow-bg); }

.btn-danger {
    background: transparent;
    color: var(--red);
    border-color: var(--red);
}

.btn-danger:hover { background: var(--red-bg); }

/* Keyboard hint */
.kbd {
    display: inline-flex;
    align-items: center;
    padding: 0.1rem 0.3rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 0.65rem;
    color: var(--text-muted);
    font-family: monospace;
    margin-left: 0.3rem;
}

/* Loading / Empty */
.loading, .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--text-secondary);
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty-state .empty-icon {
    font-size: 2.5rem;
    margin-bottom: 0.8rem;
    opacity: 0.5;
}

/* Toast / Notification */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    padding: 0.8rem 1.2rem;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 1000;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    backdrop-filter: blur(12px);
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success { background: var(--green-bg); color: var(--green); border: 1px solid rgba(16,185,129,0.3); }
.toast.error { background: var(--red-bg); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
.toast.info { background: rgba(99,102,241,0.12); color: var(--accent-light); border: 1px solid rgba(99,102,241,0.3); }

/* ---- Header User / Sign Out ---- */
.header-user {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
}

.header-user-name {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
}

/* ---- Login Screen ---- */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 60px);
    padding: 2rem 1rem;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header .logo {
    font-size: 2rem;
    font-weight: 800;
    display: block;
    margin-bottom: 0.4rem;
}

.login-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.login-error {
    margin-top: 0.8rem;
    padding: 0.55rem 0.8rem;
    background: var(--red-bg);
    color: var(--red);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
}

.login-btn {
    width: 100%;
    justify-content: center;
    margin-top: 1.2rem;
    padding: 0.65rem 1rem;
    font-size: 0.9rem;
}

/* ---- Responsive ---- */
@media (max-width: 1200px) {
    .editor-layout {
        grid-template-columns: 1fr;
        height: auto;
    }
    .editor-image-panel {
        height: 45vh;
    }
}

@media (max-width: 768px) {
    .reviewer-cards {
        grid-template-columns: 1fr;
    }
    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
    #main-content {
        padding: 1rem;
    }
}
