.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.open {
    opacity: 1;
}

.modal-content {
    background: var(--surface);
    padding: 30px;
    width: 100%;
    max-width: 450px;
    border-radius: 15px;
    position: relative;
    border: 1px solid var(--border);
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.9) translateY(15px);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 2;
}

.modal.open .modal-content {
    transform: scale(1) translateY(0);
}

.modal-content-large {
    max-width: 800px;
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content-small {
    text-align: center;
    max-width: 350px;
}

.modal-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
}

.modal-title-flex {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-title-no-margin {
    margin-top: 0;
}

.modal-confirm-buttons {
    display: flex;
    gap: 15px;
    margin-top: 25px;
}

.btn-flex-1 { flex: 1; }
.btn-danger { background: var(--danger) !important; }
.btn-danger:hover { background: #c0392b !important; }
.modal-high-z { z-index: 2000; }

.close-btn {
    position: absolute;
    left: 15px;
    top: 15px;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-muted);
    transition: 0.2s;
    z-index: 10;
    line-height: 1;
}

.close-btn:hover {
    color: var(--danger);
}

.custom-file-upload {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 25px 15px;
    border: 2px dashed var(--border);
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-muted);
    transition: 0.3s;
    background: rgba(0, 0, 0, 0.1);
    width: 100%;
    box-sizing: border-box;
    text-align: center;
}

.custom-file-upload:hover {
    border-color: var(--accent);
    color: var(--text);
    background: rgba(0, 0, 0, 0.2);
}

.custom-file-upload input[type="file"] { display: none; }
.custom-file-upload svg { width: 32px; height: 32px; margin-bottom: 10px; fill: currentColor; }
.file-name-display { font-size: 14px; margin-top: 5px; font-weight: bold; }
.upload-file-label { padding: 15px; }
.image-preview { display: none; max-width: 100%; max-height: 200px; border-radius: 8px; margin-top: 10px; object-fit: contain; }
.checkbox-label { display: flex; align-items: center; gap: 8px; margin-bottom: 15px; color: var(--text-muted); cursor: pointer; font-size: 14px; }
.before-image-wrapper { display: none; margin-bottom: 15px; }
.ai-tagging-status { display: none; color: var(--accent); font-size: 13px; margin-bottom: 5px; font-weight: bold; }
.upload-progress-text { text-align: center; font-size: 12px; margin-top: 5px; color: var(--accent); display: none; }
.edit-save-btn { width: 100%; margin-top: 15px; }

#mapNetworkWrapper {
    position: relative;
    width: 100%;
    height: 75vh;
    margin-top: 15px;
    border-radius: 10px;
    overflow: hidden;
}

#mapNetwork { width: 100%; height: 100%; background: var(--bg); }

#mapNodePopup {
    display: none;
    position: absolute;
    z-index: 10;
    background: var(--surface);
    padding: 8px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
    border: 1px solid var(--border);
    text-align: center;
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    transform: translate(-50%, -100%);
    margin-top: -15px;
    transition: 0.2s;
}

#mapNodePopup:hover {
    border-color: var(--accent);
    transform: translate(-50%, -100%) scale(1.05);
}

.map-modal-content { max-width: 90vw; height: 90vh; display: flex; flex-direction: column; }
.map-controls { display: flex; gap: 15px; font-size: 14px; background: var(--bg); padding: 8px 15px; border-radius: 8px; border: 1px solid var(--border); }
.map-network-wrapper { margin-top: 0; flex-grow: 1; position: relative; }
.map-skeleton-text { position: absolute; bottom: 20px; color: var(--text-muted); font-weight: bold; animation: skeleton-pulse 1.5s infinite; }
.map-popup-img { width: 120px; height: 120px; object-fit: cover; border-radius: 4px; margin-bottom: 5px; }
.map-popup-title { font-size: 12px; font-weight: bold; color: white; max-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.map-skeleton {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--surface);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.skel-pulse-fill { fill: var(--surface-hover); animation: skeleton-pulse 1.5s ease-in-out infinite; }
.skel-pulse-stroke { stroke: var(--surface-hover); stroke-width: 2; animation: skeleton-pulse 1.5s ease-in-out infinite; }

.btn-stats { padding: 0 10px; display: flex; align-items: center; justify-content: center; }
.stats-action-buttons { display: flex; gap: 10px; align-items: center; }
.stats-scope-btn { height: 34px; padding: 0 15px; font-size: 13px; background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-csv { height: 34px; padding: 0 15px; font-size: 13px; margin-left: 7px; }
.stats-content-wrapper { opacity: 0; transition: opacity 0.3s ease-in-out; }
.chart-subtitle { font-size: 11px; font-weight: normal; }
.chart-canvas-wrapper { position: relative; height: 280px; width: 100%; }
.chart-full-width { grid-column: 1 / -1; height: 420px; }
.chart-canvas-centered { position: relative; height: 100%; width: 100%; padding: 10px; box-sizing: border-box; }

.stats-skeleton { display: flex; flex-direction: column; gap: 20px; margin-top: 15px; }
.stats-skel-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 15px; }
.stats-skel-card { height: 80px; background: var(--surface-hover); border-radius: 10px; animation: skeleton-pulse 1.5s infinite; }
.stats-skel-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.stats-skel-chart { height: 250px; background: var(--surface-hover); border-radius: 10px; animation: skeleton-pulse 1.5s infinite; }

@media (max-width: 600px) {
    .stats-skel-charts { grid-template-columns: 1fr; }
}

.stats-summary-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 15px; margin-bottom: 25px; }
.stat-card { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 15px; text-align: center; }
.stat-card.clickable { cursor: pointer; transition: transform 0.2s ease, border-color 0.2s ease; }
.stat-card.clickable:hover { transform: translateY(-3px); border-color: var(--accent); }
.stat-value { font-size: 24px; font-weight: bold; color: var(--accent); margin-bottom: 5px; }
.stat-label { font-size: 13px; color: var(--text-muted); }
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.chart-container { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 15px; position: relative; }
.chart-container h4 { margin-top: 0; margin-bottom: 15px; font-size: 14px; text-align: center; color: var(--text-muted); }

@media (max-width: 600px) {
    .charts-grid { grid-template-columns: 1fr; }
    .chart-container { grid-column: 1 / -1 !important; }
}

#toast-container {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--surface);
    color: var(--text);
    padding: 15px 25px;
    border-radius: 8px;
    border-right: 5px solid var(--accent);
    animation: slideIn 0.3s forwards, slideOut 0.3s 2.7s forwards;
    box-shadow: 0 4px 12px var(--shadow);
}

.toast.toast-success { border-right-color: #2ecc71; }
.toast.toast-error { border-right-color: var(--danger); }
.toast.toast-warning { border-right-color: #e67e22; }

@keyframes slideIn {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(-100%); opacity: 0; }
}

@keyframes shrinkBar {
    from { width: 100%; }
    to { width: 0%; }
}

.ai-loading-indicator {
    display: none;
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: var(--accent);
    padding: 15px 20px;
    border-radius: 12px;
    z-index: 9999;
    font-size: 14px;
    border: 1px solid var(--accent);
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    width: 320px;
    text-align: center;
}

.ai-loading-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; }
.ai-loading-progress-text { font-weight: bold; }

.search-action-btn {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    padding: 5px;
    color: var(--text-muted);
    transition: 0.3s;
    z-index: 5;
}

.search-action-btn:hover { color: var(--accent); }

.explorer-panel {
    display: none;
    position: absolute;
    top: calc(100% + 5px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    z-index: 1000;
    padding: 15px;
    box-shadow: 0 4px 15px var(--shadow);
    cursor: default;
    box-sizing: border-box;
}

.panel-left-align { left: 0; width: 100%; min-width: 300px; }
.panel-center-align { left: 50%; transform: translateX(-50%); width: max-content; }

.explorer-panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.explorer-panel-title { font-weight: bold; font-size: 14px; }
.tag-sort-options { display: flex; gap: 10px; font-size: 13px; }
.tag-sort-options label { cursor: pointer; }
.tag-explorer-list { display: flex; flex-wrap: wrap; gap: 8px; max-height: 250px; overflow-y: auto; align-content: flex-start; }

.color-palette-title { font-weight: bold; font-size: 14px; margin-bottom: 15px; text-align: center; }
.color-palette-grid { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; max-width: 260px; margin: 0 auto; }
.color-search-btn { width: 100%; margin-top: 20px; justify-content: center; }

.color-swatch { width: 30px; height: 30px; border-radius: 50%; cursor: pointer; transition: 0.2s; border: 2px solid transparent; }
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: var(--accent); transform: scale(1.15); box-shadow: 0 0 8px var(--accent); }

.swatch-red { background: #e74c3c; }
.swatch-orange { background: #e67e22; }
.swatch-brown { background: #8b4513; }
.swatch-yellow { background: #f1c40f; }
.swatch-green { background: #2ecc71; }
.swatch-lightblue { background: #00bfff; }
.swatch-blue { background: #3498db; }
.swatch-purple { background: #9b59b6; }
.swatch-pink { background: #ff9ff3; }
.swatch-white { background: #ecf0f1; border: 1px solid #ccc; }
.swatch-gray { background: #95a5a6; }
.swatch-black { background: #222; border: 1px solid #555; }

.native-color-wrapper { background: linear-gradient(135deg, red, yellow, green, blue, purple); position: relative; overflow: hidden; }
.native-color-picker { position: absolute; width: 200%; height: 200%; top: -50%; left: -50%; cursor: pointer; opacity: 0; }

body.modal-open {
    overflow: hidden !important;
}