:root {
    --bg-color: #05050f;
    --surface-color: #0f101a;
    --surface-hover: #1e1e2e;
    --primary-color: #6366f1;
    /* Indigo 500 */
    --primary-hover: #4f46e5;
    /* Indigo 600 */
    --accent-color: #38bdf8;
    /* Sky 400 */
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --danger-color: #ef4444;
    --border-color: #1e1e2e;
    --glass-border: rgba(99, 102, 241, 0.15);
    --input-bg: #13131f;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    /* Prevent page scroll */
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    background-image:
        radial-gradient(circle at 15% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(56, 189, 248, 0.08) 0%, transparent 25%);
    color: var(--text-primary);
    padding: 1rem;
}

.app-container {
    max-width: 1600px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    margin-bottom: 1rem;
    flex-shrink: 0;
}

header h1 {
    font-size: 2rem;
    background: linear-gradient(to right, var(--accent-color), var(--primary-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0px;
}

header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

main {
    flex: 1;
    display: flex;
    gap: 1rem;
    overflow: hidden;
    /* Contain scrolls */
    min-height: 0;
}

/* Sidebar */
.sidebar {
    width: 320px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
}

.settings-card {
    background: var(--surface-color);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.5rem;
    height: fit-content;
    /* Allow it to be just as tall as needed, or full height? Start with fit. */
    max-height: 100%;
    overflow-y: auto;
}

/* Content Panel */
.content-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow: hidden;
    min-width: 0;
}

.chart-panel {
    flex: 0 0 auto;
    background: var(--surface-color);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1rem;
    height: 45%;
    /* Fixed height portion */
    min-height: 350px;
    display: flex;
    flex-direction: column;
}

.segments-card {
    flex: 1;
    /* Takes remaining space */
    background: var(--surface-color);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Internal scrolling */
}

/* Scroll area for segments */
#segmentsContainer {
    overflow-y: auto;
    flex: 1;
    /* Fill remaining card space */
    padding-right: 0.5rem;
}

/* Mobile Responsive */
@media (max-width: 900px) {

    html,
    body {
        overflow: auto;
        height: auto;
    }

    main {
        flex-direction: column;
        overflow: visible;
    }

    .sidebar,
    .content-panel,
    .chart-panel,
    .segments-card {
        width: 100%;
        height: auto;
        overflow: visible;
        flex: none;
    }

    .chart-panel {
        min-height: 300px;
    }
}

/* General Styles */
h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Inputs & Arrows Hidden */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
    width: 100%;
    padding: 0.75rem;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: white;
    font-family: inherit;
    font-size: 0.95rem;
}

input[type="number"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.hint {
    display: block;
    margin-top: 0.25rem;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* Toggles */
.toggle-container {
    display: flex;
    background: var(--input-bg);
    padding: 0.25rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.toggle-container input[type="radio"] {
    display: none;
}

.toggle-container label {
    flex: 1;
    text-align: center;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.toggle-container input[type="radio"]:checked+label {
    background: var(--primary-color);
    color: white;
    font-weight: 600;
}

/* Header & Table Layout */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    flex-shrink: 0;
}

.segments-header {
    display: grid;
    grid-template-columns: 1fr 1fr 32px;
    /* Matches row */
    gap: 1rem;
    padding: 0 1rem;
    margin-bottom: 0.5rem;
    flex-shrink: 0;
}

.segments-header.with-rate {
    grid-template-columns: 1fr 1fr 1fr 32px;
}

.col-header {
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
}

.segment-row {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    margin-bottom: 0.5rem;
    display: grid;
    grid-template-columns: 1fr 1fr 32px;
    gap: 1rem;
    align-items: center;
}

.segment-row.with-rate {
    grid-template-columns: 1fr 1fr 1fr 32px;
}

.segment-row label {
    display: none;
}

.segment-row .btn-delete {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
    border: none;
    border-radius: 6px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.segment-row .btn-delete:hover {
    background: rgba(239, 68, 68, 0.2);
}

@media (max-width: 600px) {
    .segments-header {
        display: none !important;
    }

    .segment-row,
    .segment-row.with-rate {
        grid-template-columns: 1fr;
        padding: 1rem;
        position: relative;
    }

    .segment-row label {
        display: block;
    }

    .segment-row .btn-delete {
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
    }
}

/* Buttons */
.btn {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    font-family: inherit;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    width: 100%;
}

.btn-secondary {
    background: transparent;
    color: var(--primary-color);
    border: 1px solid rgba(99, 102, 241, 0.3);
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
}

/* Chart */
.chart-container {
    flex: 1;
    position: relative;
    min-height: 0;
}

.stats-summary {
    display: flex;
    justify-content: space-around;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.stat-item .label {
    font-size: 0.8rem;
}

.stat-item .value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
}

.action-bar-sidebar {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.hidden {
    display: none !important;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 3px;
}