/* ========================================
   Alicia Weight Tracker - Styles
   ======================================== */

/* CSS Variables - Default Light Rose Theme */
:root {
    /* Base colors */
    --bg-primary: #fff5f7;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --text-muted: #a0aec0;

    /* Accent colors */
    --accent-primary: #ed64a6;
    --accent-secondary: #f687b3;
    --accent-light: #fed7e2;

    /* Chart colors */
    --color-median: #805ad5;
    --color-sd: rgba(128, 90, 213, 0.15);
    --color-sd-border: rgba(128, 90, 213, 0.3);
    --color-baby: #ed64a6;
    --color-baby-fill: rgba(237, 100, 166, 0.2);

    /* UI colors */
    --border-color: #e2e8f0;
    --shadow-color: rgba(0, 0, 0, 0.08);
    --danger-color: #e53e3e;
    --success-color: #38a169;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Border radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* Font */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* ======== THEME DEFINITIONS ======== */

/* Light Ocean */
[data-theme="light-ocean"] {
    --bg-primary: #f0f9ff;
    --bg-secondary: #ffffff;
    --accent-primary: #0ea5e9;
    --accent-secondary: #38bdf8;
    --accent-light: #bae6fd;
    --color-median: #0369a1;
    --color-sd: rgba(3, 105, 161, 0.15);
    --color-sd-border: rgba(3, 105, 161, 0.3);
    --color-baby: #0ea5e9;
    --color-baby-fill: rgba(14, 165, 233, 0.2);
}

/* Light Forest */
[data-theme="light-forest"] {
    --bg-primary: #f0fdf4;
    --bg-secondary: #ffffff;
    --accent-primary: #22c55e;
    --accent-secondary: #4ade80;
    --accent-light: #bbf7d0;
    --color-median: #15803d;
    --color-sd: rgba(21, 128, 61, 0.15);
    --color-sd-border: rgba(21, 128, 61, 0.3);
    --color-baby: #22c55e;
    --color-baby-fill: rgba(34, 197, 94, 0.2);
}

/* Light Lavender */
[data-theme="light-lavender"] {
    --bg-primary: #faf5ff;
    --bg-secondary: #ffffff;
    --accent-primary: #a855f7;
    --accent-secondary: #c084fc;
    --accent-light: #e9d5ff;
    --color-median: #7e22ce;
    --color-sd: rgba(126, 34, 206, 0.15);
    --color-sd-border: rgba(126, 34, 206, 0.3);
    --color-baby: #a855f7;
    --color-baby-fill: rgba(168, 85, 247, 0.2);
}

/* Dark Rose */
[data-theme="dark-rose"] {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #1f2937;
    --text-primary: #f3f4f6;
    --text-secondary: #d1d5db;
    --text-muted: #9ca3af;
    --accent-primary: #f472b6;
    --accent-secondary: #ec4899;
    --accent-light: #831843;
    --color-median: #f9a8d4;
    --color-sd: rgba(249, 168, 212, 0.15);
    --color-sd-border: rgba(249, 168, 212, 0.3);
    --color-baby: #f472b6;
    --color-baby-fill: rgba(244, 114, 182, 0.3);
    --border-color: #374151;
    --shadow-color: rgba(0, 0, 0, 0.3);
}

/* Dark Ocean */
[data-theme="dark-ocean"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --accent-primary: #38bdf8;
    --accent-secondary: #0ea5e9;
    --accent-light: #0c4a6e;
    --color-median: #7dd3fc;
    --color-sd: rgba(125, 211, 252, 0.15);
    --color-sd-border: rgba(125, 211, 252, 0.3);
    --color-baby: #38bdf8;
    --color-baby-fill: rgba(56, 189, 248, 0.3);
    --border-color: #334155;
    --shadow-color: rgba(0, 0, 0, 0.4);
}

/* Dark Forest */
[data-theme="dark-forest"] {
    --bg-primary: #0f1f0f;
    --bg-secondary: #1a2e1a;
    --bg-card: #1a2e1a;
    --text-primary: #ecfdf5;
    --text-secondary: #a7f3d0;
    --text-muted: #6ee7b7;
    --accent-primary: #4ade80;
    --accent-secondary: #22c55e;
    --accent-light: #14532d;
    --color-median: #86efac;
    --color-sd: rgba(134, 239, 172, 0.15);
    --color-sd-border: rgba(134, 239, 172, 0.3);
    --color-baby: #4ade80;
    --color-baby-fill: rgba(74, 222, 128, 0.3);
    --border-color: #2d4a2d;
    --shadow-color: rgba(0, 0, 0, 0.4);
}

/* Dark Midnight */
[data-theme="dark-midnight"] {
    --bg-primary: #0a0a0f;
    --bg-secondary: #111118;
    --bg-card: #18181f;
    --text-primary: #e4e4e7;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --accent-primary: #8b5cf6;
    --accent-secondary: #7c3aed;
    --accent-light: #3b0764;
    --color-median: #a78bfa;
    --color-sd: rgba(167, 139, 250, 0.15);
    --color-sd-border: rgba(167, 139, 250, 0.3);
    --color-baby: #8b5cf6;
    --color-baby-fill: rgba(139, 92, 246, 0.3);
    --border-color: #27272a;
    --shadow-color: rgba(0, 0, 0, 0.5);
}

/* ======== THEME PREVIEWS ======== */
.theme-preview {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    border: 2px solid var(--border-color);
}

.theme-preview.light-rose { background: linear-gradient(135deg, #fff5f7 50%, #ed64a6 50%); }
.theme-preview.light-ocean { background: linear-gradient(135deg, #f0f9ff 50%, #0ea5e9 50%); }
.theme-preview.light-forest { background: linear-gradient(135deg, #f0fdf4 50%, #22c55e 50%); }
.theme-preview.light-lavender { background: linear-gradient(135deg, #faf5ff 50%, #a855f7 50%); }
.theme-preview.dark-rose { background: linear-gradient(135deg, #1a1a2e 50%, #f472b6 50%); }
.theme-preview.dark-ocean { background: linear-gradient(135deg, #0f172a 50%, #38bdf8 50%); }
.theme-preview.dark-forest { background: linear-gradient(135deg, #0f1f0f 50%, #4ade80 50%); }
.theme-preview.dark-midnight { background: linear-gradient(135deg, #0a0a0f 50%, #8b5cf6 50%); }

/* ======== BASE STYLES ======== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
}

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

/* ======== HEADER ======== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-actions {
    display: flex;
    gap: var(--spacing-sm);
    flex: 1;
    min-width: 0;
}

.header-left {
    justify-content: flex-start;
}

.header-actions:not(.header-left) {
    justify-content: flex-end;
}

.btn-lang {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.75rem;
    font-weight: 700;
    background: var(--accent-light);
    color: var(--accent-primary);
    border: 2px solid var(--accent-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 36px;
}

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

.header-title {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    flex-shrink: 0;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-primary);
    margin: 0;
    line-height: 1.2;
}

.header-age {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ======== BUTTONS ======== */
.btn-icon {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-icon:hover, .btn-icon:focus {
    background: var(--accent-light);
    color: var(--accent-primary);
}

.btn-icon svg {
    width: 24px;
    height: 24px;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
    border: none;
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

.btn-primary:hover, .btn-primary:focus {
    background: var(--accent-secondary);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-primary);
    color: var(--accent-primary);
    border: 2px solid var(--accent-primary);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    background: var(--accent-light);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
    border: none;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
}

.btn-large {
    padding: var(--spacing-lg);
    font-size: 1.125rem;
    min-height: 60px;
}

.btn-block {
    width: 100%;
}

/* ======== NAVIGATION TABS ======== */
.tabs {
    display: flex;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 var(--spacing-md);
}

.tab {
    flex: 1;
    padding: var(--spacing-md);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    transition: color 0.2s ease;
}

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

.tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: var(--spacing-md);
    right: var(--spacing-md);
    height: 3px;
    background: var(--accent-primary);
    border-radius: 3px 3px 0 0;
}

/* ======== MAIN CONTENT ======== */
.content {
    flex: 1;
    padding: var(--spacing-lg);
}

.view {
    display: none;
}

.view.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

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

/* ======== CHART ======== */
.chart-container {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    box-shadow: 0 4px 20px var(--shadow-color);
    margin-bottom: var(--spacing-lg);
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-md);
    justify-content: center;
    margin-bottom: var(--spacing-md);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 4px;
}

.chart-options {
    display: flex;
    justify-content: center;
}

/* ======== TOGGLE SWITCH ======== */
.toggle-label {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.toggle-label input {
    display: none;
}

.toggle-slider {
    width: 44px;
    height: 24px;
    background: var(--border-color);
    border-radius: var(--radius-full);
    position: relative;
    transition: background 0.2s ease;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s ease;
}

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

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

/* ======== CARDS ======== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    box-shadow: 0 4px 20px var(--shadow-color);
}

.card h2 {
    font-size: 1.25rem;
    margin-bottom: var(--spacing-lg);
    color: var(--text-primary);
}

/* ======== INPUT MODE TOGGLE ======== */
.input-mode-toggle {
    display: flex;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    padding: 4px;
    margin-bottom: var(--spacing-lg);
}

.mode-btn {
    flex: 1;
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn.active {
    background: var(--bg-card);
    color: var(--accent-primary);
    box-shadow: 0 2px 8px var(--shadow-color);
}

/* ======== FORM INPUTS ======== */
.input-group {
    margin-bottom: var(--spacing-lg);
}

.input-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
}

.big-input {
    width: 100%;
    padding: var(--spacing-md);
    font-size: 1.25rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.2s ease;
}

.big-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.big-input::placeholder {
    color: var(--text-muted);
}

.calculated-weight {
    margin-top: var(--spacing-md);
    padding: var(--spacing-md);
    background: var(--accent-light);
    border-radius: var(--radius-md);
    text-align: center;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--accent-primary);
    min-height: 52px;
}

.age-display {
    margin-top: var(--spacing-sm);
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: center;
}

.hidden {
    display: none !important;
}

/* ======== HISTORY ======== */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
}

.history-header h2 {
    margin-bottom: 0;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md);
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    transition: transform 0.2s ease;
}

.history-item:active {
    transform: scale(0.98);
}

.history-info {
    display: flex;
    flex-direction: column;
}

.history-weight {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--accent-primary);
}

.history-age {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.history-delete {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.history-delete:hover {
    background: rgba(229, 62, 62, 0.1);
    color: var(--danger-color);
}

.history-empty {
    text-align: center;
    padding: var(--spacing-xl);
    color: var(--text-muted);
}

/* ======== MODALS ======== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-lg);
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

.modal-small {
    max-width: 320px;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.125rem;
    margin: 0;
}

.modal-body {
    padding: var(--spacing-lg);
}

.modal-body h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-md);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-body h3:not(:first-child) {
    margin-top: var(--spacing-lg);
}

.modal-actions {
    display: flex;
    gap: var(--spacing-md);
    margin-top: var(--spacing-lg);
}

.modal-actions button {
    flex: 1;
}

/* ======== THEME GRID ======== */
.theme-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--spacing-sm);
}

.theme-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm);
    border: 2px solid transparent;
    background: transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-option span {
    font-size: 0.625rem;
    color: var(--text-secondary);
    text-align: center;
}

.theme-option:hover {
    border-color: var(--border-color);
}

.theme-option.active {
    border-color: var(--accent-primary);
    background: var(--accent-light);
}

/* ======== TOAST ======== */
.toast {
    position: fixed;
    bottom: var(--spacing-lg);
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: var(--bg-primary);
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-full);
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: 0 4px 20px var(--shadow-color);
    z-index: 1001;
    animation: toastIn 0.3s ease;
}

.toast.hidden {
    display: none;
}

.toast.success {
    background: var(--success-color);
    color: white;
}

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

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ======== RESPONSIVE ======== */
@media (max-width: 480px) {
    .header {
        padding: var(--spacing-sm) var(--spacing-md);
    }

    .content {
        padding: var(--spacing-md);
    }

    .card {
        padding: var(--spacing-md);
    }

    .theme-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .theme-option span {
        font-size: 0.5rem;
    }

    .theme-preview {
        width: 32px;
        height: 32px;
    }
}

/* ======== WEIGHT DISPLAY ======== */
.weight-display {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-lg);
    background: var(--bg-primary);
    border: 3px solid var(--border-color);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.2s ease;
}

.weight-display.active {
    border-color: var(--accent-primary);
    background: var(--accent-light);
}

.weight-display .weight-value {
    font-size: 3rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    min-width: 120px;
    text-align: right;
}

.weight-display .weight-unit {
    font-size: 1.5rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.weight-display.small {
    padding: var(--spacing-md);
}

.weight-display.small .weight-value {
    font-size: 1.75rem;
    min-width: 80px;
}

.weight-display.small .weight-unit {
    font-size: 1rem;
}

/* ======== DIFF FIELDS ======== */
.diff-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
}

.diff-field {
    text-align: center;
}

.diff-field label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ======== NUMPAD ======== */
.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-lg);
}

.numpad-key {
    aspect-ratio: 1.5;
    border: none;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1.75rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.numpad-key:hover {
    background: var(--accent-light);
}

.numpad-key:active {
    background: var(--accent-primary);
    color: white;
    transform: scale(0.95);
}

.numpad-delete {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
}

.numpad-delete:hover {
    background: rgba(229, 62, 62, 0.1);
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.numpad-delete:active {
    background: var(--danger-color);
    color: white;
}

/* ======== DATE GROUP ======== */
.date-group {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.date-group label {
    margin-bottom: 0;
    white-space: nowrap;
}

.date-input {
    flex: 1;
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
}

.date-group .age-display {
    margin-top: 0;
    white-space: nowrap;
    font-weight: 500;
}

/* ======== SAFE AREA (for notched phones) ======== */
@supports (padding: max(0px)) {
    .header {
        padding-top: max(var(--spacing-md), env(safe-area-inset-top));
    }

    .content {
        padding-bottom: max(var(--spacing-lg), env(safe-area-inset-bottom));
    }
}
