/* ============================================================
   GLOBAL
============================================================ */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-main: #f4f6f8;
    --bg-panel: #ffffff;
    --bg-toolbar: #ffffff;
    --border: #e1e5e9;

    --text-main: #1f2937;
    --text-secondary: #6b7280;
    --text-light: #9ca3af;

    --primary: #2563eb;
    --primary-hover: #1d4ed8;

    --danger: #dc2626;
    --danger-hover: #b91c1c;

    --canvas-bg: #e9edf1;

    --shadow: 0 2px 10px rgba(0, 0, 0, 0.06);

    --radius: 8px;
}

html,
body {
    width: 100%;
    height: 100%;
}

body {
    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        Arial,
        sans-serif;

    background: var(--bg-main);
    color: var(--text-main);

    overflow: hidden;
}


/* ============================================================
   APP
============================================================ */

.app {
    width: 100%;
    height: 100vh;

    display: flex;
    flex-direction: column;
}


/* ============================================================
   TOP BAR
============================================================ */

.topbar {
    height: 64px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 0 18px;

    background: var(--bg-panel);

    border-bottom: 1px solid var(--border);

    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 34px;
    height: 34px;

    display: flex;
    align-items: center;
    justify-content: center;

    background: var(--primary);
    color: white;

    border-radius: 7px;

    font-size: 19px;
    font-weight: 700;
}

.brand-text h1 {
    font-size: 15px;
    font-weight: 650;
}

.brand-text span {
    display: block;

    margin-top: 2px;

    color: var(--text-secondary);

    font-size: 11px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 7px;
}

.divider {
    width: 1px;
    height: 28px;

    background: var(--border);

    margin: 0 5px;
}


/* ============================================================
   BUTTONS
============================================================ */

button {
    font-family: inherit;
    cursor: pointer;
}

.primary-btn,
.secondary-btn,
.danger-btn {
    height: 36px;

    padding: 0 14px;

    border-radius: 7px;

    font-size: 13px;
    font-weight: 600;

    transition:
        background 0.15s ease,
        border-color 0.15s ease,
        transform 0.1s ease;
}

.primary-btn {
    border: 1px solid var(--primary);

    background: var(--primary);
    color: white;
}

.primary-btn:hover {
    background: var(--primary-hover);
}

.secondary-btn {
    border: 1px solid var(--border);

    background: white;
    color: var(--text-main);
}

.secondary-btn:hover {
    background: #f8fafc;
}

.danger-btn {
    border: 1px solid #fecaca;

    background: #fff;
    color: var(--danger);
}

.danger-btn:hover {
    background: #fef2f2;
}

.primary-btn.large {
    height: 42px;
    padding: 0 22px;
}

.full-width {
    width: 100%;
}

.icon-btn {
    width: 34px;
    height: 34px;

    display: flex;
    align-items: center;
    justify-content: center;

    border: 1px solid var(--border);

    background: white;
    color: var(--text-main);

    border-radius: 7px;

    font-size: 19px;
}

.icon-btn:hover:not(:disabled) {
    background: #f8fafc;
}

button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}


/* ============================================================
   MAIN WORKSPACE
============================================================ */

.workspace {
    flex: 1;

    min-height: 0;

    display: flex;
}


/* ============================================================
   LEFT TOOLBAR
============================================================ */

.left-toolbar {
    width: 68px;

    display: flex;
    flex-direction: column;
    align-items: center;

    gap: 4px;

    padding: 10px 7px;

    background: var(--bg-toolbar);

    border-right: 1px solid var(--border);

    flex-shrink: 0;
}

.tool-btn {
    width: 54px;
    height: 54px;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    gap: 3px;

    border: none;

    background: transparent;
    color: var(--text-secondary);

    border-radius: 8px;

    transition:
        background 0.15s ease,
        color 0.15s ease;
}

.tool-btn span {
    font-size: 18px;
    line-height: 18px;
}

.tool-btn small {
    font-size: 9px;
}

.tool-btn:hover {
    background: #f1f5f9;
    color: var(--text-main);
}

.tool-btn.active {
    background: #eff6ff;
    color: var(--primary);
}

.toolbar-spacer {
    flex: 1;
}


/* ============================================================
   CANVAS AREA
============================================================ */

.canvas-area {
    flex: 1;

    min-width: 0;
    min-height: 0;

    display: flex;
    flex-direction: column;
}

.drop-zone {
    position: relative;

    flex: 1;

    min-height: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    background:
        linear-gradient(
            45deg,
            #e5e7eb 25%,
            transparent 25%
        ),
        linear-gradient(
            -45deg,
            #e5e7eb 25%,
            transparent 25%
        ),
        linear-gradient(
            45deg,
            transparent 75%,
            #e5e7eb 75%
        ),
        linear-gradient(
            -45deg,
            transparent 75%,
            #e5e7eb 75%
        );

    background-size: 20px 20px;

    background-position:
        0 0,
        0 10px,
        10px -10px,
        -10px 0;
}

.drop-zone.dragover {
    outline: 3px solid rgba(37, 99, 235, 0.25);
    outline-offset: -5px;
}


/* ============================================================
   EMPTY STATE
============================================================ */

.empty-state {
    text-align: center;

    color: var(--text-secondary);
}

.upload-icon {
    width: 64px;
    height: 64px;

    display: flex;
    align-items: center;
    justify-content: center;

    margin: 0 auto 18px;

    border-radius: 14px;

    background: white;

    box-shadow: var(--shadow);

    color: var(--primary);

    font-size: 30px;
}

.empty-state h2 {
    margin-bottom: 6px;

    color: var(--text-main);

    font-size: 19px;
}

.empty-state p {
    margin-bottom: 18px;

    font-size: 13px;
}

.supported {
    display: block;

    margin-top: 12px;

    font-size: 11px;
    color: var(--text-light);
}


/* ============================================================
   CANVAS
============================================================ */

.canvas-wrapper {
    position: relative;

    max-width: 95%;
    max-height: 92%;

    display: flex;
    align-items: center;
    justify-content: center;

    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

#editorCanvas {
    display: block;

    max-width: 100%;
    max-height: 100%;

    background: white;
}

.text-layer-container {
    position: absolute;

    inset: 0;

    pointer-events: none;
}


/* ============================================================
   OCR TEXT BOX
============================================================ */

.ocr-box {
    position: absolute;

    border: 1px dashed var(--primary);

    background: rgba(37, 99, 235, 0.08);

    pointer-events: auto;

    cursor: pointer;

    transition:
        background 0.15s ease,
        border-color 0.15s ease;
}

.ocr-box:hover,
.ocr-box.selected {
    background: rgba(37, 99, 235, 0.15);

    border: 2px solid var(--primary);
}


/* ============================================================
   STATUS BAR
============================================================ */

.statusbar {
    height: 34px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 0 12px;

    background: white;

    border-top: 1px solid var(--border);

    font-size: 11px;

    color: var(--text-secondary);

    flex-shrink: 0;
}

.status-center {
    color: var(--primary);
}

.zoom-display {
    border: none;
    background: transparent;

    color: var(--text-secondary);

    font-size: 11px;
}


/* ============================================================
   RIGHT SIDEBAR
============================================================ */

.right-sidebar {
    width: 285px;

    overflow-y: auto;

    background: white;

    border-left: 1px solid var(--border);

    flex-shrink: 0;
}

.panel {
    border-bottom: 1px solid var(--border);
}

.panel-header {
    height: 44px;

    display: flex;
    align-items: center;

    padding: 0 15px;

    border-bottom: 1px solid #f0f2f4;
}

.panel-header h3 {
    font-size: 13px;
    font-weight: 650;
}

.panel-content {
    padding: 13px 15px;
}

.panel-description {
    margin-bottom: 12px;

    color: var(--text-secondary);

    font-size: 11px;
    line-height: 1.5;
}


/* ============================================================
   FORM CONTROLS
============================================================ */

label {
    display: block;

    margin-bottom: 6px;

    color: var(--text-secondary);

    font-size: 11px;
    font-weight: 600;
}

input,
textarea,
select {
    width: 100%;

    margin-bottom: 12px;

    border: 1px solid var(--border);

    border-radius: 6px;

    background: white;

    color: var(--text-main);

    font-family: inherit;
    font-size: 12px;

    outline: none;
}

input,
select {
    height: 34px;

    padding: 0 9px;
}

textarea {
    padding: 8px;

    resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary);

    box-shadow:
        0 0 0 2px rgba(37, 99, 235, 0.08);
}

.two-columns {
    display: grid;

    grid-template-columns: 1fr 1fr;

    gap: 10px;
}

.color-control {
    display: flex;
    align-items: center;

    gap: 8px;

    margin-bottom: 12px;
}

.color-control input {
    width: 40px;

    padding: 2px;

    margin: 0;
}

#colorValue {
    font-family: monospace;

    color: var(--text-secondary);

    font-size: 11px;
}


/* ============================================================
   FORMAT BUTTONS
============================================================ */

.format-buttons {
    display: flex;

    gap: 4px;

    margin-bottom: 14px;
}

.format-btn {
    width: 34px;
    height: 32px;

    border: 1px solid var(--border);

    border-radius: 5px;

    background: white;

    color: var(--text-secondary);

    font-size: 12px;
}

.format-btn:hover {
    background: #f8fafc;
}

.format-btn.active {
    background: #eff6ff;

    border-color: #bfdbfe;

    color: var(--primary);
}


/* ============================================================
   OCR PROGRESS
============================================================ */

.progress-container {
    margin-top: 12px;
}

.progress-bar {
    width: 100%;
    height: 5px;

    overflow: hidden;

    border-radius: 5px;

    background: #e5e7eb;
}

.progress {
    width: 0;
    height: 100%;

    background: var(--primary);

    transition: width 0.2s ease;
}

#ocrProgressText {
    display: block;

    margin-top: 6px;

    font-size: 10px;

    color: var(--text-secondary);
}


/* ============================================================
   DETECTED TEXT
============================================================ */

.detected-list {
    margin-top: 12px;
}

.detected-item {
    padding: 8px;

    margin-bottom: 6px;

    border: 1px solid var(--border);

    border-radius: 6px;

    cursor: pointer;

    background: #fff;

    font-size: 11px;

    transition: background 0.15s ease;
}

.detected-item:hover {
    background: #f8fafc;
}

.detected-item strong {
    display: block;

    margin-bottom: 3px;

    font-size: 11px;
}

.detected-item span {
    color: var(--text-secondary);
}


/* ============================================================
   UTILITY
============================================================ */

.hidden {
    display: none !important;
}


/* ============================================================
   RESPONSIVE
============================================================ */

@media (max-width: 900px) {

    .right-sidebar {
        width: 250px;
    }

    .brand-text span {
        display: none;
    }
}

@media (max-width: 720px) {

    .right-sidebar {
        display: none;
    }

    .left-toolbar {
        width: 58px;
    }

    .tool-btn {
        width: 46px;
    }

    .brand-text {
        display: none;
    }
}

/* ============================================================
   OCR ACTIONS
============================================================ */

.ocr-actions {
    display: flex;
    flex-direction: column;
    gap: 7px;
}


/* ============================================================
   OCR AREA SELECTION
============================================================ */

.selection-hint {
    margin-top: 10px;
    padding: 8px;

    border-radius: 6px;

    background: #eff6ff;

    color: #1d4ed8;

    font-size: 10px;

    line-height: 1.4;

    text-align: center;
}


/* ============================================================
   OCR SELECTION RECTANGLE
============================================================ */

.ocr-selection-rectangle {
    position: absolute;

    border: 2px solid #2563eb;

    background: rgba(37, 99, 235, 0.12);

    pointer-events: none;

    z-index: 100;

    box-shadow:
        0 0 0 1px
        rgba(255, 255, 255, 0.8);
}