/* ── Global Styles & Variable Definitions ── */
:root {
    --bg-main: #0b0f19;
    --bg-panel: #111827;
    --bg-control: #1f2937;
    --bg-highlight: #1e293b;
    --border-color: #374151;
    --border-focus: #10b981;
    
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    
    --color-accent: #10b981;
    --color-accent-hover: #059669;
    --color-recommend: #6366f1;
    --color-error: #ef4444;
    --color-warning: #f59e0b;
    
    --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    --border-radius: 6px;
    --transition-fast: 0.15s ease;
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    height: 100vh;
    overflow: hidden;
}

/* ── App Container & Layout ── */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* ── Header ── */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 2.25rem;
    height: 2.25rem;
    color: var(--color-accent);
}

.logo-text h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.2;
}

.logo-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.system-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: var(--bg-highlight);
    border: 1px solid var(--border-color);
    padding: 0.375rem 0.75rem;
    border-radius: var(--border-radius);
    font-size: 0.75rem;
    font-weight: 600;
}

.status-indicator {
    width: 8px;
    height: 8px;
    background-color: var(--color-accent);
    border-radius: 50%;
    animation: status-pulse 2s infinite;
}

@keyframes status-pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* ── Workspace Split Grid ── */
.workspace-grid {
    display: grid;
    grid-template-columns: 480px 1fr;
    gap: 1.5rem;
    flex: 1;
    margin-top: 1.5rem;
    height: calc(100vh - 100px);
    overflow: hidden;
}

/* ── Panel Styles ── */
.panel {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.panel-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.panel-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.panel-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* ── Input Panel Styles ── */
.input-panel {
    overflow: hidden;
}

.parameter-form {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* ── Navigation Tabs ── */
.tabs {
    display: flex;
    background-color: var(--bg-control);
    padding: 0.25rem;
    margin: 1.25rem 1.5rem 0;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: calc(var(--border-radius) - 2px);
    transition: var(--transition-fast);
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    background-color: var(--bg-highlight);
    color: var(--text-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* ── Form Sections ── */
.form-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.075em;
    color: var(--text-muted);
    font-weight: 700;
}

.section-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ── Form Control Elements ── */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 600;
}

.control-label-simple {
    font-size: 0.85rem;
    font-weight: 600;
}

.range-wrapper {
    display: grid;
    grid-template-columns: 1fr 72px;
    gap: 1rem;
    align-items: center;
}

/* range slider styling */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
}

input[type="range"]:focus {
    outline: none;
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: var(--bg-control);
    border-radius: 2px;
    border: 1px solid var(--border-color);
}

input[type="range"]::-webkit-slider-thumb {
    height: 14px;
    width: 14px;
    border-radius: 50%;
    background: var(--color-accent);
    cursor: pointer;
    -webkit-appearance: none;
    margin-top: -6px;
    transition: var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

/* numeric and input styles */
.num-input {
    background-color: var(--bg-control);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    padding: 0.35rem 0.5rem;
    border-radius: var(--border-radius);
    text-align: right;
    width: 100%;
}

.num-input:focus, .select-input:focus, .num-input-full:focus {
    outline: none;
    border-color: var(--border-focus);
}

.num-input-full {
    background-color: var(--bg-control);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    padding: 0.5rem;
    border-radius: var(--border-radius);
    width: 100%;
}

.select-input {
    background-color: var(--bg-control);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 0.85rem;
    padding: 0.5rem;
    border-radius: var(--border-radius);
    width: 100%;
    cursor: pointer;
}

.grid-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* ── Badges ── */
.badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
}

.unit-badge {
    background-color: var(--bg-highlight);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.success-badge {
    background-color: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: var(--color-accent);
}

/* ── Switch Toggle Styles ── */
.advisory-toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-highlight);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
}

.toggle-text {
    display: flex;
    flex-direction: column;
}

.toggle-title {
    font-size: 0.85rem;
    font-weight: 600;
}

.toggle-desc {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

.switch {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-control);
    border: 1px solid var(--border-color);
    transition: .3s;
    border-radius: 20px;
}

.switch-slider:before {
    position: absolute;
    content: "";
    height: 12px;
    width: 12px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-secondary);
    transition: .3s;
    border-radius: 50%;
}

input:checked + .switch-slider {
    background-color: var(--color-accent);
    border-color: var(--color-accent);
}

input:checked + .switch-slider:before {
    transform: translateX(18px);
    background-color: var(--bg-panel);
}

/* ── Buttons ── */
.btn-primary {
    background-color: var(--color-accent);
    color: var(--bg-main);
    border: none;
    font-size: 0.9rem;
    font-weight: 700;
    padding: 0.75rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition-fast);
}

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

.btn-secondary {
    background-color: var(--bg-control);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.35rem 0.6rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition-fast);
}

.btn-secondary:hover {
    background-color: var(--bg-highlight);
}

/* ── Output Dashboard Styles ── */
.output-panel {
    overflow: hidden;
}

.output-container {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* State: Empty View */
.state-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    flex: 1;
    padding: 2rem;
}

.state-icon {
    width: 3.5rem;
    height: 3.5rem;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

.state-view h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.state-view p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    max-width: 320px;
    margin-top: 0.5rem;
}

/* State: Loading/Spinner */
.spinner {
    width: 2.25rem;
    height: 2.25rem;
    border: 2px solid rgba(16, 185, 129, 0.1);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spinner-spin 0.8s linear infinite;
    margin-bottom: 1.25rem;
}

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

/* ── Result Detail Cards ── */
.result-highlight-card {
    background-color: var(--bg-highlight);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    margin-bottom: 1.5rem;
    animation: fade-slide-in 0.25s ease-out;
}

.result-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.result-crop-name {
    font-size: 1rem;
    font-weight: 700;
}

.result-value-container {
    margin-top: 1rem;
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.result-number {
    font-size: 2.5rem;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--color-accent);
    line-height: 1;
}

.result-unit {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.result-progress-row {
    margin-top: 1.25rem;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.progress-val {
    color: var(--text-primary);
}

.progress-bar-container {
    height: 6px;
    background-color: var(--bg-control);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background-color: var(--color-accent);
    border-radius: 3px;
    transition: width 0.4s ease-out;
}

/* ── Data Grid ── */
.data-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    animation: fade-slide-in 0.3s ease-out;
}

.data-card {
    background-color: var(--bg-highlight);
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: var(--border-radius);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.data-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.data-val {
    font-size: 1.1rem;
    font-weight: 700;
    font-family: var(--font-mono);
}

/* ── Recommendations List ── */
.recommendations-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    width: 100%;
}

.recommendations-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
}

.recommendations-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    animation: fade-slide-in 0.25s ease-out;
    width: 100%;
}

.recommendation-row {
    background-color: var(--bg-highlight);
    border: 1px solid var(--border-color);
    padding: 0.85rem 1rem;
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: var(--transition-fast);
}

.recommendation-row:hover {
    border-color: var(--color-recommend);
}

.recommendation-row:first-child {
    grid-column: span 2;
    border-color: var(--color-recommend);
    background-color: #1e1b4b;
    padding: 1.15rem 1.35rem;
}

.recommendation-row:first-child .rec-name {
    font-size: 1.05rem;
    color: var(--color-accent);
}

.rec-rank-block {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.rec-rank {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 700;
}

.rec-name {
    font-size: 0.9rem;
    font-weight: 700;
}

.rec-data-block {
    display: flex;
    align-items: center;
    gap: 2rem;
    text-align: right;
}

.rec-metric-val {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    font-weight: 700;
}

.rec-metric-label {
    display: block;
    font-size: 0.65rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.suitability-ring-label {
    color: var(--color-recommend);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    font-weight: 700;
}

/* ── AI Advisory Panel ── */
.advisory-panel {
    background-color: var(--bg-highlight);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.25rem;
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    animation: fade-slide-in 0.35s ease-out;
}

.advisory-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-recommend);
}

.advisory-icon {
    width: 1.15rem;
    height: 1.15rem;
}

.advisory-content {
    font-size: 0.85rem;
    color: #e2e8f0;
    line-height: 1.6;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 0.75rem;
    white-space: pre-wrap; /* Preserve formatting cleanly */
}

/* Animations */
@keyframes fade-slide-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.hidden {
    display: none !important;
}

/* ── Rate Limit Modal Overlay ── */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(9, 13, 22, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fade-in 0.2s ease-out;
}

.overlay-card {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    width: 480px;
    padding: 2.5rem;
    border-radius: var(--border-radius);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
}

.overlay-icon {
    width: 4rem;
    height: 4rem;
    color: var(--color-warning);
}

.overlay-card h2 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.015em;
}

.overlay-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.countdown-circle {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-highlight);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 120px;
    height: 120px;
}

#countdown-timer {
    font-size: 2.25rem;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--color-warning);
    line-height: 1;
}

.countdown-sub {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
}

.overlay-card button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background-color: var(--bg-control);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ── Scrollbars ── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
