/* ============================================================
   Franchise Intelligence — app.css
   ============================================================ */

/* ---- Reset / Base ---- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #f4f6f9;
    color: #1e293b;
}

/* ---- App Shell ---- */
.fi-app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.fi-app-header {
    background: #1e293b;
    border-bottom: 3px solid #1e40af;
    padding: 0 2rem;
    height: 52px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.fi-app-header-inner {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.fi-app-logo {
    font-size: 1.4rem;
    line-height: 1;
}

.fi-app-name {
    font-size: 1.05rem;
    font-weight: 700;
    color: #f8fafc;
    letter-spacing: 0.01em;
}

.fi-app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* ---- Input Panel ---- */
.fi-input-panel {
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    padding: 1.5rem 2rem 1rem;
}

.fi-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1e40af;
    margin: 0 0 0.25rem;
}

.fi-subtitle {
    color: #64748b;
    margin: 0 0 1.25rem;
    font-size: 0.95rem;
}

.fi-form-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: flex-end;
}

.fi-form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.fi-form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.fi-optional {
    font-weight: 400;
    text-transform: none;
    color: #94a3b8;
}

.fi-address  { flex: 3; min-width: 260px; }
.fi-type     { flex: 2; min-width: 160px; }
.fi-brand    { flex: 1.5; min-width: 140px; }
.fi-radius   { flex: 1; min-width: 100px; }

.fi-input {
    padding: 0.55rem 0.75rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.95rem;
    background: #f8fafc;
    color: #1e293b;
    transition: border-color 0.15s;
    width: 100%;
}

.fi-input:focus {
    outline: none;
    border-color: #3b82f6;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

.fi-form-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-top: 1rem;
}

.fi-btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.4rem;
    background: #1e40af;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.fi-btn-primary:hover:not(:disabled) { background: #1d4ed8; }
.fi-btn-primary:disabled { background: #93c5fd; cursor: not-allowed; }

.fi-btn-secondary {
    padding: 0.6rem 1rem;
    background: transparent;
    color: #64748b;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.fi-btn-secondary:hover { border-color: #94a3b8; color: #334155; }

.fi-btn-sm {
    padding: 0.4rem 0.85rem;
    font-size: 0.85rem;
}

.fi-error {
    margin-top: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: #fef2f2;
    border: 1px solid #fca5a5;
    border-radius: 6px;
    color: #b91c1c;
    font-size: 0.9rem;
}

/* ---- Map ---- */
.fi-map-container {
    position: relative;
    width: 100%;
    height: 460px;
}

.fi-map {
    width: 100%;
    height: 100%;
}

.fi-map-legend {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    background: rgba(255,255,255,0.92);
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.82rem;
    color: #334155;
    backdrop-filter: blur(4px);
    z-index: 10;
    flex-wrap: wrap;
}

.fi-legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}

.fi-legend-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ---- Isochrone legend ---- */
.fi-legend-divider {
    width: 1px;
    height: 16px;
    background: #e2e8f0;
    flex-shrink: 0;
}

.fi-legend-zone {
    display: inline-block;
    width: 28px;
    height: 10px;
    border-radius: 3px;
    border: 1.5px dashed;
    flex-shrink: 0;
}

.fi-zone-inner {
    background: rgba(59, 130, 246, 0.14);
    border-color: #3b82f6;
}

.fi-zone-outer {
    background: rgba(139, 92, 246, 0.08);
    border-color: #8b5cf6;
}

/* ---- Heatmap legend swatches ---- */
.fi-heatmap-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
    opacity: 0.75;
}

.fi-heatmap-green  { background: #16a34a; }
.fi-heatmap-yellow { background: #ca8a04; }
.fi-heatmap-red    { background: #dc2626; }

/* ---- Dot colors ---- */
.fi-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.fi-dot.red    { background: #ef4444; }
.fi-dot.orange { background: #f97316; }
.fi-dot.yellow { background: #eab308; }

/* ---- Map marker styles ---- */
.home-marker {
    font-size: 28px;
    color: #1e40af;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
    cursor: pointer;
    line-height: 1;
}

.competitor-marker {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.8);
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.35);
    transition: transform 0.1s;
}

.competitor-marker:hover { transform: scale(1.3); }

/* ---- Results Panel ---- */
.fi-results-panel {
    padding: 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.fi-stats-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.fi-stat-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 1rem 1.5rem;
    text-align: center;
    min-width: 110px;
}

.fi-stat-card--highlight {
    border-color: #93c5fd;
    background: #eff6ff;
}

.fi-stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: #1e40af;
    line-height: 1;
}

.fi-stat-label {
    font-size: 0.78rem;
    color: #64748b;
    margin-top: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ---- Demographics Panel ---- */
.fi-demo-panel {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
}

.fi-demo-panel h3 {
    margin: 0 0 1rem;
    font-size: 1rem;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.fi-demo-radius {
    font-size: 0.8rem;
    font-weight: 400;
    color: #64748b;
}

.fi-demo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
}

.fi-demo-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.85rem 1rem;
    text-align: center;
    transition: box-shadow 0.15s;
}

.fi-demo-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.fi-demo-card--income {
    background: #eff6ff;
    border-color: #bfdbfe;
}

.fi-demo-icon {
    font-size: 1.4rem;
    line-height: 1;
    margin-bottom: 0.35rem;
}

.fi-demo-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1e40af;
    line-height: 1.1;
}

.fi-demo-label {
    font-size: 0.72rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 0.2rem;
}

.fi-demo-tier {
    display: inline-block;
    margin-top: 0.35rem;
    font-size: 0.7rem;
    font-weight: 600;
    color: #1d4ed8;
    background: #dbeafe;
    border-radius: 20px;
    padding: 0.15rem 0.5rem;
}

.fi-demo-loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #64748b;
    font-size: 0.9rem;
    padding: 1rem;
}

.fi-demo-loading .fi-spinner {
    border-color: rgba(100,116,139,0.3);
    border-top-color: #64748b;
}

/* ---- Customer Heat Map Panel ---- */
.fi-heatmap-panel {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
}

.fi-heatmap-panel h3 {
    margin: 0 0 0.5rem;
    font-size: 1rem;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.fi-optional-badge {
    font-size: 0.7rem;
    font-weight: 400;
    color: #64748b;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    padding: 0.1rem 0.5rem;
}

.fi-heatmap-desc {
    color: #64748b;
    font-size: 0.88rem;
    margin: 0 0 0.25rem;
}

.fi-heatmap-format {
    color: #94a3b8;
    font-size: 0.8rem;
    margin: 0 0 1rem;
}

.fi-heatmap-format code {
    font-family: 'Cascadia Code', 'Consolas', monospace;
    background: #f1f5f9;
    border-radius: 3px;
    padding: 0.1rem 0.3rem;
    font-size: 0.78rem;
    color: #475569;
}

/* File upload row */
.fi-upload-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* Hide the native file input visually — we use a styled label */
.fi-file-input {
    width: 0.1px;
    height: 0.1px;
    opacity: 0;
    overflow: hidden;
    position: absolute;
    z-index: -1;
}

.fi-btn-upload {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 1rem;
    background: #f8fafc;
    color: #475569;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    user-select: none;
}

.fi-btn-upload:hover {
    border-color: #94a3b8;
    background: #f1f5f9;
}

.fi-file-name {
    font-size: 0.85rem;
    color: #334155;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Progress bar */
.fi-heatmap-progress {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0;
    flex-wrap: wrap;
}

.fi-heatmap-progress .fi-spinner {
    border-color: rgba(30,64,175,0.25);
    border-top-color: #1e40af;
    flex-shrink: 0;
}

.fi-heatmap-progress span:last-of-type {
    font-size: 0.88rem;
    color: #475569;
}

.fi-progress-bar {
    flex: 1;
    min-width: 120px;
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    overflow: hidden;
}

.fi-progress-fill {
    height: 100%;
    background: #1e40af;
    border-radius: 3px;
    transition: width 0.4s ease;
}

/* Heatmap result stats */
.fi-heatmap-stats {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.fi-heatmap-stat {
    flex: 1;
    min-width: 90px;
    text-align: center;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.75rem 0.5rem;
}

.fi-heatmap-stat-green  { background: #f0fdf4; border-color: #bbf7d0; }
.fi-heatmap-stat-yellow { background: #fefce8; border-color: #fde68a; }
.fi-heatmap-stat-red    { background: #fef2f2; border-color: #fecaca; }

.fi-heatmap-stat .fi-stat-number {
    font-size: 1.5rem;
}

.fi-heatmap-stat-green  .fi-stat-number { color: #16a34a; }
.fi-heatmap-stat-yellow .fi-stat-number { color: #a16207; }
.fi-heatmap-stat-red    .fi-stat-number { color: #dc2626; }

.fi-heatmap-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.fi-heatmap-error {
    margin-top: 0.75rem;
}

/* AI Narrative panel */
.fi-narrative-panel {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
}

.fi-narrative-panel h3 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    color: #1e293b;
}

.fi-narrative-loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #64748b;
    font-size: 0.9rem;
}

.fi-narrative-text {
    font-size: 0.95rem;
    line-height: 1.7;
    color: #334155;
}

.fi-narrative-text p { margin: 0 0 0.85rem; }
.fi-narrative-text p:last-child { margin-bottom: 0; }

/* Competitor table */
.fi-competitor-list {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
}

.fi-competitor-list h3 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    color: #1e293b;
}

.fi-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.fi-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    background: #f8fafc;
    color: #475569;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid #e2e8f0;
}

.fi-table td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
    vertical-align: middle;
}

.fi-table tr:last-child td { border-bottom: none; }
.fi-table td:first-child { display: flex; align-items: center; gap: 0.4rem; font-weight: 500; }

.fi-chain-tag {
    font-size: 0.72rem;
    font-weight: 400;
    color: #64748b;
    background: #f1f5f9;
    border-radius: 4px;
    padding: 0.1rem 0.4rem;
    margin-left: 0.25rem;
}

.fi-empty {
    color: #64748b;
    font-style: italic;
    font-size: 0.9rem;
    margin: 0;
}

/* ---- Spinner ---- */
.fi-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: fi-spin 0.7s linear infinite;
}

.fi-narrative-loading .fi-spinner {
    border-color: rgba(100,116,139,0.3);
    border-top-color: #64748b;
}

@keyframes fi-spin {
    to { transform: rotate(360deg); }
}

/* ---- Blazor error UI ---- */
#blazor-error-ui {
    background: #fef2f2;
    border-top: 1px solid #fca5a5;
    color: #b91c1c;
    display: none;
    font-size: 0.9rem;
    padding: 0.6rem 1rem;
    position: fixed;
    bottom: 0;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    float: right;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .fi-input-panel { padding: 1rem; }
    .fi-results-panel { padding: 1rem; }
    .fi-form-row { flex-direction: column; }
    .fi-address, .fi-type, .fi-brand, .fi-radius { min-width: 100%; }
    .fi-map-container { height: 320px; }
    .fi-app-header { padding: 0 1rem; }
    .fi-demo-grid { grid-template-columns: repeat(2, 1fr); }
    .fi-map-legend { flex-wrap: wrap; gap: 0.5rem; }
    .fi-heatmap-stats { gap: 0.5rem; }
}
