/* ===== COMPONENTS ===== */

/* ---- Table ---- */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.855rem;
}

thead {
    background: var(--surface);
}

th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition: var(--transition);
}

th:hover {
    color: var(--text-primary);
}

th.sorted {
    color: var(--primary-light);
}

th.sorted::after {
    content: ' ↓';
    font-size: 0.65rem;
}

th.sorted.asc::after {
    content: ' ↑';
}

td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tbody tr {
    transition: var(--transition);
    cursor: pointer;
}

tbody tr:hover {
    background: var(--surface);
}

tbody tr:active {
    background: var(--primary-glow);
}

.td-light {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.td-key {
    font-family: 'Courier New', monospace;
    font-size: 0.82rem;
    color: var(--primary);
    font-weight: 600;
    letter-spacing: 0.05em;
}

.td-bold {
    font-weight: 600;
}

.td-actions {
    display: flex;
    gap: 0.35rem;
    align-items: center;
}

.td-actions .btn-icon:hover {
    background: var(--primary-glow);
    color: var(--primary);
}

/* ---- Toolbar (search + filters) ---- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.1rem;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 200px;
    max-width: 380px;
}

.search-box .search-icon {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.85rem;
    pointer-events: none;
}

.search-box input {
    width: 100%;
    padding: 0.58rem 0.9rem 0.58rem 2.2rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--surface-card);
    transition: var(--transition);
    outline: none;
}

.search-box input:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.filter-select {
    padding: 0.58rem 2rem 0.58rem 0.85rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-family: inherit;
    color: var(--text-secondary);
    background: var(--surface-card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 0.6rem center;
    cursor: pointer;
    outline: none;
    appearance: none;
    transition: var(--transition);
}

.filter-select:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

/* ---- Pagination ---- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: between;
    gap: 0.35rem;
    margin-top: 1.25rem;
    flex-wrap: wrap;
}

.pagination-info {
    font-size: 0.8rem;
    color: var(--text-muted);
    flex: 1;
}

.pag-btn {
    width: 34px;
    height: 34px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-card);
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    font-family: inherit;
}

.pag-btn:hover {
    border-color: var(--primary-light);
    color: var(--primary-light);
}

.pag-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.pag-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    backdrop-filter: blur(3px);
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--surface-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-modal);
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideDown 0.25s ease;
}

.modal-sm {
    max-width: 400px;
}

.modal-md {
    max-width: 520px;
}

.modal-lg {
    max-width: 660px;
}

.modal-header {
    padding: 1.25rem 1.5rem 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.modal-header h3 {
    flex: 1;
}

.modal-close {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.modal-close:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

.modal-body {
    padding: 1.25rem 1.5rem;
}

.modal-footer {
    padding: 0 1.5rem 1.5rem;
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* Danger Modal Accent */
.modal-danger .modal-header {
    border-top: 3px solid var(--danger);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.modal-warning .modal-header {
    border-top: 3px solid var(--warning);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

/* ---- Toast Notifications ---- */
#toast-container {
    position: fixed;
    top: calc(var(--header-h) + 0.75rem);
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 360px;
    width: calc(100% - 2rem);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    background: var(--surface-card);
    border: 1px solid var(--border);
    pointer-events: all;
    animation: slideInRight 0.35s ease;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.toast::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
}

.toast-success::before {
    background: var(--success);
}

.toast-error::before {
    background: var(--danger);
}

.toast-warning::before {
    background: var(--warning);
}

.toast-info::before {
    background: var(--primary-light);
}

.toast-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-top: 0.05rem;
}

.toast-success .toast-icon {
    color: var(--success);
}

.toast-error .toast-icon {
    color: var(--danger);
}

.toast-warning .toast-icon {
    color: var(--warning);
}

.toast-info .toast-icon {
    color: var(--primary-light);
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.toast-msg {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 0.1rem;
}

.toast-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 0.1rem 0.2rem;
    border-radius: 3px;
    transition: var(--transition);
    flex-shrink: 0;
}

.toast-close:hover {
    color: var(--text-primary);
    background: var(--surface);
}

.toast.removing {
    animation: slideInRight 0.2s ease reverse;
    opacity: 0;
}

/* ---- Stat Card (Dashboard) ---- */
.stat-card {
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 1.35rem 1.5rem;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    transition: var(--transition);
    cursor: default;
}

.stat-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.stat-info {}

.stat-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1.2;
    margin-top: 0.15rem;
    color: var(--text-primary);
}

.stat-change {
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

.stat-change.up {
    color: var(--success);
}

.stat-change.down {
    color: var(--danger);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    flex-shrink: 0;
}

/* ---- Detail Row ---- */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.25rem;
}

.detail-item {}

.detail-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.detail-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.detail-value.mono {
    font-family: 'Courier New', monospace;
    font-size: 0.83rem;
    color: var(--primary);
    letter-spacing: 0.04em;
}

/* ---- Timeline / Activity Feed ---- */
.activity-feed {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.activity-item {
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--border);
    transition: var(--transition);
}

.activity-item:last-child {
    border-bottom: none;
}

.activity-item:hover {
    background: var(--surface);
    margin: 0 -1rem;
    padding-left: 1rem;
    padding-right: 1rem;
    border-radius: var(--radius-sm);
}

.activity-dot {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.activity-content {
    flex: 1;
}

.activity-action {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.activity-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
}

/* ---- Key Success Display ---- */
.key-success-box {
    background: linear-gradient(135deg, #F0FDF4, #DCFCE7);
    border: 1.5px solid #86EFAC;
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    text-align: center;
}

.key-success-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.key-value {
    background: white;
    border: 1.5px solid #86EFAC;
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    font-family: 'Courier New', monospace;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--primary);
    margin: 0.75rem 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.copy-btn {
    background: var(--primary-glow);
    border: none;
    border-radius: 4px;
    padding: 0.3rem 0.5rem;
    cursor: pointer;
    color: var(--primary);
    font-size: 0.75rem;
    transition: var(--transition);
}

.copy-btn:hover {
    background: var(--primary);
    color: white;
}

/* ---- Checkbox ---- */
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    font-size: 0.855rem;
}

.checkbox-item input[type=checkbox] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}

/* ---- Tabs ---- */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1.5rem;
}

.tab-btn {
    padding: 0.65rem 1.2rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--primary-light);
    border-bottom-color: var(--primary-light);
}

/* ---- Chips (Duration quick select) ---- */
.chip-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.chip {
    padding: 0.35rem 0.85rem;
    border-radius: 99px;
    border: 1.5px solid var(--border);
    background: var(--surface-card);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
    font-family: inherit;
}

.chip:hover {
    border-color: var(--primary-light);
    color: var(--primary-light);
}

.chip.selected {
    border-color: var(--primary);
    background: var(--primary-glow);
    color: var(--primary);
}

/* ---- Loading Spinner ---- */
.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid var(--border);
    border-top-color: var(--primary-light);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
}

.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    gap: 0.75rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .toolbar {
        gap: 0.5rem;
    }

    .search-box {
        max-width: 100%;
    }

    .detail-grid {
        grid-template-columns: 1fr 1fr;
    }

    .modal-footer {
        flex-direction: column-reverse;
    }

    .modal-footer .btn {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .stat-value {
        font-size: 1.6rem;
    }
}