/*
 * Visual stack editor (Редактор на изображения / Видео редактор).
 *
 * Plain CSS on purpose: the app's Tailwind build can't run on this machine's
 * Node, so the editor ships its own prefixed styles instead of utility classes.
 * Colours follow Filament's CSS variables so light/dark themes just work.
 */

.cma-editor {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 20rem;
    gap: 1rem;
    align-items: start;
}

@media (max-width: 1024px) {
    .cma-editor {
        grid-template-columns: minmax(0, 1fr);
    }
}

.cma-panel {
    background: var(--cma-panel-bg, rgba(255, 255, 255, 0.85));
    border: 1px solid rgba(120, 120, 130, 0.25);
    border-radius: 0.75rem;
    padding: 0.75rem;
}

.dark .cma-panel {
    background: rgba(24, 24, 27, 0.75);
}

/* ---------------------------------------------------------------- toolbar */

.cma-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.cma-toolbar__group {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.cma-toolbar__sep {
    width: 1px;
    align-self: stretch;
    background: rgba(120, 120, 130, 0.3);
}

.cma-label {
    font-size: 0.75rem;
    opacity: 0.7;
    white-space: nowrap;
}

/* Long helper sentences: same look as a label, but allowed to wrap. */
.cma-hint {
    white-space: normal;
}

.cma-input,
.cma-select {
    background: transparent;
    border: 1px solid rgba(120, 120, 130, 0.35);
    border-radius: 0.5rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    color: inherit;
    min-width: 0;
}

/* The dropdown popup is drawn by the OS; `color: inherit` there is white-on-
   white in dark mode. Pin explicit colours so options stay readable in both. */
.cma-select option {
    background-color: #ffffff;
    color: #111827;
}

.dark .cma-select option {
    background-color: #1f2937;
    color: #f9fafb;
}

.cma-input--num {
    width: 4.5rem;
}

.cma-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: transparent;
    border: 1px solid rgba(120, 120, 130, 0.35);
    border-radius: 0.5rem;
    padding: 0.3rem 0.55rem;
    font-size: 0.78rem;
    color: inherit;
    cursor: pointer;
    white-space: nowrap;
}

.cma-btn:hover:not(:disabled) {
    background: rgba(120, 120, 130, 0.15);
}

.cma-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.cma-btn--icon {
    padding: 0.3rem;
    line-height: 1;
}

.cma-btn--primary {
    background: rgb(var(--primary-600, 217 119 6));
    border-color: transparent;
    color: #fff;
    font-weight: 600;
}

.cma-btn--primary:hover:not(:disabled) {
    background: rgb(var(--primary-500, 245 158 11));
}

.cma-btn--active {
    background: rgba(120, 120, 130, 0.25);
}

/* Prominent primary actions (add file / add text / process). */
.cma-btn--lg {
    padding: 0.5rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 0.6rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.cma-btn--accent {
    background: rgb(var(--primary-500, 245 158 11) / 0.12);
    border-color: rgb(var(--primary-500, 245 158 11));
    color: rgb(var(--primary-600, 217 119 6));
}

.cma-btn--accent:hover:not(:disabled) {
    background: rgb(var(--primary-500, 245 158 11) / 0.22);
}

/* A visible divider + breathing room so the action cluster reads as the CTA. */
/* Add/process buttons: always their own bottom row, right-aligned. */
.cma-toolbar__group--actions {
    gap: 0.5rem;
    flex-basis: 100%;
    justify-content: flex-start;
}

/* Brand-colour swatches under the text-colour picker. */
.cma-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.cma-swatch {
    width: 1.4rem;
    height: 1.4rem;
    border-radius: 0.35rem;
    border: 1px solid rgba(120, 120, 130, 0.45);
    padding: 0;
    cursor: pointer;
}

.cma-swatch:hover {
    transform: scale(1.1);
}

.cma-swatch--active {
    outline: 2px solid rgb(var(--primary-500, 245 158 11));
    outline-offset: 1px;
}

/* ------------------------------------------------------------------ stage */

.cma-stage-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 24rem;
    padding: 1rem;
    border-radius: 0.75rem;
    background-color: rgba(120, 120, 130, 0.12);
    /* Checkerboard: shows through where the canvas itself is transparent. */
    background-image:
        linear-gradient(45deg, rgba(120, 120, 130, 0.18) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(120, 120, 130, 0.18) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, rgba(120, 120, 130, 0.18) 75%),
        linear-gradient(-45deg, transparent 75%, rgba(120, 120, 130, 0.18) 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    overflow: hidden;
}

.cma-stage {
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    touch-action: none;
    user-select: none;
}

.cma-layer {
    position: absolute;
    transform-origin: center center;
}

.cma-layer > img,
.cma-layer > video {
    width: 100%;
    height: 100%;
    display: block;
    /* The box is what the user drew, so fill it exactly - same as the render. */
    object-fit: fill;
    pointer-events: none;
}

/* A keyed clip's shader output. It sits exactly over the layer's box, on top of
   the (hidden) <video> that still drives playback. */
.cma-layer > canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none;
}

.cma-layer--hidden {
    display: none;
}

.cma-layer__hit {
    position: absolute;
    inset: 0;
    cursor: move;
}

.cma-layer--selected {
    outline: 1px solid rgb(59, 130, 246);
    outline-offset: 0;
}

/* Non-primary members of a multi-selection: dashed so the primary stands out. */
.cma-layer--multi {
    outline: 1px dashed rgb(59, 130, 246);
    outline-offset: 0;
}

.cma-handle {
    position: absolute;
    width: 11px;
    height: 11px;
    margin: -6px 0 0 -6px;
    background: #fff;
    border: 1px solid rgb(59, 130, 246);
    border-radius: 2px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.cma-handle--rotate {
    border-radius: 50%;
    background: rgb(59, 130, 246);
    cursor: grab;
}

.cma-guide {
    position: absolute;
    background: rgb(236, 72, 153);
    pointer-events: none;
    z-index: 60;
}

.cma-guide--v {
    top: 0;
    bottom: 0;
    width: 1px;
}

.cma-guide--h {
    left: 0;
    right: 0;
    height: 1px;
}

.cma-dropzone {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
    font-size: 0.9rem;
    background: rgba(59, 130, 246, 0.12);
    border: 2px dashed rgb(59, 130, 246);
    border-radius: 0.75rem;
    z-index: 80;
}

.cma-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
    opacity: 0.65;
    font-size: 0.85rem;
    pointer-events: none;
    padding: 2rem;
}

/* Video editor: extra breathing room around the empty-stage hint. */
.cma-empty--padded {
    padding: 4rem;
}

.cma-stage-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    opacity: 0.6;
    margin-top: 0.4rem;
}

/* ------------------------------------------------------------ layer list */

.cma-layers {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 32rem;
    overflow-y: auto;
}

.cma-layer-row {
    display: grid;
    grid-template-columns: 2.5rem minmax(0, 1fr);
    gap: 0.5rem;
    align-items: center;
    padding: 0.4rem;
    border: 1px solid rgba(120, 120, 130, 0.25);
    border-radius: 0.6rem;
    background: rgba(120, 120, 130, 0.08);
    cursor: pointer;
}

.dark .cma-layer-row {
    background: rgba(255, 255, 255, 0.05);
}

.cma-layer-row--selected {
    border-color: rgb(59, 130, 246);
    background: rgba(59, 130, 246, 0.08);
}

/* Also-selected (not the primary/reference) rows: dimmer than the primary. */
.cma-layer-row--multi {
    border-color: rgba(59, 130, 246, 0.6);
    background: rgba(59, 130, 246, 0.04);
}

.cma-layer-row--dragover {
    border-top: 2px solid rgb(59, 130, 246);
}

.cma-layer-row__thumb {
    width: 2.5rem;
    height: 2.5rem;
    object-fit: cover;
    border-radius: 0.4rem;
    background: rgba(120, 120, 130, 0.25);
}

.cma-layer-row__name {
    font-size: 0.75rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cma-layer-row__meta {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.2rem;
}

.cma-range {
    width: 100%;
    accent-color: rgb(59, 130, 246);
}

.cma-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.cma-field {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.cma-field .cma-input {
    width: 100%;
}

/* --------------------------------------------------------------- timeline */

.cma-timeline {
    margin-top: 0.75rem;
}

.cma-transport {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.cma-time {
    font-variant-numeric: tabular-nums;
    font-size: 0.78rem;
    opacity: 0.8;
}

.cma-track-list {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.cma-ruler {
    position: relative;
    height: 1.25rem;
    border-bottom: 1px solid rgba(120, 120, 130, 0.3);
    cursor: pointer;
}

.cma-ruler__tick {
    position: absolute;
    top: 0;
    bottom: 0;
    border-left: 1px solid rgba(120, 120, 130, 0.35);
    padding-left: 2px;
    font-size: 0.6rem;
    opacity: 0.6;
    white-space: nowrap;
}

/* Near the right edge: keep the tick line on the mark, label grows leftwards. */
.cma-ruler__tick--end {
    transform: translateX(-100%);
    border-left: none;
    border-right: 1px solid rgba(120, 120, 130, 0.35);
    padding-left: 0;
    padding-right: 2px;
}

.cma-track {
    position: relative;
    height: 2rem;
    background: rgba(120, 120, 130, 0.12);
    border-radius: 0.4rem;
}

.cma-clip {
    position: absolute;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    padding: 0 0.6rem;
    font-size: 0.7rem;
    color: #fff;
    background: rgba(59, 130, 246, 0.75);
    border-radius: 0.4rem;
    cursor: grab;
    overflow: hidden;
    white-space: nowrap;
}

.cma-clip--image {
    background: rgba(139, 92, 246, 0.75);
}

.cma-clip--audio {
    background: rgba(16, 185, 129, 0.8);
}

.cma-clip--selected {
    outline: 2px solid #fff;
    outline-offset: -2px;
}

.cma-clip__trim {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 0.45rem;
    background: rgba(255, 255, 255, 0.55);
    cursor: ew-resize;
}

.cma-clip__trim--start {
    left: 0;
    border-radius: 0.4rem 0 0 0.4rem;
}

.cma-clip__trim--end {
    right: 0;
    border-radius: 0 0.4rem 0.4rem 0;
}

.cma-playhead {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: rgb(239, 68, 68);
    pointer-events: none;
    z-index: 10;
}

/* Ruler ticks continued through the tracks as a faint grid. */
.cma-timegrid {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.cma-timegrid__line {
    position: absolute;
    top: 1.25rem; /* below the ruler */
    bottom: 0;
    border-left: 1px dashed rgba(120, 120, 130, 0.18);
}

/* Where a dragged clip edge just snapped to. */
.cma-snapline {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: rgb(236, 72, 153);
    pointer-events: none;
    z-index: 11;
}

/* Start/end times shown on the selected clip. */
.cma-clip__time {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.6rem;
    line-height: 1.4;
    padding: 0 0.25rem;
    border-radius: 0.2rem;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    pointer-events: none;
}

.cma-clip__time--start {
    left: 0.55rem;
}

.cma-clip__time--end {
    right: 0.55rem;
}
