/* CSS Variables - Apple Design System Dark Theme */
:root {
    --bg-primary: #000000;
    --bg-secondary: #1c1c1e;
    --bg-tertiary: #2c2c2e;
    --bg-elevated: #3a3a3c;

    --text-primary: #ffffff;
    --text-secondary: #98989f;
    --text-tertiary: #636366;

    --accent-blue: #0a84ff;
    --accent-green: #30d158;
    --accent-red: #ff453a;
    --accent-orange: #ff9f0a;
    --accent-purple: #bf5af2;

    --border-color: #38383a;
    --separator: #38383a;

    --safe-area-top: env(safe-area-inset-top, 20px);
    --safe-area-bottom: env(safe-area-inset-bottom, 20px);

    --font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', sans-serif;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    height: 100%;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100%;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Screens */
.screen {
    display: none;
    min-height: 100vh;
    min-height: 100dvh;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* Login Screen */
#login-screen {
    justify-content: center;
    align-items: center;
    padding: 20px;
    background: linear-gradient(180deg, #1a1a2e 0%, #000000 100%);
}

.login-container {
    width: 100%;
    max-width: 320px;
    text-align: center;
}

.login-icon {
    width: 100px;
    height: 100px;
    margin: 0 auto 24px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.login-container h1 {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.login-container .subtitle {
    color: var(--text-secondary);
    font-size: 17px;
    margin-bottom: 40px;
}

.input-group {
    margin-bottom: 16px;
    text-align: left;
}

.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-group input,
.input-group select {
    width: 100%;
    padding: 16px;
    font-size: 17px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s, background-color 0.2s;
}

.input-group input:focus,
.input-group select:focus {
    border-color: var(--accent-blue);
    background: var(--bg-tertiary);
}

.input-group input::placeholder {
    color: var(--text-tertiary);
}

.input-group select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2398989f' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
    padding-right: 44px;
}

/* Buttons */
.primary-btn {
    width: 100%;
    padding: 16px 24px;
    font-size: 17px;
    font-weight: 600;
    background: var(--accent-blue);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
}

.primary-btn:active {
    opacity: 0.8;
    transform: scale(0.98);
}

.secondary-btn {
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 600;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.secondary-btn:active {
    opacity: 0.7;
}

.danger-btn {
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 600;
    background: rgba(255, 69, 58, 0.15);
    color: var(--accent-red);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.danger-btn:active {
    opacity: 0.7;
}

.text-btn {
    padding: 8px 16px;
    font-size: 17px;
    font-weight: 600;
    background: transparent;
    color: var(--accent-blue);
    border: none;
    cursor: pointer;
}

.icon-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--accent-blue);
    cursor: pointer;
    border-radius: 22px;
    transition: background-color 0.2s;
}

.icon-btn:active {
    background: var(--bg-tertiary);
}

.add-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    font-size: 17px;
    font-weight: 500;
    background: var(--bg-secondary);
    color: var(--accent-blue);
    border: 1px dashed var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-bottom: 16px;
}

.add-btn:active {
    background: var(--bg-tertiary);
}

.full-width {
    width: 100%;
    margin-bottom: 12px;
}

.error-text {
    color: var(--accent-red);
    font-size: 14px;
    margin-top: 12px;
    min-height: 20px;
}

.hidden {
    display: none !important;
}

/* App Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    padding-top: calc(var(--safe-area-top) + 12px);
    background: var(--bg-primary);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

/* Tab Content */
.tab-content {
    flex: 1;
    padding: 0 16px 120px;
    overflow-y: auto;
}

.tab-panel {
    display: none;
    animation: fadeIn 0.3s ease;
}

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

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

.section-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 16px;
    letter-spacing: -0.3px;
}

/* Welcome Card */
.welcome-card {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    border-radius: 20px;
    padding: 24px;
    margin-bottom: 20px;
}

.welcome-card h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.welcome-card p {
    font-size: 17px;
    opacity: 0.9;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 20px;
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 36px;
    font-weight: 700;
    color: var(--accent-blue);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    background: rgba(28, 28, 30, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 8px 0;
    padding-bottom: calc(var(--safe-area-bottom) + 8px);
    border-top: 1px solid var(--separator);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-size: 10px;
    padding: 6px 12px;
    cursor: pointer;
    transition: color 0.2s;
}

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

.nav-item.start-workout {
    position: relative;
    top: -20px;
}

.start-icon {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 4px 20px rgba(10, 132, 255, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
}

.nav-item.start-workout:active .start-icon {
    transform: scale(0.95);
    box-shadow: 0 2px 10px rgba(10, 132, 255, 0.3);
}

/* History List */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-item {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 16px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.history-item:active {
    background: var(--bg-tertiary);
}

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

.history-item-day {
    font-size: 17px;
    font-weight: 600;
}

.history-item-date {
    font-size: 15px;
    color: var(--text-secondary);
}

.history-item-summary {
    font-size: 14px;
    color: var(--text-tertiary);
}

/* Weight Section */
.weight-input-container {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.weight-input-container input {
    flex: 1;
    padding: 14px 16px;
    font-size: 17px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    outline: none;
}

.weight-input-container input:focus {
    border-color: var(--accent-blue);
}

.weight-chart {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 20px;
    height: 200px;
}

.weight-chart canvas {
    width: 100% !important;
    height: 100% !important;
}

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

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

.weight-item-value {
    font-size: 20px;
    font-weight: 600;
}

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

.weight-item-change {
    font-size: 14px;
    font-weight: 500;
}

.weight-item-change.positive {
    color: var(--accent-red);
}

.weight-item-change.negative {
    color: var(--accent-green);
}

/* Exercises List */
.exercises-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.exercise-item {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 16px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.exercise-item:active {
    background: var(--bg-tertiary);
}

.exercise-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.exercise-item-name {
    font-size: 17px;
    font-weight: 600;
}

.exercise-item-day {
    font-size: 13px;
    color: var(--accent-blue);
    background: rgba(10, 132, 255, 0.15);
    padding: 4px 10px;
    border-radius: 20px;
}

.exercise-item-details {
    font-size: 14px;
    color: var(--text-secondary);
}

.empty-state {
    text-align: center;
    color: var(--text-tertiary);
    padding: 40px 20px;
    font-size: 15px;
}

/* Workout Screen */
#workout-screen {
    background: var(--bg-primary);
}

.workout-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 8px;
    padding-top: calc(var(--safe-area-top) + 12px);
    background: var(--bg-primary);
    position: sticky;
    top: 0;
    z-index: 100;
}

.workout-header h1 {
    font-size: 20px;
    font-weight: 600;
}

.workout-exercises {
    flex: 1;
    padding: 16px;
    padding-bottom: calc(var(--safe-area-bottom) + 32px);
    overflow-y: auto;
}

.workout-exercise-card {
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 16px;
}

.workout-exercise-header {
    margin-bottom: 16px;
}

.workout-exercise-name {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 4px;
}

.workout-exercise-last {
    font-size: 14px;
    color: var(--text-secondary);
}

.workout-sets {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.workout-set {
    display: flex;
    align-items: center;
    gap: 12px;
}

.workout-set-number {
    width: 32px;
    height: 32px;
    background: var(--bg-tertiary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

.workout-set-input {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.workout-set-input input {
    width: 70px;
    padding: 12px;
    font-size: 17px;
    font-weight: 600;
    text-align: center;
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    border-radius: 12px;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s;
}

.workout-set-input input:focus {
    border-color: var(--accent-blue);
}

.workout-set-input span {
    font-size: 14px;
    color: var(--text-tertiary);
}

.workout-progress-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 16px;
    padding: 12px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
}

.workout-progress-indicator.improved {
    background: rgba(48, 209, 88, 0.15);
    color: var(--accent-green);
}

.workout-progress-indicator.declined {
    background: rgba(255, 69, 58, 0.15);
    color: var(--accent-red);
}

.workout-progress-indicator.same {
    background: rgba(255, 159, 10, 0.15);
    color: var(--accent-orange);
}

.workout-progress-indicator.waiting {
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    align-items: flex-end;
    justify-content: center;
}

.modal.active {
    display: flex;
    animation: fadeInModal 0.3s ease;
}

@keyframes fadeInModal {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    background: var(--bg-secondary);
    border-radius: 20px 20px 0 0;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

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

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

.modal-header h2 {
    font-size: 20px;
    font-weight: 700;
}

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

.modal-body {
    padding: 20px;
    max-height: 60vh;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    gap: 12px;
    padding: 20px;
    padding-bottom: calc(var(--safe-area-bottom) + 20px);
    border-top: 1px solid var(--separator);
}

.modal-footer .primary-btn {
    flex: 1;
}

.modal-footer .danger-btn {
    flex: 0 0 auto;
}

/* Settings Section */
.settings-section {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--separator);
}

.settings-section h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

/* Session Detail */
.session-detail-exercise {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
}

.session-detail-exercise-name {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.session-detail-sets {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.session-detail-set {
    background: var(--bg-secondary);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-secondary);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 0;
    height: 0;
}

/* Selection */
::selection {
    background: var(--accent-blue);
    color: white;
}

/* Print/Export hidden */
@media print {
    .bottom-nav,
    .app-header button {
        display: none;
    }
}
