﻿:root {
    --primary: #FF8C00;
    --primary-glow: rgba(255, 140, 0, 0.4);
    --secondary: #FF4500;
    --gradient-primary: linear-gradient(135deg, #FF8C00 0%, #FF3D00 100%);
    --gradient-stage: linear-gradient(135deg, #FF8C00 0%, #7C4DFF 100%);
    --bg-app: #0B0C10;
    --bg-surface: #141722;
    --bg-card: #1C202E;
    --bg-card-hover: #24293B;
    --border: rgba(255, 255, 255, 0.08);
    --border-active: rgba(255, 140, 0, 0.5);
    --text-main: #FFFFFF;
    --text-muted: #9BA3B5;
    --text-dim: #646E82;
    --success: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    --info: #3B82F6;
    --purple: #8B5CF6;
    --radius-full: 9999px;
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 10px;
    --safe-bottom: env(safe-area-inset-bottom, 16px);
}

body.light-theme {
    --bg-app: #F4F6FA;
    --bg-surface: #FFFFFF;
    --bg-card: #F0F3F8;
    --bg-card-hover: #E4E8F0;
    --border: rgba(0, 0, 0, 0.08);
    --border-active: rgba(255, 140, 0, 0.6);
    --text-main: #111827;
    --text-muted: #64748B;
    --text-dim: #94A3B8;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Plus Jakarta Sans', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

body {
    background-color: #050608;
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow-x: hidden;
}

/* App Frame Container */
.app-container {
    width: 100%;
    max-width: 480px;
    height: 100vh;
    max-height: 920px;
    background-color: var(--bg-app);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.7);
}

@media (min-width: 520px) {
    .app-container {
        border-radius: 36px;
        border: 1px solid var(--border);
        height: 94vh;
    }
}

/* Header */
.app-header {
    padding: 16px 20px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-app);
    z-index: 10;
}

.user-greeting {
    display: flex;
    flex-direction: column;
}

.user-greeting .greeting-sub {
    font-size: 12px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
}

.user-greeting .greeting-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--text-main);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-btn:active {
    transform: scale(0.92);
}

/* Main Content Views */
.app-main {
    flex: 1;
    overflow-y: auto;
    padding: 10px 20px calc(85px + var(--safe-bottom));
    scroll-behavior: smooth;
}

.app-main::-webkit-scrollbar {
    display: none;
}

.tab-view {
    display: none;
    animation: fadeIn 0.25s ease forwards;
}

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

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Home Screen: Fasting Timer Circle */
.timer-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 10px 0 20px;
    position: relative;
}

.timer-circle-wrapper {
    position: relative;
    width: 270px;
    height: 270px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.timer-svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.timer-bg-ring {
    fill: none;
    stroke: var(--bg-surface);
    stroke-width: 14;
}

.timer-progress-ring {
    fill: none;
    stroke: url(#timerGradient);
    stroke-width: 14;
    stroke-linecap: round;
    stroke-dasharray: 785;
    stroke-dashoffset: 785;
    transition: stroke-dashoffset 0.8s ease;
    filter: drop-shadow(0 0 10px var(--primary-glow));
}

.timer-inner-content {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.timer-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 14px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-bottom: 8px;
    background: rgba(255, 140, 0, 0.15);
    color: var(--primary);
    border: 1px solid rgba(255, 140, 0, 0.3);
}

.timer-status-badge.eating {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
    border-color: rgba(16, 185, 129, 0.3);
}

.timer-status-badge.idle {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
    border-color: var(--border);
}

.timer-digits {
    font-size: 38px;
    font-weight: 900;
    letter-spacing: -0.5px;
    font-variant-numeric: tabular-nums;
    color: var(--text-main);
    line-height: 1.1;
}

.timer-subtext {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.timer-percentage {
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
    margin-top: 2px;
}

/* Fasting Stage Overview Card */
.stage-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    margin-bottom: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.stage-card:active {
    transform: scale(0.98);
}

.stage-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.stage-badge {
    font-size: 11px;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.stage-card-title {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.stage-card-desc {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.4;
    margin-bottom: 12px;
}

.stage-progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-card);
    border-radius: 10px;
    overflow: hidden;
}

.stage-progress-fill {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: 10px;
    width: 0%;
    transition: width 0.5s ease;
}

/* Action Controls Buttons */
.controls-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    margin-bottom: 24px;
}

.btn-main-action {
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 8px 20px var(--primary-glow);
    transition: all 0.2s ease;
}

.btn-main-action:active {
    transform: translateY(2px);
    box-shadow: 0 4px 10px var(--primary-glow);
}

.btn-main-action.stop-mode {
    background: linear-gradient(135deg, #EF4444 0%, #B91C1C 100%);
    box-shadow: 0 8px 20px rgba(239, 68, 68, 0.4);
}

.btn-time-edit {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: var(--radius-lg);
    padding: 0 18px;
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
}

.btn-time-edit:active {
    background: var(--bg-card);
}

/* Stats Mini Strip */
.stats-strip {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.stat-box {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 10px;
    text-align: center;
}

.stat-box-title {
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    font-weight: 700;
    margin-bottom: 2px;
}

.stat-box-value {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-main);
}

/* Plans Tab */
.section-title {
    font-size: 18px;
    font-weight: 800;
    margin: 10px 0 14px;
    color: var(--text-main);
}

.plans-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.plan-card {
    background: var(--bg-surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.plan-card.selected {
    border-color: var(--primary);
    background: rgba(255, 140, 0, 0.08);
}

.plan-card-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.plan-emoji {
    font-size: 28px;
}

.plan-name {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-main);
}

.plan-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.plan-tag {
    font-size: 11px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background: var(--bg-card);
    color: var(--text-muted);
}

.plan-card.selected .plan-tag {
    background: var(--gradient-primary);
    color: white;
}

/* Weight Screen */
.bmi-hero-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    text-align: center;
    margin-bottom: 20px;
}

.bmi-value {
    font-size: 42px;
    font-weight: 900;
    color: var(--primary);
    margin: 6px 0 2px;
}

.bmi-badge {
    display: inline-block;
    font-size: 12px;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.chart-container {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 20px;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.chart-header h4 {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-main);
}

#weightCanvas {
    width: 100%;
    height: 160px;
    display: block;
}

.weight-history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.weight-item {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.weight-item-val {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-main);
}

.weight-item-date {
    font-size: 12px;
    color: var(--text-dim);
}

.weight-delete-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 14px;
    padding: 4px;
}

.weight-delete-btn:hover {
    color: var(--danger);
}

/* History Screen */
.history-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.history-stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
}

.history-stat-card .val {
    font-size: 22px;
    font-weight: 900;
    color: var(--primary);
    margin-top: 4px;
}

.history-stat-card .lbl {
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    font-weight: 700;
}

.session-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.session-plan {
    font-size: 14px;
    font-weight: 800;
    color: var(--text-main);
}

.session-dates {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 2px;
}

.session-right {
    text-align: right;
}

.session-duration {
    font-size: 15px;
    font-weight: 800;
    color: var(--text-main);
}

.session-status {
    font-size: 11px;
    font-weight: 700;
    color: var(--success);
}

.session-status.interrupted {
    color: var(--warning);
}

/* Settings Screen */
.settings-group {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 18px;
    overflow: hidden;
}

.settings-group-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 800;
    color: var(--text-dim);
    padding: 14px 18px 6px;
}

.settings-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.settings-item:last-child {
    border-bottom: none;
}

.settings-item-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
}

.settings-item-desc {
    font-size: 12px;
    color: var(--text-dim);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    transition: 0.3s;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background: var(--gradient-primary);
}

input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

.btn-secondary-action {
    width: 100%;
    padding: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-secondary-action:active {
    background: var(--bg-card-hover);
}

/* Bottom Navigation Bar */
.bottom-nav {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(65px + var(--safe-bottom));
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: var(--safe-bottom);
    z-index: 100;
    backdrop-filter: blur(12px);
}

.nav-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    color: var(--text-dim);
    font-size: 10px;
    font-weight: 700;
    cursor: pointer;
    background: none;
    border: none;
    outline: none;
    padding: 8px 12px;
    transition: all 0.2s ease;
}

.nav-tab svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

.nav-tab.active {
    color: var(--primary);
}

.nav-tab.active svg {
    filter: drop-shadow(0 0 6px var(--primary-glow));
}

/* Modals */
.modal-backdrop {
    display: none;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    z-index: 200;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal-backdrop.open {
    display: flex;
}

.modal-sheet {
    width: 100%;
    background: var(--bg-surface);
    border-top-left-radius: 28px;
    border-top-right-radius: 28px;
    border: 1px solid var(--border);
    border-bottom: none;
    padding: 24px 20px calc(24px + var(--safe-bottom));
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-sheet-title {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-main);
}

.modal-close-btn {
    background: var(--bg-card);
    border: none;
    color: var(--text-main);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-field {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    font-size: 16px;
    color: var(--text-main);
    outline: none;
    margin-bottom: 16px;
}

.input-field:focus {
    border-color: var(--primary);
}

/* Toast */
.toast-banner {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    background: var(--bg-surface);
    border: 1px solid var(--border-active);
    color: var(--text-main);
    border-radius: var(--radius-md);
    padding: 12px 18px;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 300;
    transform: translateY(-100px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast-banner.show {
    transform: translateY(0);
    opacity: 1;
}

/* PWA Install Banner */
.pwa-install-banner {
    display: none;
    background: linear-gradient(135deg, rgba(255, 140, 0, 0.15) 0%, rgba(255, 61, 0, 0.05) 100%);
    border: 1px solid rgba(255, 140, 0, 0.3);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    margin-bottom: 16px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.pwa-install-banner.show {
    display: flex;
}

.pwa-install-btn {
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: var(--radius-full);
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
    white-space: nowrap;
}