/* ============================================================
   style.css — Alpha Monitor Web Edition
   Catppuccin Latte (Light) / Mocha (Dark) Dual-Theme
   ============================================================ */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* --- CSS Custom Properties (Design Tokens) --- */
/* DEFAULT: Catppuccin Latte (Light Theme) */
:root {
    --crust:    #dce0e8;
    --mantle:   #e6e9ef;
    --base:     #eff1f5;
    --surface0: #ccd0da;
    --surface1: #bcc0cc;
    --surface2: #acb0be;
    --overlay0: #9ca0b0;
    --overlay1: #8c8fa1;
    --text:     #4c4f69;
    --subtext0: #6c6f85;
    --subtext1: #5c5f77;
    --lavender: #7287fd;
    --blue:     #1e66f5;
    --sapphire: #209fb5;
    --sky:      #04a5e5;
    --teal:     #179299;
    --green:    #40a02b;
    --yellow:   #df8e1d;
    --peach:    #fe640b;
    --maroon:   #e64553;
    --red:      #d20f39;
    --mauve:    #8839ef;
    --pink:     #ea76cb;
    --flamingo: #dd7878;
    --rosewater:#dc8a78;

    /* Semantic Colors */
    --bg-primary:    var(--base);
    --bg-secondary:  var(--mantle);
    --bg-elevated:   var(--surface0);
    --border-color:  var(--surface1);
    --text-primary:  var(--text);
    --text-secondary:var(--subtext0);
    --accent:        var(--blue);
    --accent-glow:   rgba(30, 102, 245, 0.12);

    /* Alert Row Colors */
    --alert-price-bg:   rgba(210, 15, 57, 0.1);
    --alert-price-fg:   var(--red);
    --alert-volume-bg:  rgba(223, 142, 29, 0.1);
    --alert-volume-fg:  var(--yellow);
    --alert-both-bg:    rgba(136, 57, 239, 0.1);
    --alert-both-fg:    var(--mauve);
    --safe-entry-bg:    rgba(64, 160, 43, 0.1);
    --safe-entry-fg:    var(--green);
    --disabled-bg:      var(--mantle);
    --disabled-fg:      var(--overlay0);

    /* Layout */
    --header-height: 56px;
    --toolbar-height: 48px;
    --log-height: 200px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* DARK: Catppuccin Mocha */
[data-theme="dark"] {
    --crust:    #11111b;
    --mantle:   #181825;
    --base:     #1e1e2e;
    --surface0: #313244;
    --surface1: #45475a;
    --surface2: #585b70;
    --overlay0: #6c7086;
    --overlay1: #7f849c;
    --text:     #cdd6f4;
    --subtext0: #a6adc8;
    --subtext1: #bac2de;
    --lavender: #b4befe;
    --blue:     #89b4fa;
    --sapphire: #74c7ec;
    --sky:      #89dceb;
    --teal:     #94e2d5;
    --green:    #a6e3a1;
    --yellow:   #f9e2af;
    --peach:    #fab387;
    --maroon:   #eba0ac;
    --red:      #f38ba8;
    --mauve:    #cba6f7;
    --pink:     #f5c2e7;
    --flamingo: #f2cdcd;
    --rosewater:#f5e0dc;

    --accent-glow:   rgba(137, 180, 250, 0.15);

    --alert-price-bg:   rgba(69, 26, 36, 0.6);
    --alert-price-fg:   var(--red);
    --alert-volume-bg:  rgba(68, 58, 26, 0.6);
    --alert-volume-fg:  var(--yellow);
    --alert-both-bg:    rgba(59, 36, 71, 0.6);
    --alert-both-fg:    var(--mauve);
    --safe-entry-bg:    rgba(32, 56, 43, 0.6);
    --safe-entry-fg:    var(--green);
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--crust);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: background 0.3s ease, color 0.3s ease;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--mantle); }
::-webkit-scrollbar-thumb { background: var(--surface1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--surface2); }

/* --- Header Bar --- */
.header {
    height: var(--header-height);
    background: linear-gradient(135deg, var(--mantle) 0%, var(--base) 100%);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
    flex-shrink: 0;
    position: relative;
    z-index: 100;
}

.header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: 0.4;
}

.header-logo {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.5px;
}

.header-logo .version {
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--overlay1);
    background: var(--surface0);
    padding: 2px 8px;
    border-radius: 10px;
}

/* --- Toolbar --- */
.toolbar {
    height: var(--toolbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 8px;
    flex-shrink: 0;
}

.toolbar-separator {
    width: 1px;
    height: 24px;
    background: var(--surface1);
    margin: 0 8px;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn:hover {
    background: var(--surface1);
    border-color: var(--surface2);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--accent);
    color: var(--crust);
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--lavender);
    border-color: var(--lavender);
}

.btn-success {
    background: rgba(166, 227, 161, 0.15);
    color: var(--green);
    border-color: rgba(166, 227, 161, 0.3);
}

.btn-success:hover {
    background: rgba(166, 227, 161, 0.25);
}

.btn-danger {
    background: rgba(243, 139, 168, 0.15);
    color: var(--red);
    border-color: rgba(243, 139, 168, 0.3);
}

.btn-danger:hover {
    background: rgba(243, 139, 168, 0.25);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

/* Pulse animation for running state */
@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(166, 227, 161, 0.4); }
    50% { box-shadow: 0 0 0 6px rgba(166, 227, 161, 0); }
}

.btn-running {
    animation: pulse-glow 2s ease-in-out infinite;
}

/* --- Status Indicator --- */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--overlay1);
    margin-left: auto;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--overlay0);
    transition: background var(--transition-normal);
}

.status-dot.active {
    background: var(--green);
    box-shadow: 0 0 8px rgba(166, 227, 161, 0.5);
}

/* --- Main Table Area --- */
.table-container {
    flex: 1;
    overflow: auto;
    padding: 8px;
    min-height: 0;
}

.monitor-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.82rem;
}

.monitor-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.monitor-table th {
    background: var(--mantle);
    color: var(--red);
    font-weight: 600;
    font-size: 0.78rem;
    padding: 8px 10px;
    text-align: center;
    border-bottom: 2px solid var(--surface0);
    white-space: nowrap;
    user-select: none;
    letter-spacing: 0.3px;
}

.monitor-table th:first-child { text-align: center; }
.monitor-table th:nth-child(2) { text-align: left; }

.monitor-table td {
    padding: 7px 10px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition-fast), color var(--transition-fast);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.monitor-table td:first-child { text-align: center; }
.monitor-table td:nth-child(2) { 
    text-align: left; 
    font-weight: 600;
}
.monitor-table td:nth-child(3),
.monitor-table td:nth-child(8) { 
    text-align: right; 
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
}

.monitor-table tbody tr {
    cursor: pointer;
    transition: background var(--transition-fast);
}

.monitor-table tbody tr:hover {
    background: rgba(137, 180, 250, 0.06) !important;
}

/* Row Alert Tags */
.monitor-table tbody tr.alert-price {
    background: var(--alert-price-bg);
    color: var(--alert-price-fg);
}

.monitor-table tbody tr.alert-volume {
    background: var(--alert-volume-bg);
    color: var(--alert-volume-fg);
}

.monitor-table tbody tr.alert-both {
    background: var(--alert-both-bg);
    color: var(--alert-both-fg);
}

.monitor-table tbody tr.safe-entry {
    background: var(--safe-entry-bg);
    color: var(--safe-entry-fg);
}

.monitor-table tbody tr.disabled-row {
    background: var(--disabled-bg);
    color: var(--disabled-fg);
}

@keyframes row-flash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.monitor-table tbody tr.flash {
    animation: row-flash 0.5s ease 2;
}

/* Enable/Disable Toggle */
.enable-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.9rem;
    transition: all var(--transition-fast);
}

.enable-toggle.on {
    color: var(--green);
    background: rgba(166, 227, 161, 0.1);
}

.enable-toggle.off {
    color: var(--overlay0);
    background: rgba(108, 112, 134, 0.1);
}

/* Stability cell special styling */
.stability-stable {
    color: var(--green) !important;
    font-weight: 600;
}

.stability-unstable {
    color: var(--red) !important;
}

.stability-counting {
    color: var(--yellow) !important;
}

/* --- Log Panel --- */
.log-panel {
    height: var(--log-height);
    background: var(--crust);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.log-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px;
    background: var(--mantle);
    border-bottom: 1px solid rgba(49, 50, 68, 0.5);
}

.log-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--sapphire);
    letter-spacing: 1px;
}

.log-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    line-height: 1.6;
    color: var(--green);
}

.log-content .log-line {
    opacity: 0;
    animation: log-appear 0.3s ease forwards;
}

@keyframes log-appear {
    from { opacity: 0; transform: translateX(-8px); }
    to { opacity: 1; transform: translateX(0); }
}

.log-content .log-time {
    color: var(--overlay1);
}

.log-content .log-alert {
    color: var(--red);
    font-weight: 500;
}

.log-content .log-restore {
    color: var(--teal);
}

/* --- Modal Dialog --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 580px;
    max-width: 95vw;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5), 0 0 1px 0 var(--accent);
    transform: translateY(20px) scale(0.96);
    transition: transform var(--transition-normal);
}

.modal-overlay.active .modal {
    transform: translateY(0) scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--surface0);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--surface1);
    color: var(--red);
}

.modal-body {
    padding: 20px 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* --- Form Elements --- */
.form-group {
    margin-bottom: 14px;
}

.form-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.form-label {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--subtext1);
    min-width: 110px;
    flex-shrink: 0;
}

.form-input {
    background: var(--mantle);
    border: 1px solid var(--surface1);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    padding: 7px 12px;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    width: 100%;
}

.form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-input-sm {
    width: 80px;
}

.form-input-md {
    width: 140px;
}

.form-select {
    background: var(--mantle);
    border: 1px solid var(--surface1);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    padding: 7px 12px;
    outline: none;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.form-select:focus {
    border-color: var(--accent);
}

.form-hint {
    font-size: 0.72rem;
    color: var(--overlay0);
    margin-top: 4px;
}

/* Toggle Switch */
.toggle-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.toggle-switch input {
    display: none;
}

.toggle-track {
    width: 36px;
    height: 20px;
    background: var(--surface1);
    border-radius: 10px;
    position: relative;
    transition: background var(--transition-fast);
}

.toggle-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: var(--text-primary);
    border-radius: 50%;
    transition: transform var(--transition-fast);
}

.toggle-switch input:checked + .toggle-track {
    background: var(--green);
}

.toggle-switch input:checked + .toggle-track::after {
    transform: translateX(16px);
}

.toggle-label {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

/* Section divider */
.section-divider {
    border: none;
    border-top: 1px solid var(--surface0);
    margin: 18px 0;
}

.section-title {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-title::before {
    content: '';
    width: 3px;
    height: 14px;
    background: var(--accent);
    border-radius: 2px;
}

/* --- Settings Panel (Collapsible Sections) --- */
.settings-section {
    background: var(--mantle);
    border: 1px solid var(--surface0);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    overflow: hidden;
}

.settings-section-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
    transition: background var(--transition-fast);
}

.settings-section-header:hover {
    background: var(--surface0);
}

.settings-section-header h3 {
    font-size: 0.85rem;
    font-weight: 600;
    flex: 1;
}

.settings-section-body {
    padding: 0 16px 16px;
}

/* --- Context Menu (Right-Click) --- */
.context-menu {
    position: fixed;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 4px;
    min-width: 150px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 2000;
    display: none;
}

.context-menu.visible {
    display: block;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 4px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background var(--transition-fast);
    color: var(--text-primary);
}

.context-menu-item:hover {
    background: var(--surface0);
}

.context-menu-item.danger {
    color: var(--red);
}

.context-menu-divider {
    height: 1px;
    background: var(--surface0);
    margin: 4px 0;
}

/* --- Drag & Drop --- */
.monitor-table tbody tr.dragging {
    opacity: 0.4;
    background: var(--surface0) !important;
}

.monitor-table tbody tr.drag-over {
    border-top: 2px solid var(--accent) !important;
}

/* --- Empty State --- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--overlay0);
    text-align: center;
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state-text {
    font-size: 0.95rem;
    margin-bottom: 8px;
}

.empty-state-hint {
    font-size: 0.8rem;
    color: var(--surface2);
}

/* --- Toast Notifications --- */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 20px;
    font-size: 0.82rem;
    color: var(--text-primary);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    animation: toast-in 0.3s ease, toast-out 0.3s ease 2.7s forwards;
    max-width: 320px;
}

.toast.toast-success { border-left: 3px solid var(--green); }
.toast.toast-error   { border-left: 3px solid var(--red); }
.toast.toast-info    { border-left: 3px solid var(--blue); }

@keyframes toast-in {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}

@keyframes toast-out {
    from { opacity: 1; }
    to   { opacity: 0; transform: translateX(30px); }
}

/* --- Row Action Delete Button --- */
.row-delete-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: var(--overlay0);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all var(--transition-fast);
    opacity: 0;
}

.monitor-table tbody tr:hover .row-delete-btn {
    opacity: 1;
}

.row-delete-btn:hover {
    background: rgba(210, 15, 57, 0.15);
    color: var(--red);
}

/* --- Theme Toggle Button --- */
.theme-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.1rem;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.theme-toggle:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    transform: rotate(20deg);
}

/* Log panel light-mode adjustments */
:root .log-content {
    color: var(--teal);
}

[data-theme="dark"] .log-content {
    color: var(--green);
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .header { padding: 0 12px; }
    .toolbar { overflow-x: auto; }
    .modal { width: 95vw; }
    .form-label { min-width: 90px; }
}
