/* Segment Editor Styles */
.segment-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.segment-modal-backdrop.active {
    opacity: 1;
    visibility: visible;
}

.segment-modal-window {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background: var(--bg-body, #0f172a);
    color: var(--text-primary, #f8fafc);
    position: relative;
    overflow: hidden;
}

/* Light theme overrides */
body.light-theme .segment-modal-window,
html[data-theme="light"] .segment-modal-window {
    background: #f8fafc;
    color: #0f172a;
}

.segment-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--term-card-bg, #1e293b);
    border-bottom: 1px solid var(--term-border, #334155);
    gap: 16px;
    flex-wrap: wrap;
    z-index: 10;
}

body.light-theme .segment-editor-header,
html[data-theme="light"] .segment-editor-header {
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
}

.segment-header-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.segment-header-title {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.segment-header-desc {
    font-size: 12.5px;
    color: var(--text-secondary, #94a3b8);
    margin: 0;
}

.segment-counter-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 6px;
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.35);
    color: #10b981;
    font-weight: 600;
    font-size: 13px;
    font-family: 'JetBrains Mono', monospace;
}

.segment-counter-badge.empty {
    background: rgba(100, 116, 139, 0.15);
    border-color: rgba(100, 116, 139, 0.3);
    color: #94a3b8;
}

.segment-editor-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.segment-search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.segment-search-box input {
    width: 220px;
    padding: 7px 12px 7px 32px;
    border-radius: 6px;
    border: 1px solid var(--term-border, #334155);
    background: var(--bg-body, #0f172a);
    color: inherit;
    font-size: 13px;
    outline: none;
    transition: width 0.2s, border-color 0.2s;
}

.segment-search-box input:focus {
    width: 260px;
    border-color: #3b82f6;
}

body.light-theme .segment-search-box input,
html[data-theme="light"] .segment-search-box input {
    background: #ffffff;
    border-color: #cbd5e1;
}

.segment-search-icon {
    position: absolute;
    left: 10px;
    pointer-events: none;
    color: #64748b;
    display: flex;
    align-items: center;
}

/* Legend bar */
.segment-legend-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px;
    background: rgba(30, 41, 59, 0.6);
    border-bottom: 1px solid rgba(51, 65, 85, 0.5);
    font-size: 12px;
    color: var(--text-secondary, #94a3b8);
    flex-wrap: wrap;
    gap: 12px;
    z-index: 9;
}

body.light-theme .segment-legend-bar,
html[data-theme="light"] .segment-legend-bar {
    background: #f1f5f9;
    border-bottom: 1px solid #e2e8f0;
    color: #475569;
}

.segment-legend-items {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.segment-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.legend-dot.green { background: #10b981; box-shadow: 0 0 6px rgba(16, 185, 129, 0.4); }
.legend-dot.red { background: #ef4444; box-shadow: 0 0 6px rgba(239, 68, 68, 0.4); }
.legend-dot.gray { background: #64748b; }

.segment-tools-items {
    display: flex;
    align-items: center;
    gap: 8px;
}

.segment-btn-sm {
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 6px;
    border: 1px solid var(--term-border, #334155);
    background: transparent;
    color: inherit;
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.segment-btn-sm:hover {
    background: rgba(59, 130, 246, 0.1);
    border-color: #3b82f6;
    color: #3b82f6;
}

/* Canvas viewport */
.segment-canvas-container {
    flex: 1;
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}

.segment-canvas-container:active {
    cursor: grabbing;
}

.segment-canvas-container canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
}

/* Floating helper instructions */
.segment-instructions-card {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid var(--term-border, #334155);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 12px;
    color: var(--text-secondary, #94a3b8);
    pointer-events: none;
    z-index: 5;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    max-width: 340px;
    backdrop-filter: blur(4px);
}

body.light-theme .segment-instructions-card,
html[data-theme="light"] .segment-instructions-card {
    background: rgba(255, 255, 255, 0.95);
    border-color: #cbd5e1;
    color: #334155;
}

.segment-instructions-card b {
    color: var(--text-primary, #f8fafc);
}

body.light-theme .segment-instructions-card b,
html[data-theme="light"] .segment-instructions-card b {
    color: #0f172a;
}

/* Zoom controls */
.segment-zoom-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 5;
}

.segment-zoom-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--term-border, #334155);
    background: var(--term-card-bg, #1e293b);
    color: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    transition: all 0.15s;
}

.segment-zoom-btn:hover {
    border-color: #3b82f6;
    color: #3b82f6;
    transform: translateY(-1px);
}

body.light-theme .segment-zoom-btn,
html[data-theme="light"] .segment-zoom-btn {
    background: #ffffff;
    border-color: #cbd5e1;
}

/* Tooltip */
.segment-tooltip {
    position: absolute;
    display: none;
    padding: 8px 12px;
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid #38bdf8;
    border-radius: 6px;
    font-size: 12px;
    color: #f8fafc;
    pointer-events: none;
    z-index: 100;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    transform: translate(-50%, -120%);
    white-space: nowrap;
}

body.light-theme .segment-tooltip,
html[data-theme="light"] .segment-tooltip {
    background: #ffffff;
    color: #0f172a;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

@media (max-width: 768px) {
    .segment-editor-header {
        padding: 10px 14px;
        gap: 10px;
    }
    .segment-search-box input {
        width: 140px;
    }
    .segment-search-box input:focus {
        width: 180px;
    }
    .segment-instructions-card {
        display: none;
    }
}

/* Segment Share Dialog */
.segment-share-dialog-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 10005;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    padding: 16px;
}

.segment-share-dialog-backdrop.open {
    opacity: 1;
    visibility: visible;
}

.segment-share-card {
    background: var(--term-card-bg, #1e293b);
    border: 1px solid var(--term-border, #334155);
    border-radius: 12px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    animation: sharePop 0.2s ease-out;
}

@keyframes sharePop {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

body.light-theme .segment-share-card,
html[data-theme="light"] .segment-share-card {
    background: #ffffff;
    border-color: #cbd5e1;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}

.segment-share-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--term-border, #334155);
}

body.light-theme .segment-share-header,
html[data-theme="light"] .segment-share-header {
    border-bottom-color: #e2e8f0;
}

.segment-share-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary, #f8fafc);
}

body.light-theme .segment-share-header h3,
html[data-theme="light"] .segment-share-header h3 {
    color: #0f172a;
}

.segment-share-close {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    color: var(--text-secondary, #94a3b8);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.15s;
}

.segment-share-close:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.segment-share-body {
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.segment-share-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.segment-share-title {
    font-size: 13.5px;
    font-weight: 600;
    color: #38bdf8;
    display: flex;
    align-items: center;
    gap: 6px;
}

body.light-theme .segment-share-title,
html[data-theme="light"] .segment-share-title {
    color: #0284c7;
}

.segment-share-hint {
    font-size: 12px;
    color: var(--text-secondary, #94a3b8);
    line-height: 1.4;
}

.segment-share-code-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-body, #0f172a);
    border: 1px solid var(--term-border, #334155);
    border-radius: 8px;
    padding: 8px 12px;
}

body.light-theme .segment-share-code-box,
html[data-theme="light"] .segment-share-code-box {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.segment-share-code-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 2.5px;
    color: #10b981;
}

.segment-share-link-row,
.segment-share-apply-row {
    display: flex;
    gap: 8px;
}

.segment-share-link-row input,
.segment-share-apply-row input {
    flex: 1;
    min-width: 0;
    padding: 7px 10px;
    border-radius: 6px;
    border: 1px solid var(--term-border, #334155);
    background: var(--bg-body, #0f172a);
    color: var(--text-primary, #f8fafc);
    font-size: 12.5px;
    outline: none;
}

body.light-theme .segment-share-link-row input,
body.light-theme .segment-share-apply-row input,
html[data-theme="light"] .segment-share-link-row input,
html[data-theme="light"] .segment-share-apply-row input {
    background: #ffffff;
    border-color: #cbd5e1;
    color: #0f172a;
}

.segment-share-divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 4px 0;
    color: var(--text-secondary, #64748b);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.segment-share-divider::before,
.segment-share-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--term-border, #334155);
}

body.light-theme .segment-share-divider::before,
body.light-theme .segment-share-divider::after,
html[data-theme="light"] .segment-share-divider::before,
html[data-theme="light"] .segment-share-divider::after {
    border-bottom-color: #e2e8f0;
}

.segment-share-divider span {
    padding: 0 10px;
}

.segment-share-status {
    font-size: 12px;
    min-height: 16px;
    line-height: 1.4;
    transition: all 0.2s;
}

.segment-share-status.error {
    color: #ef4444;
}

.segment-share-status.success {
    color: #10b981;
}

/* Toast alert inside Segment Editor */
.segment-toast {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #0f172a;
    color: #f8fafc;
    border: 1px solid #10b981;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 10004;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.segment-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

body.light-theme .segment-toast,
html[data-theme="light"] .segment-toast {
    background: #ffffff;
    color: #0f172a;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}
