* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --font-sans: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
    --ink: #14181f;
    --ink-soft: #5a6573;
    --ink-faint: #94a0ae;
    --line: #e7eaee;
    --line-soft: #eef1f4;
    --good: #0a7d4d;
    --good-bg: #e7f5ee;
    --bad: #c0392b;
    --bad-bg: #fbeae8;
    --accent: #4a90d9;
    --accent-dark: #3a7bc8;
}

body {
    font-family: var(--font-sans);
    background: #f4f6f8;
    color: var(--ink);
    line-height: 1.5;
}

.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.detail-container {
    max-width: 1400px;
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.dashboard-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.refresh-all-btn {
    padding: 0.4rem 0.75rem;
    background: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: background 0.15s;
}

.refresh-all-btn:hover {
    background: #e0e0e0;
}

.monitor-link {
    display: inline-block;
    padding: 0.4rem 0.75rem;
    background: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.8125rem;
    color: var(--ink-soft);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s;
    margin-left: auto;
}

.monitor-link:hover {
    background: #e0e0e0;
    color: var(--ink);
    text-decoration: none;
}

.empty-state {
    text-align: center;
    color: #888;
    padding: 2rem 0;
    font-style: italic;
}

.add-form {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.add-form h2 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.form-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.form-row input {
    flex: 1;
    min-width: 120px;
    padding: 0.5rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.875rem;
}

.form-row input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

.form-row input[type="date"] {
    -webkit-appearance: none;
    appearance: none;
}

.form-row button {
    padding: 0.5rem 1rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 0.15s;
}

.form-row button:hover {
    background: var(--accent-dark);
}

/* ── Tracker card ─────────────────────────────────────────── */
.tracker-card {
    position: relative;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    margin-bottom: 0.75rem;
    padding-bottom: 1.4rem;
    transition: box-shadow 0.18s ease, border-color 0.18s ease;
}

.tracker-card:hover {
    border-color: #d8dde3;
    box-shadow: 0 1px 2px rgba(20, 24, 31, 0.04), 0 8px 24px -12px rgba(20, 24, 31, 0.18);
}

.card-grid {
    display: grid;
    grid-template-columns: minmax(150px, 0.75fr) 1.4fr;
}

/* Left: route, date, status */
.card-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    padding: 1rem 0.75rem 1rem 1.25rem;
}

.card-route {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.route {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    font-family: var(--font-mono);
    color: var(--ink);
    transition: color 0.15s;
}

.card-route:hover .route {
    color: #2563c9;
}

.route-arrow {
    color: var(--ink-faint);
    font-weight: 400;
    font-size: 0.95em;
}

.date {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--ink-soft);
    white-space: nowrap;
}

.status-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.15rem 0.45rem 0.15rem 0.4rem;
    border-radius: 999px;
    font-family: var(--font-sans);
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, border-color 0.15s;
    position: absolute;
    bottom: 0.42rem;
    left: 1rem;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.status-toggle.active {
    background: var(--good-bg);
    color: var(--good);
    border-color: #cde9da;
}

.status-toggle.paused {
    background: #f4f6f8;
    color: var(--ink-soft);
    border-color: var(--line);
}

.status-toggle.active:hover { background: #ddefe5; }
.status-toggle.paused:hover { background: #eceff2; }



/* Right panel: chart row */
.card-panel {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.75rem 1rem 0.75rem 0.5rem;
    min-width: 0;
}

.price-chart-row {
    display: flex;
    position: relative;
    min-height: 64px;
    align-items: flex-start;
    gap: 0.75rem;
}

.spark-wrapper {
    flex: 0 1 250px;
    max-width: 270px;
    position: relative;
    height: 64px;
    min-width: 0;
}

.spark-wrapper .spark {
    width: 100%;
    height: 100%;
}

.spark-dot-el {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1.5px solid #fff;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.spark-dot-el.low     { background: var(--good); }
.spark-dot-el.current { background: var(--ink); }

.spark-at-low .spark-dot-el.current { background: var(--good); }

.price-rail {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    flex: 1;
    width: auto;
    min-width: 190px;
    gap: 0.65rem;
    padding: 8px 0;
}

.price-rail--combined {
    justify-content: center;
}

.rail-stat {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
}

.rail-alltime {
    margin-top: 0.35rem;
}

.rail-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.rail-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.rail-dot.current { background: var(--ink); }
.rail-dot.alltime { background: var(--good); }

.rail-cap {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-faint);
}

.rail-current .best-price {
    font-family: var(--font-mono);
    font-size: 1.9rem;
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.rail-alltime .rail-cap { color: var(--good); opacity: 0.8; }

.rail-alltime .rail-price {
    font-family: var(--font-mono);
    font-size: 1.15rem;
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--good);
    opacity: 0.6;
    font-variant-numeric: tabular-nums;
}

.rail-combined .rail-cap { color: var(--good); }

.rail-combined .best-price {
    font-family: var(--font-mono);
    font-size: 1.9rem;
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--good);
    font-variant-numeric: tabular-nums;
}

.rail-row .airline-logo { height: 20px; }
.rail-row .airline-logo-wrap { border: 1px solid var(--line); border-radius: 4px; padding: 1px; line-height: 0; }

.panel-fallback {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.5rem 0;
}

.panel-fallback .best-price {
    font-family: var(--font-mono);
    font-size: 1.85rem;
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.fallback-alltime {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.price-main {
    display: flex;
    align-items: baseline;
    gap: 0.55rem;
}

.best-price {
    font-family: var(--font-mono);
    font-size: 1.85rem;
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.price-main .airline-logo-wrap {
    align-self: center;
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 1px;
    line-height: 0;
}
.price-main .airline-logo { height: 16px; width: auto; border-radius: 3px; }

.filtered-tag {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    color: var(--ink-faint);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    align-self: center;
}

/* Sparkline */
.spark {
    display: block;
    overflow: visible;
}

.spark-line {
    fill: none;
    stroke-width: 1.8;
    stroke-linejoin: round;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
}

.spark-area { opacity: 0.07; stroke: none; }

.spark-down .spark-line { stroke: var(--good); }
.spark-down .spark-area { fill: var(--good); }

.spark-up .spark-line { stroke: var(--bad); }
.spark-up .spark-area { fill: var(--bad); }

.spark-flat .spark-line { stroke: var(--ink-faint); }
.spark-flat .spark-area { fill: var(--ink-faint); }

/* Trend chip */
.trend-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.1em;
    padding: 0.1rem 0.35rem;
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.trend-chip.down { background: var(--good-bg); color: var(--good); }
.trend-chip.up   { background: var(--bad-bg);  color: var(--bad);  }

.trend-chip-period {
    font-size: 0.6em;
    font-weight: 500;
    opacity: 0.75;
    margin-left: 0.15em;
}

/* Meta footer line */
.card-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    font-size: 0.72rem;
    color: var(--ink-soft);
    margin-top: auto;
}

.card-meta strong {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.meta-fetch {
    position: absolute;
    bottom: 0.45rem;
    right: 1rem;
    font-size: 0.65rem;
    color: var(--ink-faint);
    white-space: nowrap;
    pointer-events: none;
}

.last-checked { color: inherit; }

.badge.alert-count {
    margin-left: auto;
    background: #fef3e2;
    color: #b5651d;
    text-transform: none;
    letter-spacing: 0;
}

/* Delete (hover-revealed) */
.card-delete {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--ink-faint);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.tracker-card:hover .card-delete,
.card-delete:focus-visible { opacity: 1; }

.card-delete:hover {
    background: var(--bad-bg);
    color: var(--bad);
}

/* Shared badge / labels (used by detail + results pages) */
.day-offset {
    font-size: 0.8em;
    color: #999;
}

.label {
    font-size: 0.75rem;
    color: #999;
    margin-right: 0.25rem;
}

.badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge.active {
    background: #d4edda;
    color: #155724;
}

.badge.paused {
    background: #fff3cd;
    color: #856404;
}

.htmx-request.form-row button {
    opacity: 0.6;
    pointer-events: none;
}

.htmx-request.tracker-card {
    opacity: 0.5;
}

.back-link {
    display: inline-block;
    margin-bottom: 1rem;
    color: var(--accent);
    text-decoration: none;
    font-size: 0.875rem;
}

.back-link:hover {
    text-decoration: underline;
}

.detail-header {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
}

.detail-header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

.detail-header-left h1 {
    margin-bottom: 0.25rem;
}

.detail-header .date {
    display: inline-block;
    font-size: 1.05rem;
    color: #444;
}

.detail-best {
    color: #2a7d4f;
    font-weight: 600;
}

.detail-historical {
    color: #888;
}

.gf-link {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--accent);
    border-radius: 4px;
    background: #fff;
    color: var(--accent);
    font-size: 0.8125rem;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s;
}

.gf-link:hover {
    background: #eef5fc;
}

.detail-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

.detail-controls-left,
.detail-controls-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.detail-controls button {
    padding: 0.4rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.detail-controls button:hover {
    background: #f0f0f0;
    border-color: #999;
}

.detail-controls button.danger {
    color: #c0392b;
    border-color: #e0c0c0;
}

.detail-controls button.danger:hover {
    background: #fdf0f0;
    border-color: #c0392b;
}

.chart-section {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
}

.chart-section h2 {
    font-size: 1rem;
    margin-bottom: 1rem;
}

.chart-container {
    position: relative;
    height: 300px;
}

.results-section {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
    overflow-x: auto;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.results-header h2 {
    font-size: 1rem;
}

.search-now-btn {
    padding: 0.4rem 1rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: background 0.15s;
}

.search-now-btn:hover {
    background: var(--accent-dark);
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.results-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 2px solid #eee;
    font-weight: 600;
    color: #555;
}

.results-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #f0f0f0;
    white-space: nowrap;
}

.results-table tbody tr:hover {
    background: #f9f9f9;
}

.price-cell {
    font-weight: 600;
    color: #2a7d4f;
}

.price-badge {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    white-space: nowrap;
}

.price-badge.down {
    background: #d4edda;
    color: #155724;
}

.price-badge.up {
    background: #f8d7da;
    color: #721c24;
}

.price-badge.new {
    background: #d1ecf1;
    color: #0c5460;
}

.price-badge.same {
    background: #e9ecef;
    color: #6c757d;
}

.price-badge.missing {
    background: #fff3cd;
    color: #856404;
}

.row-missing {
    opacity: 0.6;
}

.row-missing td {
    text-decoration: line-through;
}

.card-delta.same {
    color: #6c757d;
}

.htmx-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8125rem;
    color: #888;
    opacity: 0;
    transition: opacity 0.2s;
}

.htmx-indicator::before {
    content: "";
    width: 12px;
    height: 12px;
    border: 2px solid #ccc;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spinner 0.6s linear infinite;
    display: inline-block;
    vertical-align: middle;
}

@keyframes spinner {
    to { transform: rotate(360deg); }
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    opacity: 1;
}

.error-banner {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    border-radius: 6px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    display: none;
}

.error-banner.visible {
    display: block;
}

@media (max-width: 600px) {
    .container {
        padding: 1rem 0.75rem;
    }

    .form-row {
        flex-direction: column;
    }

    .form-row input {
        min-width: unset;
        width: 100%;
    }

    .card-grid {
        grid-template-columns: 1fr;
    }

    .card-panel {
        border-left: none;
        border-top: 1px solid var(--line-soft);
    }

    .detail-controls {
        flex-wrap: wrap;
    }
}

.stat-cards {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    flex: 1;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: #222;
}

.stat-label {
    display: block;
    font-size: 0.75rem;
    color: #888;
    margin-top: 0.25rem;
}

.logs-section h2 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.auto-refresh-note {
    font-size: 0.75rem;
    color: #999;
    font-weight: 400;
}

.logs-scroll-wrap {
    max-height: 70vh;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
}

.logs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
    background: #fff;
}

.logs-scroll-wrap .logs-table thead th {
    position: sticky;
    top: 0;
    background: #f9f9f9;
    z-index: 1;
}

.logs-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 2px solid #eee;
    font-weight: 600;
    color: #555;
}

.logs-table td {
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid #f5f5f5;
}

.log-row.log-error {
    background: #fff5f5;
}

.log-row.log-warning {
    background: #fffdf0;
}

.log-level {
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.log-row.log-error .log-level {
    color: #c0392b;
}

.log-row.log-warning .log-level {
    color: #d68910;
}

.log-id {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--ink-faint);
    white-space: nowrap;
}

.log-date {
    font-size: 0.75rem;
    color: #555;
    white-space: nowrap;
}

.log-hour {
    font-size: 0.8rem;
    white-space: nowrap;
    font-family: var(--font-mono);
}

.log-tid {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--ink-faint);
    margin-right: 0.3rem;
}

.log-route {
    color: var(--ink-soft);
}

.airline-logo {
    height: 32px;
    width: auto;
    vertical-align: middle;
}

.airline-logo-wrap {
    display: inline-flex;
    align-items: center;
}

.results-table tr.row-colored td:first-child { box-shadow: inset 4px 0 0 var(--row-color); }

/* --- filter sidebar layout (plan 010) --- */

.detail-layout {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
}

.detail-main {
    flex: 1;
    min-width: 0;
}

.filter-sidebar {
    width: 240px;
    flex-shrink: 0;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 1rem;
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.filter-group {
    margin-bottom: 1rem;
}

.filter-group > label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 0.35rem;
}

.filter-group select,
.filter-group input[type="range"] {
    width: 100%;
    box-sizing: border-box;
}

.filter-group.filter-airlines {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.filter-group.filter-airlines .airline-list {
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
}

.airline-actions {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.35rem;
}

.airline-action-link {
    font-size: 0.75rem;
    color: var(--accent);
    text-decoration: none;
    cursor: pointer;
}

.airline-action-link:hover {
    text-decoration: underline;
}

.airline-list {
    max-height: 180px;
    overflow-y: auto;
}

.airline-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    padding: 0.15rem 0;
    cursor: pointer;
}

.airline-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.airline-count {
    color: #999;
    font-size: 0.75rem;
}

.airline-row.airline-disabled {
    opacity: 0.4;
    pointer-events: none;
}

.airline-price {
    margin-left: auto;
    text-align: right;
    white-space: nowrap;
    color: #444;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.filtered-tag {
    font-size: 0.7rem;
    color: #888;
    text-align: right;
}

.filter-reset-btn {
    width: 100%;
    padding: 0.35rem 0;
    font-size: 0.85rem;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
}

.filter-reset-btn:hover {
    background: #e9e9e9;
}

.results-table tr.row-filtered {
    opacity: 0.35;
}

.results-table tr.row-filtered td:first-child {
    box-shadow: inset 4px 0 0 #ccc;
}

@media (max-width: 600px) {
    .detail-layout {
        flex-direction: column;
    }
    .filter-sidebar {
        width: 100%;
        position: static;
    }
}

.last-fetched-time {
    font-size: 0.8rem;
    color: #999;
    margin-top: 0.1rem;
}
