/* ============================================================
   Smart Pool Robot — Jupiter-inspired UI
   ============================================================ */

:root {
    --bg: #f2f3f7;
    --bg-secondary: #e6e8ef;
    --card: #ffffff;
    --text: #0f1724;
    --text-secondary: #5c6378;
    --text-tertiary: #8e95a9;
    --border: rgba(0,0,0,0.06);
    --border-card: rgba(0,0,0,0.04);

    --green: #22c55e;
    --green-dark: #16a34a;
    --green-bg: rgba(34,197,94,0.1);
    --green-bg-solid: #ecfdf5;
    --red: #ef4444;
    --red-bg: rgba(239,68,68,0.07);
    --amber: #f59e0b;
    --amber-bg: rgba(245,158,11,0.08);

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 0 0 1px var(--border-card);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.1);

    --radius: 10px;
    --radius-sm: 8px;
    --radius-xs: 6px;

    --font: 'Overpass', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --mono: 'Overpass', 'SF Mono', 'Cascadia Code', monospace;

    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior: none;
    min-height: 100%;
}

/* ---- Layout ---- */

#app {
    max-width: 420px;
    margin: 0 auto;
    padding: var(--sat) 14px calc(80px + var(--sab));
}
.page { display: none; }
.page.active { display: block; }

/* ---- Header ---- */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0 10px;
    z-index: 10;
    background: var(--bg);
}
.header-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.5px;
}

/* ---- Alert banner ---- */

.alert-banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    font-size: 12px;
    line-height: 1.4;
    animation: alertIn .3s ease;
    transition: opacity .3s, transform .3s;
}
.alert-banner.hiding {
    opacity: 0;
    transform: translateY(-6px);
}
.alert-banner-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
}
.alert-banner-icon {
    flex-shrink: 0;
    width: 16px; height: 16px;
    margin-top: 1px;
}
.alert-banner-body { flex: 1; min-width: 0; }
.alert-banner-title { font-weight: 700; font-size: 12px; margin-bottom: 1px; }
.alert-banner-text { opacity: 0.8; font-size: 11px; word-break: break-all; }
.alert-banner-close {
    flex-shrink: 0;
    width: 20px; height: 20px;
    display: flex; align-items: center; justify-content: center;
    border: none; background: none;
    cursor: pointer; color: inherit; opacity: 0.5;
    border-radius: 4px; transition: opacity .15s;
}
.alert-banner-close:hover { opacity: 1; }
.alert-banner-close svg { width: 14px; height: 14px; }

@keyframes alertIn { from { opacity:0; transform:translateY(-8px) } to { opacity:1; transform:translateY(0) } }

/* ---- Status badge ---- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}
.badge-green  { background: var(--green-bg); color: var(--green-dark); }
.badge-red    { background: var(--red-bg); color: var(--red); }
.badge-amber  { background: var(--amber-bg); color: var(--amber); }
.badge-muted  { background: var(--bg-secondary); color: var(--text-secondary); }

.badge-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}
.badge-green .badge-dot { background: var(--green); animation: pulse 2s infinite; }
.badge-red .badge-dot   { background: var(--red); }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ---- Hero / Balance ---- */

.hero {
    text-align: center;
    padding: 20px 0 22px;
}
.hero-price {
    font-size: 42px;
    font-weight: 900;
    font-family: var(--mono);
    letter-spacing: 0.5px;
    color: var(--text);
    line-height: 1;
}
.hero-sub {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 6px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.hero-badge {
    display: inline-block;
    margin-top: 10px;
}

/* ---- Quick actions ---- */

.quick-actions {
    display: flex;
    gap: 8px;
    padding-bottom: 16px;
}
.qa-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 4px 12px;
    background: var(--card);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all .15s;
    touch-action: manipulation;
    font-family: var(--font);
}
.qa-btn:active { transform: scale(0.95); }
.qa-btn:disabled { opacity: 0.3; pointer-events: none; }

.qa-icon {
    width: 36px; height: 36px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
}
.qa-icon.green { background: var(--green-bg-solid); color: var(--green-dark); }
.qa-icon.red   { background: rgba(239,68,68,0.08); color: var(--red); }
.qa-icon.gray  { background: var(--bg-secondary); color: var(--text-secondary); }
.qa-icon svg { width: 16px; height: 16px; }

.qa-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

/* ---- Portfolio breakdown ---- */

.breakdown {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
}
.breakdown-item {
    flex: 1;
    text-align: center;
    padding: 12px 4px;
    background: var(--card);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-sm);
}
.breakdown-item-label {
    font-size: 9px;
    color: var(--text-tertiary);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}
.breakdown-item-value {
    font-size: 15px;
    font-weight: 800;
    font-family: var(--mono);
    margin-top: 3px;
    letter-spacing: 0.3px;
}

/* ---- Cards ---- */

.card {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border-card);
    box-shadow: var(--shadow-sm);
    padding: 16px;
    margin-bottom: 10px;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.card-title {
    font-size: 15px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.2px;
}
.card-subtitle {
    font-size: 15px;
    color: var(--text);
    font-weight: 800;
    font-family: var(--mono);
    letter-spacing: 0.2px;
}

/* ---- Data rows ---- */

.row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}
.row + .row { border-top: 1px solid var(--border); }

.row-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}
.row-value {
    font-size: 13px;
    font-weight: 700;
    font-family: var(--mono);
    letter-spacing: 0.2px;
    text-align: right;
}
.row-value.green { color: var(--green-dark); }
.row-value.red   { color: var(--red); }
.row-value.amber { color: var(--amber); }

/* ---- Stat grid ---- */

.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.stat { display: flex; flex-direction: column; gap: 3px; }
.stat-label {
    font-size: 11px;
    color: var(--text-tertiary);
    font-weight: 600;
}
.stat-value {
    font-size: 16px;
    font-weight: 800;
    font-family: var(--mono);
    letter-spacing: 0.2px;
}
.stat-value.sm { font-size: 14px; font-weight: 700; }
.stat-value.green { color: var(--green-dark); }
.stat-value.red   { color: var(--red); }
.stat-value.amber { color: var(--amber); }

/* ---- Progress bar ---- */

.progress {
    height: 4px;
    background: var(--bg-secondary);
    border-radius: 2px;
    overflow: hidden;
    margin: 12px 0 6px;
}
.progress-fill {
    height: 100%;
    background: var(--green);
    border-radius: 2px;
    transition: width .6s ease;
}

/* ---- Range bar ---- */

.range-vis {
    position: relative;
    height: 28px;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin: 10px 0 6px;
    overflow: hidden;
}
.range-vis-fill {
    position: absolute;
    top: 0; bottom: 0;
    background: var(--green-bg-solid);
    border-radius: 8px;
}
.range-vis-marker {
    position: absolute;
    top: 5px; bottom: 5px;
    width: 3px;
    background: var(--green-dark);
    border-radius: 2px;
    z-index: 1;
    transition: left .4s ease;
}
.range-vis-label {
    position: absolute;
    top: 50%; transform: translateY(-50%);
    font-size: 10px;
    font-weight: 700;
    font-family: var(--mono);
    color: var(--text-secondary);
    pointer-events: none;
}
.range-vis-label.left  { left: 10px; }
.range-vis-label.right { right: 10px; }

.pool-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 3px 10px;
    border-radius: 6px;
}
.pool-status.in-range    { background: var(--green-bg); color: var(--green-dark); }
.pool-status.out-of-range { background: var(--red-bg); color: var(--red); }

/* ---- Buttons ---- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: all .15s;
    touch-action: manipulation;
    width: 100%;
    font-family: var(--font);
    letter-spacing: -0.1px;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--green-dark); }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: var(--bg-secondary); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: #d5d8e0; }

.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
    border-radius: var(--radius-xs);
    width: auto;
}
.btn-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 14px;
}

/* ---- Bottom nav ---- */

.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: rgba(255,255,255,0.95);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: center;
    padding: 8px 0 calc(4px + var(--sab));
    z-index: 100;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}
.nav-btn {
    flex: 1;
    max-width: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 4px 0;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: color .15s;
    border: none;
    background: none;
    touch-action: manipulation;
    font-family: var(--font);
    letter-spacing: 0.2px;
}
.nav-btn.active { color: var(--green-dark); }
.nav-btn svg { width: 22px; height: 22px; }

/* ---- Settings ---- */

.settings-section { margin-bottom: 8px; }
.settings-section-title {
    font-size: 11px;
    font-weight: 800;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 12px 4px 6px;
}
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }
.setting-info { flex: 1; min-width: 0; }
.setting-label { font-size: 14px; font-weight: 600; color: var(--text); }
.setting-desc { font-size: 11px; color: var(--text-tertiary); margin-top: 2px; line-height: 1.3; }

.setting-input {
    width: 80px;
    text-align: right;
    padding: 8px 10px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-xs);
    font-size: 14px;
    font-family: var(--mono);
    font-weight: 700;
    color: var(--text);
    background: var(--bg);
    transition: border-color .15s;
    flex-shrink: 0;
}
.setting-input:focus { outline: none; border-color: var(--green); }
.setting-input.wide { width: 100%; text-align: left; margin-top: 8px; font-size: 12px; }
.setting-row.col { flex-direction: column; align-items: stretch; }
#settingsContent { padding-bottom: 320px; }

.toggle {
    position: relative;
    width: 44px; height: 24px;
    flex-shrink: 0;
}
.toggle input { display: none; }
.toggle-track {
    position: absolute; inset: 0;
    background: #d1d5db;
    border-radius: 24px;
    cursor: pointer;
    transition: background .2s;
}
.toggle-track::before {
    content: '';
    position: absolute;
    width: 18px; height: 18px;
    left: 3px; top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform .2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.toggle input:checked + .toggle-track { background: var(--green); }
.toggle input:checked + .toggle-track::before { transform: translateX(20px); }

/* ---- Toast ---- */

.toast-container {
    position: fixed;
    top: calc(12px + var(--sat));
    left: 50%; transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
    max-width: 360px;
    width: calc(100% - 32px);
}
.toast {
    background: var(--text);
    color: #fff;
    padding: 11px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateY(-10px);
    animation: toastIn .25s ease forwards;
    pointer-events: auto;
}
.toast.success { background: var(--green-dark); }
.toast.error   { background: var(--red); }
@keyframes toastIn { to { opacity:1; transform:translateY(0) } }

/* ---- Spinner ---- */

.spinner {
    display: inline-block;
    width: 16px; height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform:rotate(360deg) } }
.spinner-lg { width: 24px; height: 24px; border-width: 2.5px; }

.loading-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 60px 20px;
    color: var(--text-tertiary);
    font-size: 13px;
    font-weight: 600;
}
.empty {
    text-align: center;
    padding: 24px;
    color: var(--text-secondary);
    font-size: 13px;
}

/* ---- Dialog ---- */

.dialog-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 200;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
}
.dialog-overlay.active { display: flex; }

.dialog {
    background: var(--card);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 24px 20px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0));
    width: 100%;
    max-width: 420px;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
}
.dialog h3 { font-size: 17px; font-weight: 800; margin-bottom: 6px; }
.dialog p { font-size: 13px; color: var(--text-secondary); margin-bottom: 16px; line-height: 1.5; }

/* ---- Action choice dialog ---- */

.action-choice-tabs {
    display: flex;
    background: var(--bg-secondary);
    border-radius: var(--radius-xs);
    padding: 3px;
    margin-bottom: 14px;
}
.action-tab {
    flex: 1;
    padding: 8px;
    border: none;
    background: none;
    border-radius: 5px;
    font-size: 13px;
    font-weight: 700;
    font-family: var(--font);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all .15s;
}
.action-tab.active {
    background: var(--card);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.action-panel { margin-top: 4px; }
.trigger-form { margin-bottom: 14px; }

.trigger-condition {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}
.cond-btn {
    flex: 1;
    padding: 9px;
    border: 1.5px solid var(--border);
    background: var(--bg);
    border-radius: var(--radius-xs);
    font-size: 13px;
    font-weight: 700;
    font-family: var(--font);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all .15s;
}
.cond-btn.active {
    border-color: var(--green);
    background: var(--green-bg);
    color: var(--green-dark);
}

.trigger-price-row {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 0 12px;
    transition: border-color .15s;
}
.trigger-price-row:focus-within { border-color: var(--green); }
.trigger-price-label {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-secondary);
}
.trigger-price-input {
    flex: 1;
    border: none;
    background: none;
    padding: 10px 0;
    font-size: 16px;
    font-weight: 800;
    font-family: var(--mono);
    color: var(--text);
    outline: none;
}
.trigger-price-input::-webkit-inner-spin-button { display: none; }

.trigger-hint {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 6px;
    text-align: center;
}

.trigger-pool-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.trigger-pool-label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.trigger-pool-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
}
.trigger-pool-option {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}
.trigger-pool-option input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: var(--green);
}
.trigger-pool-input {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg);
    font-size: 12px;
    font-family: var(--mono);
    color: var(--text);
    outline: none;
    transition: border-color .15s;
}
.trigger-pool-input:focus {
    border-color: var(--green);
}
.trigger-pool-input::placeholder {
    color: var(--text-tertiary);
}

/* ---- Trigger tags ---- */

.trigger-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
}
.trigger-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    background: var(--amber-bg);
    color: #92690a;
    border: 1px solid rgba(245,158,11,0.2);
}
.trigger-tag-close {
    width: 14px; height: 14px;
    display: flex; align-items: center; justify-content: center;
    border: none;
    background: rgba(0,0,0,0.08);
    border-radius: 4px;
    cursor: pointer;
    color: inherit;
    padding: 0;
    line-height: 1;
}
.trigger-tag-close:hover { background: rgba(0,0,0,0.15); }
.trigger-tag-close svg { width: 10px; height: 10px; }
