/* ============================================================
   Text Management — Admin Dashboard Styles
   Prefix: tm-  (text-management)
   Reuses --cs-* / --a-* tokens from challenge-setup.css
   ============================================================ */

/* ---- Page layout ---- */
.tm-page {
    display: flex;
    height: 100vh;
    font-family: var(--cs-font);
    color: var(--cs-text-primary);
    background: var(--cs-content-bg);
    overflow: hidden;
}

/* ---- Sidebar ---- */
.tm-sidebar {
    width: var(--cs-sidebar-width);
    min-width: var(--cs-sidebar-width);
    background: var(--cs-sidebar-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tm-sidebar-header {
    padding: 20px 16px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.tm-sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.tm-sidebar-logo svg {
    width: 24px;
    height: 24px;
    stroke: var(--cs-sidebar-text-bright);
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tm-sidebar-logo span {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--cs-sidebar-text-bright);
}

.tm-sidebar-search {
    width: 100%;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--cs-radius-sm);
    color: var(--cs-sidebar-text-bright);
    font-size: 13px;
    font-family: var(--cs-font);
    outline: none;
    transition: border-color 0.15s;
}

.tm-sidebar-search::placeholder {
    color: var(--cs-sidebar-text);
}

.tm-sidebar-search:focus {
    border-color: var(--cs-accent);
}

.tm-sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.tm-sidebar-list::-webkit-scrollbar {
    width: 4px;
}

.tm-sidebar-list::-webkit-scrollbar-track {
    background: transparent;
}

.tm-sidebar-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

.tm-sidebar-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.12s;
    border-left: 3px solid transparent;
}

.tm-sidebar-item:hover {
    background: var(--cs-sidebar-hover);
}

.tm-sidebar-item.active {
    background: var(--cs-sidebar-active);
    border-left-color: var(--cs-accent);
}

.tm-sidebar-item-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--cs-sidebar-text-bright);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.tm-sidebar-item-count {
    font-size: 11px;
    font-weight: 600;
    color: var(--cs-sidebar-text);
    flex-shrink: 0;
}

.tm-sidebar-loading {
    padding: 24px 16px;
    text-align: center;
    color: var(--cs-sidebar-text);
    font-size: 13px;
}

/* ---- Main content ---- */
.tm-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* ---- Header bar ---- */
.tm-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 28px;
    background: var(--cs-card-bg);
    border-bottom: 1px solid var(--cs-card-border);
    flex-shrink: 0;
}

.tm-header-left {
    display: flex;
    flex-direction: column;
}

.tm-header-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--cs-text-primary);
}

.tm-header-subtitle {
    font-size: 13px;
    color: var(--cs-text-muted);
    margin-top: 2px;
}

.tm-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ---- Toolbar ---- */
.tm-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 28px;
    background: var(--cs-card-bg);
    border-bottom: 1px solid var(--cs-card-border);
    flex-shrink: 0;
}

.tm-toolbar-search {
    flex: 1;
    max-width: 400px;
    padding: 8px 12px;
    border: 1px solid var(--cs-input-border);
    border-radius: var(--cs-radius-sm);
    font-size: 13px;
    font-family: var(--cs-font);
    background: var(--cs-input-bg);
    color: var(--cs-text-primary);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.tm-toolbar-search:focus {
    border-color: var(--cs-input-focus);
    box-shadow: 0 0 0 3px rgba(99, 130, 255, 0.15);
}

.tm-toolbar-search::placeholder {
    color: var(--cs-text-muted);
}

/* ---- Content area ---- */
.tm-content {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* ---- Text table ---- */
.tm-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}

.tm-table thead th {
    text-align: left;
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--cs-text-muted);
    background: var(--cs-card-bg);
    border-bottom: 1px solid var(--cs-card-border);
    position: sticky;
    top: 0;
    z-index: 1;
}

.tm-table tbody td {
    padding: 10px 16px;
    border-bottom: 1px solid #f0f1f5;
    color: var(--cs-text-primary);
}

.tm-table tbody tr {
    cursor: pointer;
    transition: background 0.1s;
}

.tm-table tbody tr:hover {
    background: #f9f9fc;
}

.tm-table tbody tr.active {
    background: var(--cs-accent-light);
}

.tm-table tbody tr:last-child td {
    border-bottom: none;
}

.tm-text-key {
    font-family: var(--cs-font-mono);
    font-size: 12px;
    color: var(--cs-accent);
    font-weight: 500;
}

.tm-text-value {
    max-width: 500px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tm-text-desc {
    font-size: 12px;
    color: var(--cs-text-muted);
}

/* ---- Edit panel ---- */
.tm-edit-panel {
    border-top: 2px solid var(--cs-accent);
    background: var(--cs-card-bg);
    padding: 24px 28px;
    flex-shrink: 0;
    max-height: 50vh;
    overflow-y: auto;
}

.tm-edit-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.tm-edit-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--cs-text-primary);
}

.tm-edit-key {
    font-family: var(--cs-font-mono);
    font-size: 13px;
    color: var(--cs-accent);
    font-weight: 500;
}

.tm-edit-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.tm-edit-grid .tm-field-full {
    grid-column: 1 / -1;
}

.tm-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tm-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--cs-text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.tm-label-flag {
    font-size: 14px;
}

.tm-input {
    padding: 9px 12px;
    border: 1px solid var(--cs-input-border);
    border-radius: var(--cs-radius-sm);
    font-size: 13px;
    font-family: var(--cs-font);
    background: var(--cs-input-bg);
    color: var(--cs-text-primary);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.tm-input:focus {
    border-color: var(--cs-input-focus);
    box-shadow: 0 0 0 3px rgba(99, 130, 255, 0.15);
}

.tm-input::placeholder {
    color: var(--cs-text-muted);
}

.tm-input-mono {
    font-family: var(--cs-font-mono);
    font-size: 12px;
}

.tm-textarea {
    padding: 9px 12px;
    border: 1px solid var(--cs-input-border);
    border-radius: var(--cs-radius-sm);
    font-size: 13px;
    font-family: var(--cs-font);
    background: var(--cs-input-bg);
    color: var(--cs-text-primary);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
    resize: vertical;
    min-height: 36px;
}

.tm-textarea:focus {
    border-color: var(--cs-input-focus);
    box-shadow: 0 0 0 3px rgba(99, 130, 255, 0.15);
}

.tm-lang-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.tm-lang-grid .tm-field-full {
    grid-column: 1 / -1;
}

.tm-edit-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-top: 12px;
    border-top: 1px solid var(--cs-card-border);
}

.tm-edit-actions-right {
    margin-left: auto;
}

/* ---- Buttons (reuse cs-btn pattern) ---- */
.tm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--cs-radius-sm);
    font-size: 13px;
    font-weight: 600;
    font-family: var(--cs-font);
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

.tm-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.tm-btn-primary {
    background: var(--cs-accent);
    color: var(--cs-accent-text);
}

.tm-btn-primary:hover:not(:disabled) {
    background: var(--cs-accent-hover);
}

.tm-btn-publish {
    background: #0d6efd;
    color: #fff;
}

.tm-btn-publish:hover:not(:disabled) {
    background: #0b5ed7;
}

.tm-btn-danger {
    background: var(--cs-danger);
    color: #fff;
}

.tm-btn-danger:hover:not(:disabled) {
    background: var(--cs-danger-hover);
}

.tm-btn-ghost {
    background: transparent;
    color: var(--cs-text-secondary);
    border: 1px solid var(--cs-card-border);
}

.tm-btn-ghost:hover:not(:disabled) {
    background: #f0f1f5;
    color: var(--cs-text-primary);
}

.tm-btn-sm {
    padding: 5px 12px;
    font-size: 12px;
}

/* ---- Alerts ---- */
.tm-alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--cs-radius-sm);
    font-size: 13px;
    line-height: 1.5;
    margin: 12px 28px 0;
}

.tm-alert-error {
    background: var(--cs-danger-light);
    color: var(--cs-danger);
    border: 1px solid rgba(229, 72, 77, 0.15);
}

.tm-alert-success {
    background: var(--cs-success-light);
    color: var(--cs-success);
    border: 1px solid rgba(48, 164, 108, 0.15);
}

.tm-alert-text {
    flex: 1;
}

.tm-alert-close {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    opacity: 0.6;
    color: inherit;
    flex-shrink: 0;
}

.tm-alert-close:hover {
    opacity: 1;
}

/* ---- Empty state ---- */
.tm-empty {
    text-align: center;
    padding: 48px 16px;
    color: var(--cs-text-muted);
    font-size: 13px;
}

.tm-empty-icon {
    font-size: 32px;
    margin-bottom: 8px;
    opacity: 0.4;
}

/* ---- Spinner ---- */
.tm-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: tm-spin 0.6s linear infinite;
}

@keyframes tm-spin {
    to { transform: rotate(360deg); }
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .tm-page {
        flex-direction: column;
    }

    .tm-sidebar {
        width: 100%;
        min-width: 100%;
        max-height: 200px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .tm-sidebar-list {
        display: flex;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 4px 8px;
        gap: 4px;
    }

    .tm-sidebar-item {
        flex-shrink: 0;
        padding: 6px 12px;
        border-left: none;
        border-bottom: 2px solid transparent;
        border-radius: var(--cs-radius-sm);
    }

    .tm-sidebar-item.active {
        border-left-color: transparent;
        border-bottom-color: var(--cs-accent);
    }

    .tm-header {
        padding: 12px 16px;
    }

    .tm-toolbar {
        padding: 8px 16px;
    }

    .tm-edit-panel {
        padding: 16px;
    }

    .tm-edit-grid,
    .tm-lang-grid {
        grid-template-columns: 1fr;
    }

    .tm-alert {
        margin: 8px 16px 0;
    }
}
