/* =========================================================
   Segment Details Page — v4
   ========================================================= */

/* ── Toolbar card wrapper ────────────────────────────────── */
.sd-toolbar-card {
    padding: 14px 20px;
    margin-bottom: 20px;
    overflow: visible;  /* allow dropdown panel to float over cards below */
    position: relative;
    z-index: 20;        /* sit above sibling cards so dropdown floats over them */
}

/* ── Toolbar ─────────────────────────────────────────────── */
.sd-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: nowrap;
    margin-bottom: 0;
}
.sd-seg-selector-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;       /* allow shrinking */
    overflow: visible;  /* panel must float freely */
}
.sd-seg-selector-wrap label {
    font-weight: 500;
    color: #374151;
    font-size: 0.9rem;
    white-space: nowrap;
    flex-shrink: 0;
}
.sd-custom-select {
    position: relative;
    flex: 1;
    min-width: 0;
    max-width: 360px;
}
.sd-select-trigger {
    width: 100%;
    min-width: 0;
    padding: 9px 14px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    text-align: left;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-size: 0.93rem;
}
.sd-select-trigger:hover,
.sd-select-trigger:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
    outline: none;
}
.sd-trigger-name {
    font-weight: 600;
    color: #1e293b;
    font-size: 0.93rem;
}
.sd-trigger-meta {
    font-size: 0.76rem;
    color: #64748b;
    margin-left: 8px;
    font-weight: 400;
}
.sd-select-chevron {
    color: #94a3b8;
    font-size: 0.75rem;
    flex-shrink: 0;
    transition: transform 0.2s;
}
.sd-select-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    z-index: 500;
    max-height: 340px;
    overflow-y: auto;
}
.sd-select-option {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.12s;
}
.sd-select-option:last-child { border-bottom: none; }
.sd-select-option:hover { background: #f0f7ff; }
.sd-select-option--selected { background: #eff6ff; }
.sd-select-option-name {
    font-size: 0.92rem;
    font-weight: 600;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 6px;
}
.sd-active-check {
    color: #10b981;
    font-size: 0.82rem;
}
.sd-select-option-meta {
    font-size: 0.76rem;
    color: #64748b;
    margin-top: 3px;
}
.sd-select-empty {
    padding: 14px;
    color: #94a3b8;
    font-size: 0.88rem;
    text-align: center;
}
.sd-toolbar-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    align-items: center;
}

/* ── Delete confirm overlay ──────────────────────────────── */
.sd-confirm-box {
    background: #fff;
    border-radius: 10px;
    padding: 28px 32px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.22);
}
.sd-confirm-box h3 {
    margin: 0 0 12px;
    font-size: 1.05rem;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 8px;
}
.sd-confirm-box p {
    color: #475569;
    margin: 0 0 24px;
    font-size: 0.95rem;
    line-height: 1.5;
}
.sd-confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ── Page-level messages ─────────────────────────────────── */
.sd-page-msg {
    padding: 12px 18px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-weight: 500;
}
.sd-page-msg--success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}
.sd-page-msg--error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

/* ── New / Edit form card ────────────────────────────────── */
.sd-form-card {
    border: 2px solid #6366f1;
    margin-bottom: 24px;
}
.sd-form-card h2 {
    margin: 0 0 20px;
    color: #312e81;
    font-size: 1.1rem;
}
/* ── form-control base (scoped to this page) ────────────── */
.sd-form-card .form-control,
.sd-seg-row .form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.93rem;
    color: #1e293b;
    background: #fff;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
}
.sd-form-card .form-control:focus,
.sd-seg-row .form-control:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.sd-form-card .form-control::placeholder,
.sd-seg-row .form-control::placeholder {
    color: #9ca3af;
}

/* ── form-group inside seg form ──────────────────────────── */
.sd-form-card .form-group,
.sd-seg-row .form-group {
    margin-bottom: 0;
}
.sd-form-card > .form-group {
    margin-bottom: 16px;
}
.sd-form-card .form-group label,
.sd-seg-row .form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    font-size: 0.85rem;
    color: #374151;
}

/* Force uppercase as user types */
#form-name,
.seg-name-input {
    text-transform: uppercase;
}
#form-name::placeholder,
.seg-name-input::placeholder {
    text-transform: none;
}

/* ── Segments builder ────────────────────────────────────── */
.sd-segments-builder {
    margin-top: 20px;
}
.sd-seg-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.sd-seg-header h4 {
    margin: 0;
    color: #1e293b;
    font-size: 0.95rem;
}
.sd-no-rows {
    color: #94a3b8;
    font-style: italic;
    padding: 12px 0;
    margin: 0;
    font-size: 0.88rem;
}

/* ── Segment row (inside form) ───────────────────────────── */
.sd-seg-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 14px;
    padding: 16px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}
.sd-seg-row-fields {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1.4fr;
    gap: 14px;
    flex: 1;
    min-width: 0;
    align-items: start;
}
@media (max-width: 900px) {
    .sd-seg-row-fields {
        grid-template-columns: 1fr 1fr;
    }
}
@media (max-width: 560px) {
    .sd-seg-row-fields {
        grid-template-columns: 1fr;
    }
}
.req { color: #ef4444; }
.sd-hint {
    color: #64748b;
    font-size: 0.82em;
    white-space: nowrap;
}

/* Lookback toggle buttons */
.sd-lookback-toggle {
    display: flex;
    gap: 6px;
    margin-bottom: 2px;
}

/* Remove-row button */
.sd-remove-row-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #ef4444;
    font-size: 1.1rem;
    padding: 4px 6px;
    margin-top: 22px;
    flex-shrink: 0;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}
.sd-remove-row-btn:hover {
    color: #b91c1c;
    background: #fee2e2;
}

/* Form inline error */
.sd-form-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 12px;
    font-size: 0.9rem;
}

/* Form action row */
.sd-form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #e2e8f0;
}
#form-save-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* ── Segmentation list cards ─────────────────────────────── */
.sd-seg-card {
    margin-bottom: 16px;
    transition: box-shadow 0.2s;
}
.sd-seg-card--active {
    border-left: 4px solid #10b981;
}
.sd-seg-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 10px;
}
.sd-seg-card-title {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.sd-seg-name {
    font-size: 1.05rem;
    font-weight: 700;
    color: #1e293b;
}
.sd-seg-card-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

/* Meta line (segment count, EA version) */
.sd-seg-meta {
    font-size: 0.82rem;
    color: #64748b;
    display: flex;
    gap: 16px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.sd-seg-meta i {
    margin-right: 4px;
}

/* ── Badges ──────────────────────────────────────────────── */
.badge-active {
    background: #d1fae5;
    color: #065f46;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.badge-ea {
    background: #dbeafe;
    color: #1e40af;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.badge-custom {
    background: #ede9fe;
    color: #5b21b6;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

/* Set-active button */
.sd-set-active-btn {
    background: #ffffff !important;
    border: 1px solid #6366f1 !important;
    color: #4338ca !important;
}
.sd-set-active-btn:hover {
    background: #e0e7ff !important;
    color: #3730a3 !important;
}

/* Delete button */
.sd-del-btn {
    background: #fee2e2 !important;
    color: #dc2626 !important;
    border-color: #fca5a5 !important;
}
.sd-del-btn:hover {
    background: #fecaca !important;
}

/* ── Segment items inside card (old-style card grid) ────── */
.sd-segments-list {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.sd-segment-item {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
}
.sd-segment-item-header {
    padding: 10px 16px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}
.sd-segment-item-header h4 {
    margin: 0;
    font-size: 0.95rem;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 8px;
}
.sd-segment-item-header h4 i {
    font-size: 0.55rem;
    color: #6366f1;
    vertical-align: middle;
}
.sd-segment-item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0;
    padding: 14px 16px;
    background: #f8f9fa;
}
.sd-segment-detail {
    padding: 6px 12px 6px 0;
}
.sd-segment-detail-label {
    font-size: 0.78rem;
    color: #64748b;
    font-weight: 600;
    margin-bottom: 3px;
}
.sd-segment-detail-label i {
    margin-right: 4px;
    color: #94a3b8;
}
.sd-segment-detail-value {
    font-size: 0.92rem;
    color: #1e293b;
    font-weight: 500;
}
.sd-no-data {
    color: #94a3b8;
    font-style: italic;
    padding: 12px 0;
    font-size: 0.88rem;
}

/* ── Empty state ─────────────────────────────────────────── */
.sd-empty-state {
    text-align: center;
    padding: 48px 20px;
    color: #94a3b8;
}
.sd-empty-state i {
    font-size: 2.5rem;
    margin-bottom: 12px;
    display: block;
}
.sd-empty-state p {
    font-size: 0.95rem;
    color: #64748b;
}

/* ── Loading state ───────────────────────────────────────── */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: #374151;
    margin-bottom: 20px;
}
.loading-state i {
    font-size: 2.4rem;
    color: #6366f1;
    margin-bottom: 12px;
}
.loading-state p {
    margin: 0;
    font-size: 0.95rem;
    color: #374151;
}


