/* ============================================================
   EcoKing - Main Stylesheet
   Mobile-first, component-based
   ============================================================ */

/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    transition: background-color var(--transition), color var(--transition);
}

/* === Typography === */
h1, h2, h3, h4 {
    font-weight: 600;
    line-height: 1.2;
    color: var(--text-primary);
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }
h4 { font-size: 0.9375rem; }

p { color: var(--text-secondary); }

a {
    color: var(--accent);
    text-decoration: none;
}
a:hover { text-decoration: underline; }

/* === Layout === */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
}

.main-content {
    flex: 1;
    padding: 1rem;
    padding-bottom: 5rem; /* Space for bottom nav */
}

/* === Header === */
.app-header {
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.app-header .logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--text-primary);
}

.app-header .logo svg {
    color: var(--accent);
}

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

/* === Status Indicator === */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.status-dot.producing {
    background: var(--status-producing);
    box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.2);
    animation: pulse-green 2s infinite;
}

.status-dot.idle {
    background: var(--status-idle);
}

.status-dot.offline {
    background: var(--status-offline);
    animation: pulse-red 2s infinite;
}

.status-dot.unknown {
    background: var(--status-unknown);
}

@keyframes pulse-green {
    0%, 100% { box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.2); }
    50% { box-shadow: 0 0 0 6px rgba(22, 163, 74, 0.1); }
}

@keyframes pulse-red {
    0%, 100% { box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.2); }
    50% { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0.1); }
}

/* === Bottom Navigation === */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-nav);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 100;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
    max-width: 1200px;
    margin: 0 auto;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 0.5rem;
    gap: 0.25rem;
    cursor: pointer;
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 0.6875rem;
    font-weight: 500;
    transition: color var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.nav-item svg {
    width: 22px;
    height: 22px;
    transition: transform var(--transition);
}

.nav-item.active {
    color: var(--accent);
}

.nav-item.active svg {
    transform: scale(1.1);
}

.nav-item:hover {
    color: var(--accent);
}

/* === Cards === */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: box-shadow var(--transition), background-color var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

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

.card-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* === Power Display (Hero Card) === */
.power-hero {
    background: linear-gradient(135deg, var(--accent-bg) 0%, var(--bg-card) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.power-hero::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at center, var(--accent-bg) 0%, transparent 60%);
    opacity: 0.5;
    pointer-events: none;
}

.power-value {
    font-size: 3.5rem;
    font-weight: 800;
    line-height: 1;
    color: var(--accent);
    letter-spacing: -0.02em;
    transition: color var(--transition);
}

.power-value.no-production {
    color: var(--text-muted);
}

.power-unit {
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-left: 0.25rem;
}

.power-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* === Stats Grid === */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.stat-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.625rem;
}

.stat-icon.green  { background: var(--accent-bg); color: var(--accent); }
.stat-icon.orange { background: var(--accent-warm-bg); color: var(--accent-warm); }
.stat-icon.blue   { background: var(--info-bg); color: var(--info); }
.stat-icon.red    { background: var(--danger-bg); color: var(--danger); }

.stat-value {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

.stat-sub {
    font-size: 0.8125rem;
    color: var(--accent);
    font-weight: 600;
    margin-top: 0.125rem;
}

/* === Phase Details === */
.phase-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.phase-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 0.875rem;
    border: 1px solid var(--border);
}

.phase-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.phase-metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.8125rem;
}

.phase-metric:last-child {
    border-bottom: none;
}

.phase-metric-label {
    color: var(--text-muted);
}

.phase-metric-value {
    font-weight: 600;
    color: var(--text-primary);
}

/* === Collapsible Section === */
.collapsible-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 0.75rem 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.collapsible-header h3 {
    font-size: 0.9375rem;
    color: var(--text-secondary);
}

.collapsible-icon {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    transition: transform var(--transition);
}

.collapsible-icon.open {
    transform: rotate(180deg);
}

.collapsible-content {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    max-height: 0;
    opacity: 0;
}

.collapsible-content.open {
    max-height: 500px;
    opacity: 1;
}

/* === Chart Container === */
.chart-container {
    position: relative;
    width: 100%;
    height: 200px;
}

.chart-container.tall {
    height: 280px;
}

/* === Section Spacing === */
.section {
    margin-bottom: 1rem;
}

.section-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* === View Tabs (History) === */
.view-tabs {
    display: flex;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 0.25rem;
    gap: 0.25rem;
    margin-bottom: 1rem;
}

.view-tab {
    flex: 1;
    padding: 0.5rem;
    border: none;
    background: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.view-tab.active {
    background: var(--bg-card);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}

/* === Forms === */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
}

.form-input,
.form-select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9375rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    -webkit-appearance: none;
    appearance: none;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.15);
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    filter: brightness(1.1);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-card-hover);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    filter: brightness(1.1);
}

.btn-full {
    width: 100%;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

/* === Toggle Switch === */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.toggle-row:last-child {
    border-bottom: none;
}

.toggle-info {
    flex: 1;
}

.toggle-label {
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-primary);
}

.toggle-desc {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

.toggle-switch {
    position: relative;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
    margin-left: 1rem;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 13px;
    transition: all var(--transition);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    top: 3px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all var(--transition);
}

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

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
    background: white;
}

/* === Alert / Toast === */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.alert-success {
    background: var(--accent-bg);
    color: var(--accent);
    border: 1px solid rgba(22, 163, 74, 0.2);
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid rgba(220, 38, 38, 0.2);
}

.alert-warning {
    background: var(--warning-bg);
    color: var(--warning);
    border: 1px solid rgba(217, 119, 6, 0.2);
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 5.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    font-size: 0.875rem;
    font-weight: 500;
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
    white-space: nowrap;
    max-width: calc(100vw - 2rem);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* === Loading Spinner === */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--text-muted);
    gap: 0.75rem;
    font-size: 0.875rem;
}

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin: 0 auto 1rem;
    opacity: 0.4;
}

.empty-state h3 {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.empty-state p {
    font-size: 0.875rem;
}

/* === Divider === */
.divider {
    height: 1px;
    background: var(--border);
    margin: 1rem 0;
}

/* === Badge === */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-green  { background: var(--accent-bg); color: var(--accent); }
.badge-orange { background: var(--accent-warm-bg); color: var(--accent-warm); }
.badge-red    { background: var(--danger-bg); color: var(--danger); }
.badge-gray   { background: var(--bg-secondary); color: var(--text-muted); }

/* === API Key Display === */
.api-key-display {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.8125rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.625rem 0.875rem;
    word-break: break-all;
    color: var(--text-secondary);
}

/* === View Panels === */
.view-panel {
    display: none;
}

.view-panel.active {
    display: block;
}

/* === Last Updated === */
.last-updated {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    padding: 0.5rem;
}

/* === Utility === */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-muted  { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-danger { color: var(--danger); }
.text-sm     { font-size: 0.875rem; }
.text-xs     { font-size: 0.75rem; }
.font-bold   { font-weight: 700; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.hidden { display: none !important; }
