/* client/css/alert.css */

/* Right Sidebar Alert Panel (shares structure with Watchlist) */
.tv-alert-panel {
    width: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 10;
}

.tv-alert-panel.open {
    width: 400px;
}

.tv-alert-resizer {
    position: absolute;
    top: 0;
    left: -3px;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 20;
}

.alert-panel-header {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-color);
    background-color: rgba(20, 22, 26, 0.95);
}

.alert-panel-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-normal);
}

.alert-header-actions {
    display: flex;
    gap: 4px;
}

.alert-header-btn {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.alert-header-btn:hover {
    background: var(--bg-hover);
    color: var(--text-normal);
}

.alert-panel-body {
    flex: 1;
    overflow-y: auto;
}

/* Alert Items */
.alert-list {
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 8px;
}

.alert-item {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px;
    position: relative;
    transition: border-color 0.2s;
}

.alert-item:hover {
    border-color: rgba(255, 255, 255, 0.15);
}

.alert-item.status-active {
    border-left: 3px solid var(--green);
}

.alert-item.status-triggered {
    border-left: 3px solid var(--orange);
}

.alert-item.status-paused {
    border-left: 3px solid var(--text-muted);
}

.alert-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.alert-symbol {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-normal);
}

.alert-status-badge {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 10px;
    text-transform: uppercase;
    font-weight: 600;
}

.alert-item.status-active .alert-status-badge {
    background: rgba(38, 166, 154, 0.15);
    color: var(--green);
}

.alert-item.status-triggered .alert-status-badge {
    background: rgba(255, 152, 0, 0.15);
    color: var(--orange);
}

.alert-item.status-paused .alert-status-badge {
    background: rgba(120, 123, 134, 0.15);
    color: var(--text-muted);
}

.alert-condition {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.alert-condition strong {
    color: var(--text-normal);
}

.alert-actions {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 8px;
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
}

.alert-btn {
    padding: 4px 8px;
    font-size: 0.75rem;
    border-radius: 4px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.alert-btn:hover {
    background: var(--bg-hover);
    color: var(--text-normal);
}

.alert-btn.delete:hover {
    color: var(--red);
    background: rgba(239, 83, 80, 0.1);
}

.empty-alerts {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
    height: 100%;
}

.empty-alerts svg {
    margin-bottom: 12px;
    opacity: 0.5;
}

/* Modal Dialog */
.alert-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.alert-modal-overlay.show {
    display: flex;
}

.alert-modal {
    background: #1e222d;
    border: 1px solid #2a2e39;
    border-radius: 8px;
    width: 440px;
    max-width: 90vw;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    color: #d1d4dc;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.alert-modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #2a2e39;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.alert-modal-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 500;
    color: #d1d4dc;
}

.alert-modal-close {
    background: transparent;
    border: none;
    color: #787b86;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

.alert-modal-close:hover {
    color: #d1d4dc;
    background: #2a2e39;
}

.alert-modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 16px;
    align-items: start;
}

.form-group label {
    font-size: 13px;
    color: #787b86;
    margin-top: 9px;
    font-weight: 500;
}

.form-group-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.alert-modal input[type="text"],
.alert-modal input[type="number"],
.alert-modal input[type="datetime-local"],
.alert-modal select,
.alert-modal textarea {
    width: 100%;
    min-height: 38px;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid #2a2e39;
    background: #131722;
    color: #d1d4dc;
    font-size: 13px;
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.alert-modal input:focus,
.alert-modal select:focus,
.alert-modal textarea:focus {
    border-color: #2962ff;
    box-shadow: 0 0 0 2px rgba(41, 98, 255, 0.2);
}

.alert-modal select {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23787b86%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 12px top 50%;
    background-size: 10px auto;
    padding-right: 32px;
}

.alert-modal input[type="datetime-local"] {
    position: relative;
    display: flex;
    align-items: center;
    color-scheme: dark;
    cursor: pointer;
    padding-right: 36px;
}

.alert-modal input[type="datetime-local"]::-webkit-datetime-edit {
    flex: 1;
    display: inline-flex;
}

.alert-modal input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    filter: invert(0.6);
    opacity: 0.8;
    transition: opacity 0.2s;
    padding: 0;
    margin: 0;
}

.alert-modal input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

.alert-modal textarea {
    resize: vertical;
    min-height: 60px;
}

.alert-modal-footer {
    padding: 16px 20px;
    border-top: 1px solid #2a2e39;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.alert-btn-cancel,
.alert-btn-save {
    padding: 8px 24px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.alert-btn-cancel {
    background: transparent;
    color: #d1d4dc;
}

.alert-btn-cancel:hover {
    background: #2a2e39;
}

.alert-btn-save {
    background: #2962ff;
    color: white;
}

.alert-btn-save:hover {
    background: #1e53e5;
}

/* Toast */
/* ── Alert Toast — TradingView style ── */
.alert-toast-container {
    position: fixed;
    bottom: 24px;
    left: 24px;
    display: flex;
    flex-direction: column-reverse;  /* newest on bottom */
    gap: 10px;
    z-index: 99999;
    pointer-events: auto;
    max-width: 360px;
}

.alert-toast {
    background: #1e222d;
    border: 1px solid #2a2e39;
    color: #d1d4dc;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    width: 340px;
    pointer-events: none;
    animation: toast-slide-up 0.28s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
    overflow: hidden;
}

.alert-toast.hiding {
    animation: toast-slide-down 0.22s ease-in forwards;
}

/* Inner layout: icon | body */
.alert-toast-inner {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 14px 12px 14px;
}

/* Bell icon circle */
.alert-toast-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #1565c0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    margin-top: 1px;
}

.alert-toast-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Header row: "Cảnh báo về" + symbol chip + ✕ */
.alert-toast-header {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
}

.alert-toast-heading {
    font-size: 0.82rem;
    color: #787b86;
    white-space: nowrap;
    flex-shrink: 0;
}

.alert-toast-chip {
    font-size: 0.8rem;
    font-weight: 700;
    color: #d1d4dc;
    background: #2a2e39;
    border-radius: 4px;
    padding: 1px 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 130px;
}

.alert-toast-close {
    margin-left: auto;
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: #787b86;
    padding: 2px;
    display: flex;
    align-items: center;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}
.alert-toast-close:hover {
    color: #d1d4dc;
    background: #2a2e39;
}

/* Body message */
.alert-toast-msg {
    font-size: 0.88rem;
    color: #d1d4dc;
    font-weight: 500;
    line-height: 1.3;
    word-break: break-word;
}

/* Footer: link + timestamp */
.alert-toast-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 2px;
}

.alert-toast-link {
    font-size: 0.78rem;
    color: #2962ff;
    text-decoration: none;
    white-space: nowrap;
}
.alert-toast-link:hover {
    text-decoration: underline;
    color: #5b8df5;
}

.alert-toast-time {
    font-size: 0.75rem;
    color: #787b86;
    white-space: nowrap;
}

@keyframes toast-slide-up {
    from { transform: translateY(24px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}
@keyframes toast-slide-down {
    from { transform: translateY(0);    opacity: 1; }
    to   { transform: translateY(24px); opacity: 0; }
}


/* --------------------------------------------------- */
/* Tích hợp Giao diện Y-Axis chuẩn TradingView         */
/* --------------------------------------------------- */

.tv-alert-add-btn {
    position: absolute;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background-color: #2a2e39;
    border: 1px solid #787b86;
    color: #d1d4dc;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100;
    pointer-events: auto;
    transform: translateY(-50%); 
    transition: background-color 0.1s, border-color 0.1s;
    font-size: 16px;
    font-weight: 300;
    line-height: 1;
    user-select: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.tv-alert-add-btn svg {
    pointer-events: none;
}

.tv-alert-add-btn:hover {
    background-color: #363a45;
    border-color: #d1d4dc;
    color: white;
}

.tv-alert-price-label {
    position: absolute;
    left: 20px; /* Aligns exactly with the price scale when button x offset is 20 */
    top: 50%;
    transform: translateY(-50%);
    background-color: #2962FF;
    color: white;
    padding: 3px 6px;
    font-size: 12px;
    font-family: -apple-system, BlinkMacSystemFont, "Trebuchet MS", Roboto, Ubuntu, sans-serif;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.1s ease;
}

.tv-alert-price-label::before {
    content: '';
    position: absolute;
    left: -4px;
    top: 50%;
    transform: translateY(-50%);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-right: 4px solid #2962FF;
}

.tv-alert-add-btn:hover .tv-alert-price-label {
    opacity: 1;
}

/* Pseudo-element to simulate the crosshair dashed line when hovering over the plus button */
.tv-alert-add-btn::before {
    content: '';
    position: absolute;
    right: 100%; /* Start from left edge of the plus button */
    top: 50%;
    width: 3000px; /* Stretch across the entire chart */
    border-top: 1px dashed #787b86;
    pointer-events: none;
    z-index: -1;
    display: none;
}

.tv-alert-add-btn:hover::before {
    display: block;
}

.tv-alert-context-menu {
    position: absolute;
    background: #1e222d;
    border: 1px solid #2a2e39;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    z-index: 1000;
    min-width: 280px;
    padding: 8px 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.tv-alert-context-item {
    padding: 8px 16px;
    font-size: 13px;
    color: #d1d4dc;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
}

.tv-alert-context-item:not(.disabled):hover {
    background: #2962ff;
    color: white;
}

.tv-alert-context-item svg {
    width: 16px;
    height: 16px;
    opacity: 0.7;
    flex-shrink: 0;
}

.tv-alert-context-item:not(.disabled):hover svg {
    opacity: 1;
}

.tv-alert-context-item.disabled {
    cursor: default;
    opacity: 0.5;
}

.tv-alert-shortcut {
    color: #787b86;
    font-size: 12px;
    margin-left: auto;
    padding-left: 16px;
}

.tv-alert-context-item:not(.disabled):hover .tv-alert-shortcut {
    color: rgba(255, 255, 255, 0.7);
}

.tv-alert-context-divider {
    height: 1px;
    background: #2a2e39;
    margin: 6px 0;
}

/* --------------------------------------------------- */
/* Tích hợp Giao diện Alert Panel chuẩn TradingView    */
/* --------------------------------------------------- */
.alert-panel-header-tv {
    background-color: #1e222d;
    border-bottom: 1px solid #2a2e39;
}

.alert-tabs {
    display: flex;
    padding: 8px 12px;
    gap: 8px;
    border-bottom: 1px solid #2a2e39;
}

.alert-tab {
    flex: 1;
    background: transparent;
    border: 1px solid transparent;
    color: #787b86;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

.alert-tab:hover {
    background: #2a2e39;
    color: #d1d4dc;
}

.alert-tab.active {
    background: #2a2e39;
    border: 1px solid #2962ff;
    color: #d1d4dc;
}

.log-badge {
    background: #f44336;
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 4px;
}

.alert-toolbar {
    display: flex;
    justify-content: space-between;
    padding: 4px 8px;
}

.toolbar-btn {
    background: transparent;
    border: none;
    color: #787b86;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
}

.toolbar-btn:hover {
    color: #d1d4dc;
    background: #2a2e39;
}

.alert-item {
    padding: 10px 12px;
    border-bottom: 1px solid #2a2e39;
    position: relative;
    cursor: default;
}

.alert-item:hover {
    background: #2a2e39;
}

.alert-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.alert-item-title {
    font-size: 13px;
    color: #d1d4dc;
    font-weight: 400;
}

.alert-item-subtitle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #787b86;
}

.alert-coin-icon-wrap {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    overflow: hidden;
}

.alert-coin-logo {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.alert-coin-icon {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #6366f1;
    color: white;
    font-size: 9px;
    font-weight: 700;
    line-height: 1;
}

.alert-modal-coin-logo-wrap {
    display: inline-flex;
    vertical-align: middle;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    overflow: hidden;
    margin-left: 6px;
    margin-right: 4px;
}

.alert-modal-coin-logo {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.alert-coin-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

.alert-status-text {
    color: #00c853; /* Active green */
}

.status-paused .alert-status-text {
    color: #ff9800; /* Paused orange */
}

.status-triggered .alert-status-text {
    color: #ff9800;
}

.alert-item-actions {
    display: none;
    gap: 4px;
}

.alert-item:hover .alert-item-actions {
    display: flex;
}

.alert-icon-btn {
    background: transparent;
    border: none;
    color: #787b86;
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.alert-icon-btn:hover {
    color: #d1d4dc;
    background: #363a45;
}

.alert-icon-btn svg {
    width: 16px;
    height: 16px;
}

.alert-icon-btn.delete:hover {
    color: #f44336;
}

/* Alert Item Tooltip */
.alert-item-tooltip {
    display: none;
    position: absolute;
    left: -230px;
    top: 0;
    width: 220px;
    background: #1e222d;
    border: 1px solid #2a2e39;
    padding: 12px;
    border-radius: 6px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    color: #d1d4dc;
}
.alert-item {
    position: relative;
}
.alert-item:hover .alert-item-tooltip {
    display: block;
}

/* Shared Hover Tooltip for Alerts */
.alert-hover-tooltip {
    display: none;
    position: fixed;
    z-index: 99999;
    width: 260px;
    background: #1e222d;
    border: 1px solid #2a2e39;
    border-radius: 6px;
    padding: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    color: #d1d4dc;
    pointer-events: none;
}

/* ── Light Theme Overrides for Alert Panel ───────────────────── */
body[data-theme="light"] .tv-alert-panel,
body[data-theme="light"] .alert-panel-tv,
body[data-theme="light"] #proAlertPanel,
body[data-theme="light"] #chartsAlertPanel,
body[data-theme="light"] #mtfAlertList {
    background-color: #ffffff !important;
    border-left-color: #e0e3eb !important;
    color: #131722 !important;
}

body[data-theme="light"] .alert-panel-header-tv,
body[data-theme="light"] .alert-toolbar,
body[data-theme="light"] .logs-toolbar,
body[data-theme="light"] .alert-tabs {
    background-color: #ffffff !important;
    border-bottom-color: #e0e3eb !important;
}

body[data-theme="light"] .alert-tab {
    color: #787b86 !important;
    background: transparent !important;
    border-color: transparent !important;
}

body[data-theme="light"] .alert-tab:hover {
    background: #f0f3fa !important;
    color: #131722 !important;
}

body[data-theme="light"] .alert-tab.active {
    background: #f0f3fa !important;
    border-color: #2962ff !important;
    color: #2962ff !important;
}

body[data-theme="light"] .alert-item,
body[data-theme="light"] .log-item {
    background: #ffffff !important;
    border-color: #e0e3eb !important;
    color: #131722 !important;
}

body[data-theme="light"] .alert-item:hover,
body[data-theme="light"] .log-item:hover {
    background: #f0f3fa !important;
}

body[data-theme="light"] .alert-item-title {
    color: #131722 !important;
}

body[data-theme="light"] .alert-item-subtitle {
    color: #787b86 !important;
}

body[data-theme="light"] .log-date-header {
    color: #787b86 !important;
}

body[data-theme="light"] .toolbar-btn,
body[data-theme="light"] .alert-icon-btn {
    color: #787b86 !important;
}

body[data-theme="light"] .toolbar-btn:hover,
body[data-theme="light"] .alert-icon-btn:hover {
    color: #131722 !important;
    background: #e0e3eb !important;
}

body[data-theme="light"] .alert-hover-tooltip,
body[data-theme="light"] .alert-item-tooltip {
    background: #ffffff !important;
    border-color: #e0e3eb !important;
    color: #131722 !important;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12) !important;
}

