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

:root {
    --primary: #4a90d9;
    --primary-dark: #3a7bc8;
    --green: #4caf50;
    --green-dark: #388e3c;
    --yellow: #ff9800;
    --red: #f44336;
    --red-dark: #d32f2f;
    --bg: #f5f5f5;
    --card-bg: #ffffff;
    --text: #212121;
    --text-secondary: #666666;
    --border: #e0e0e0;
    --radius: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121212;
        --card-bg: #1e1e1e;
        --text: #e0e0e0;
        --text-secondary: #aaaaaa;
        --border: #333333;
        --shadow: 0 2px 8px rgba(0,0,0,0.3);
    }
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding-bottom: 80px;
}

/* === Navigation === */
header {
    background: var(--primary);
    color: white;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    max-width: 600px;
    margin: 0 auto;
}

.nav-brand {
    color: white;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.1rem;
}

.nav-links {
    display: flex;
    gap: 16px;
}

.nav-links a {
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    font-size: 0.9rem;
}

/* === Main content === */
main {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
}

/* === Flash Messages === */
.flash-messages {
    margin-bottom: 16px;
}

.flash {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.flash-success {
    background: #e8f5e9;
    color: #2e7d32;
}

.flash-error {
    background: #ffebee;
    color: #c62828;
}

@media (prefers-color-scheme: dark) {
    .flash-success { background: #1b3a1b; color: #81c784; }
    .flash-error { background: #3a1b1b; color: #ef9a9a; }
}

/* === Login === */
.login-container {
    text-align: center;
    padding-top: 60px;
}

.login-container h1 {
    font-size: 1.8rem;
    margin-bottom: 8px;
    color: var(--primary);
}

.login-subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.pin-display {
    margin-bottom: 24px;
}

.pin-dots {
    display: flex;
    justify-content: center;
    gap: 16px;
}

.pin-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    transition: background 0.15s;
}

.pin-dot.filled {
    background: var(--primary);
}

.pin-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-width: 280px;
    margin: 0 auto;
}

.pin-key {
    width: 100%;
    aspect-ratio: 1.3;
    border: none;
    border-radius: var(--radius);
    background: var(--card-bg);
    color: var(--text);
    font-size: 1.5rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow);
    min-height: 56px;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.1s;
}

.pin-key:active {
    transform: scale(0.95);
}

.pin-key-empty {
    visibility: hidden;
}

.pin-key-del {
    font-size: 1.3rem;
}

/* === Dashboard === */
.dashboard h2 {
    font-size: 1.1rem;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.medicine-section {
    margin-bottom: 24px;
}

.medicine-buttons {
    display: flex;
    gap: 12px;
}

.medicine-card {
    flex: 1;
    text-align: center;
}

.medicine-btn {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: var(--radius);
    color: white;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    min-height: 56px;
    box-shadow: var(--shadow);
    transition: opacity 0.2s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.medicine-btn:active {
    transform: scale(0.97);
}

.medicine-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.medicine-btn-panodil {
    background: var(--primary);
}

.medicine-btn-ipren {
    background: var(--green);
}

.medicine-status {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 8px;
    min-height: 2.4em;
}

/* === Entry List === */
.entries-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.entry-card {
    display: block;
    text-decoration: none;
    color: var(--text);
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--border);
    transition: transform 0.1s;
}

.entry-card:active {
    transform: scale(0.99);
}

.entry-card.severity-light { border-left-color: var(--green); }
.entry-card.severity-medium { border-left-color: var(--yellow); }
.entry-card.severity-severe { border-left-color: var(--red); }

.entry-date {
    font-weight: 600;
    margin-bottom: 4px;
}

.entry-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.entry-meds {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
}

/* === FAB === */
.fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-size: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    box-shadow: 0 4px 12px rgba(74,144,217,0.4);
    z-index: 50;
    transition: transform 0.1s;
    line-height: 1;
}

.fab:active {
    transform: scale(0.9);
}

/* === Forms === */
.form-container, .report-container, .detail-container {
    padding-bottom: 20px;
}

.form-container h1, .report-container h1, .detail-container h1 {
    font-size: 1.4rem;
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group > label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.95rem;
}

.form-input {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--card-bg);
    color: var(--text);
    font-size: 16px;  /* Prevents iOS zoom */
    -webkit-appearance: none;
    appearance: none;
}

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

.form-row {
    display: flex;
    gap: 12px;
}

.form-group-half {
    flex: 1;
}

/* === Toggle Buttons === */
.toggle-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.toggle-btn {
    position: relative;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.toggle-btn input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-btn span {
    display: inline-block;
    padding: 12px 20px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    transition: all 0.15s;
    min-width: 56px;
    min-height: 48px;
    text-align: center;
    background: var(--card-bg);
    line-height: 1.2;
}

.toggle-btn input:checked + span {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* Severity-specific colors */
.toggle-severity-light input:checked + span {
    background: var(--green);
    border-color: var(--green);
}

.toggle-severity-medium input:checked + span {
    background: var(--yellow);
    border-color: var(--yellow);
    color: #333;
}

.toggle-severity-severe input:checked + span {
    background: var(--red);
    border-color: var(--red);
}

/* === Medication rows === */
.med-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.med-name {
    flex: 2;
}

.med-amount {
    flex: 1;
}

.med-time {
    flex: 1.2;
}

/* === Buttons === */
.btn-save {
    width: 100%;
    padding: 16px;
    background: var(--green);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    min-height: 56px;
    box-shadow: var(--shadow);
    margin-top: 8px;
    -webkit-tap-highlight-color: transparent;
}

.btn-save:active {
    opacity: 0.9;
}

.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    min-height: 48px;
    line-height: 1.8;
    -webkit-tap-highlight-color: transparent;
}

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

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

.btn-back {
    background: var(--card-bg);
    color: var(--text);
    border: 2px solid var(--border);
    display: block;
    text-align: center;
    margin-top: 20px;
}

.btn-preset {
    background: var(--card-bg);
    color: var(--text);
    border: 2px solid var(--border);
    padding: 10px 16px;
}

.btn-preset:active {
    border-color: var(--primary);
    color: var(--primary);
}

.inline-form {
    display: inline;
}

/* === Detail View === */
.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 8px;
}

.detail-actions {
    display: flex;
    gap: 8px;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.detail-item {
    background: var(--card-bg);
    padding: 12px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.detail-item-full {
    grid-column: 1 / -1;
}

.detail-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.detail-value {
    font-weight: 600;
    font-size: 0.95rem;
}

.severity-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    color: white;
    font-size: 0.85rem;
}

.severity-badge.severity-light { background: var(--green); }
.severity-badge.severity-medium { background: var(--yellow); color: #333; }
.severity-badge.severity-severe { background: var(--red); }

.med-detail {
    margin-bottom: 4px;
}

/* === Report Page === */
.report-form {
    margin-top: 16px;
}

.preset-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

/* === Utilities === */
select.form-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

textarea.form-input {
    resize: vertical;
    min-height: 60px;
}

/* === Active Episode Banner === */
.active-episode-banner {
    background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
    border: 2px solid var(--green);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 20px;
}

@media (prefers-color-scheme: dark) {
    .active-episode-banner {
        background: linear-gradient(135deg, #1b3a1b, #243824);
        border-color: var(--green);
    }
}

.active-episode-inner {
    display: flex;
    align-items: center;
    gap: 12px;
}

.active-episode-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--green);
    flex-shrink: 0;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.2); }
}

.active-episode-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.active-episode-label {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--green-dark);
}

@media (prefers-color-scheme: dark) {
    .active-episode-label { color: #81c784; }
}

.active-episode-time {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.btn-active-episode {
    background: var(--green);
    color: white;
    padding: 10px 18px;
    border-radius: var(--radius);
    font-weight: 700;
    text-decoration: none;
    font-size: 0.9rem;
    white-space: nowrap;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}

/* === Active Episode Page === */
.episode-container {
    padding-bottom: 20px;
}

.episode-header {
    margin-bottom: 24px;
}

.episode-header h1 {
    font-size: 1.4rem;
    margin-bottom: 4px;
}

.episode-started {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.episode-container .medicine-section {
    margin-bottom: 24px;
}

.episode-container h2 {
    font-size: 1.1rem;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

/* === Snapshots === */
.snapshots-section {
    margin-top: 24px;
    margin-bottom: 24px;
}

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

.snapshot-item {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 12px 14px;
    box-shadow: var(--shadow);
    border-left: 3px solid var(--primary);
}

.snapshot-time {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.snapshot-details {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.snapshot-nausea {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.snapshot-note {
    font-size: 0.85rem;
    color: var(--text);
    font-style: italic;
    width: 100%;
    margin-top: 2px;
}

/* === Snapshot Form === */
.snapshot-form-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.snapshot-form .form-group {
    margin-bottom: 14px;
}

.snapshot-form .form-group > label {
    font-size: 0.9rem;
}

/* === Finish Episode === */
.episode-finish {
    margin-top: 8px;
}

.btn-finish-episode {
    display: block;
    width: 100%;
    text-align: center;
    padding: 16px;
    background: var(--yellow);
    color: #333;
    font-weight: 700;
    font-size: 1rem;
    border-radius: var(--radius);
    text-decoration: none;
    box-shadow: var(--shadow);
    min-height: 56px;
    line-height: 1.5;
}

/* === Form subtitle === */
.form-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: -12px;
    margin-bottom: 20px;
}
