/* ── Reset & Base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 13px;
    color: #333;
    background: #f0f0f0;
}

/* ── Toolbar ────────────────────────────────────────────── */
#toolbar {
    position: fixed; top: 0; left: 0; right: 0;
    height: 42px;
    display: flex; align-items: center;
    padding: 0 8px;
    background: #2c2c2c;
    color: #eee;
    z-index: 100;
    gap: 2px;
    user-select: none;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.toolbar-group {
    display: flex; align-items: center; gap: 2px;
}

.toolbar-separator {
    width: 1px; height: 26px;
    background: #555;
    margin: 0 6px;
}

.toolbar-spacer { flex: 1; }

.toolbar-label {
    font-size: 11px;
    color: #aaa;
    padding: 0 4px;
    min-width: 20px;
    text-align: center;
}

.tool-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 4px;
    height: 32px; min-width: 32px;
    padding: 0 6px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: #ccc;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.15s, border-color 0.15s;
}

.tool-btn:hover {
    background: #444;
    border-color: #555;
    color: #fff;
}

.tool-btn.active {
    background: #0078d4;
    border-color: #005a9e;
    color: #fff;
}

.tool-btn.btn-primary {
    background: #0078d4;
    color: #fff;
}

.tool-btn.btn-primary:hover {
    background: #005a9e;
}

/* ── Canvas ─────────────────────────────────────────────── */
#canvas-container {
    position: fixed;
    top: 42px; left: 0; right: 0; bottom: 22px;
    overflow: hidden;
    background: #e8e8e8;
}

#canvas-container .canvas-container {
    width: 100% !important;
    height: 100% !important;
}

/* ── Status Bar ─────────────────────────────────────────── */
#statusbar {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: 22px;
    display: flex; align-items: center;
    padding: 0 10px;
    background: #2c2c2c;
    color: #999;
    font-size: 11px;
    gap: 16px;
    z-index: 100;
}

#status-mode {
    color: #6fc3df;
    font-weight: 600;
}

#status-version {
    margin-left: auto;
    color: #666;
}

/* ── Modals ─────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 200;
}

.modal-overlay.hidden { display: none; }

.modal {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    max-width: 800px;
    width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
}

.modal.modal-sm {
    max-width: 400px;
}

.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #e0e0e0;
}

.modal-header h3 {
    font-size: 15px;
    font-weight: 600;
}

.modal-close-btn {
    background: none; border: none;
    font-size: 22px; color: #888;
    cursor: pointer; line-height: 1;
    padding: 0 4px;
}

.modal-close-btn:hover { color: #333; }

.modal-body {
    padding: 16px;
}

.modal-actions {
    display: flex; gap: 8px; justify-content: flex-end;
    margin-top: 12px;
}

.step-label {
    font-weight: 600;
    margin-bottom: 8px;
    color: #555;
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 6px 16px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #f5f5f5;
    cursor: pointer;
    font-size: 13px;
    color: #333;
    transition: background 0.15s;
}

.btn:hover { background: #e5e5e5; }

.btn.btn-primary {
    background: #0078d4;
    border-color: #005a9e;
    color: #fff;
}

.btn.btn-primary:hover { background: #005a9e; }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.hidden { display: none !important; }

/* ── Crop Container ─────────────────────────────────────── */
#crop-container {
    max-height: 55vh;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin: 0 20px 10px;
    padding: 0;
    position: relative;
    cursor: crosshair;
}

#crop-container canvas {
    display: block;
}

/* Ensure crop modal is tall enough */
#pin-config-modal {
    max-height: 92vh;
}

/* ── Pin Canvas ─────────────────────────────────────────── */
#pin-canvas-container {
    width: 100%;
    max-height: 500px;
    overflow: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #f8f8f8;
    cursor: crosshair;
}

#pin-canvas-container canvas {
    display: block;
}

/* ── Pin Row Form ───────────────────────────────────────── */
.pin-row-form {
    display: flex; align-items: center; gap: 10px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.pin-row-form label {
    font-size: 13px;
}

.pin-row-form input[type="number"] {
    width: 60px;
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 13px;
}

#pin-rows-list {
    margin-top: 8px;
}

.pin-row-item {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 8px;
    background: #eef6ff;
    border-radius: 3px;
    margin-bottom: 4px;
    font-size: 12px;
}

.pin-row-item .remove-row {
    cursor: pointer;
    color: #c00;
    font-weight: bold;
    margin-left: auto;
}

/* ── Pin Preview ────────────────────────────────────────── */
#pin-preview-container {
    margin-top: 12px;
}

#pin-preview-canvas {
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
}

/* ── Color Picker Modal ─────────────────────────────────── */
#color-swatches {
    display: flex; flex-wrap: wrap; gap: 6px;
    margin-bottom: 12px;
}

.color-swatch-btn {
    width: 28px; height: 28px;
    border-radius: 4px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
}

.color-swatch-btn:hover { transform: scale(1.15); }

.color-swatch-btn.selected {
    border-color: #0078d4;
    box-shadow: 0 0 0 2px rgba(0,120,212,0.3);
}

#color-wheel-container {
    display: flex; gap: 8px;
    margin-bottom: 12px;
    justify-content: center;
}

#color-wheel { cursor: crosshair; border-radius: 4px; }
#color-brightness { cursor: ns-resize; border-radius: 4px; }

#color-hex-row {
    display: flex; align-items: center; gap: 10px;
}

#color-hex-row label {
    display: flex; align-items: center; gap: 6px;
}

#color-hex-input {
    width: 80px;
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 13px;
    font-family: monospace;
}

#color-preview-box {
    width: 32px; height: 32px;
    border-radius: 4px;
    border: 1px solid #ccc;
}

/* ── Export Modal ────────────────────────────────────────── */
#export-modal .modal-body label {
    display: flex; align-items: center; gap: 8px;
}

#export-multiplier {
    padding: 4px 8px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 13px;
}

/* ── Info Modal ─────────────────────────────────────────── */
.shortcuts-body { padding: 8px 16px 16px; }

.about-section {
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid #ddd;
}

.about-subtitle {
    font-size: 12px;
    color: #888;
    letter-spacing: 0.5px;
    margin: 0 0 8px;
}

.about-text {
    font-size: 13px;
    color: #555;
    margin: 0 0 6px;
    line-height: 1.5;
}

.shortcuts-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.shortcuts-table th {
    text-align: left;
    font-size: 12px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 10px 0 4px;
    border-bottom: 1px solid #e0e0e0;
}

.shortcuts-table td {
    padding: 4px 8px 4px 0;
    vertical-align: middle;
}

.shortcuts-table td:first-child {
    white-space: nowrap;
    width: 140px;
}

kbd {
    display: inline-block;
    padding: 2px 6px;
    font-size: 11px;
    font-family: monospace;
    background: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 3px;
    box-shadow: 0 1px 0 #bbb;
    min-width: 20px;
    text-align: center;
}

/* ── Dark Mode for Dialogs ──────────────────────────────── */
body.dark-mode .modal {
    background: #2c2c2c;
    color: #ddd;
}

body.dark-mode .modal-header {
    border-bottom-color: #444;
}

body.dark-mode .modal-header h3 { color: #eee; }
body.dark-mode .modal-close-btn { color: #888; }
body.dark-mode .modal-close-btn:hover { color: #ddd; }

body.dark-mode .step-label { color: #aaa; }

body.dark-mode .btn {
    background: #3c3c3c;
    border-color: #555;
    color: #ddd;
}
body.dark-mode .btn:hover { background: #4a4a4a; }
body.dark-mode .btn.btn-primary { background: #0078d4; border-color: #005a9e; color: #fff; }
body.dark-mode .btn.btn-primary:hover { background: #005a9e; }

body.dark-mode input[type="number"],
body.dark-mode input[type="text"],
body.dark-mode select {
    background: #3c3c3c;
    border-color: #555;
    color: #ddd;
}

body.dark-mode #crop-container,
body.dark-mode #pin-canvas-container {
    background: #333;
    border-color: #555;
}

body.dark-mode #pin-preview-canvas { background: #333; }

body.dark-mode .pin-row-item { background: #3a4050; color: #ccc; }

body.dark-mode kbd {
    background: #3c3c3c;
    border-color: #555;
    box-shadow: 0 1px 0 #444;
    color: #ddd;
}

body.dark-mode .shortcuts-table th { color: #777; border-bottom-color: #444; }
body.dark-mode .about-section { border-bottom-color: #444; }
body.dark-mode .about-subtitle { color: #666; }
body.dark-mode .about-text { color: #aaa; }

body.dark-mode #color-hex-input { background: #3c3c3c; border-color: #555; color: #ddd; }
body.dark-mode #color-preview-box { border-color: #555; }

body.dark-mode #statusbar { background: #1e1e1e; }

/* ── Fabric canvas overrides ────────────────────────────── */
.upper-canvas {
    cursor: default !important;
}
