* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* PWA Safe Area Support */
body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* Detect standalone mode (installed as PWA) */
@media all and (display-mode: standalone) {
    body {
        padding-top: max(env(safe-area-inset-top), 20px);
    }
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    padding: 20px;
    /* Prevent pull-to-refresh on mobile */
    overscroll-behavior-y: contain;
    /* Prevent text size adjustment on iOS */
    -webkit-text-size-adjust: 100%;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

.header {
    text-align: center;
    color: white;
    margin-bottom: 30px;
}

.header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.beta-badge {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid white;
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.5em;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.footer {
    text-align: center;
    color: white;
    padding: 30px 20px;
    margin-top: 50px;
    border-top: 2px solid rgba(255, 255, 255, 0.2);
}

.footer p {
    margin: 8px 0;
    font-size: 0.9rem;
    line-height: 1.6;
}

.footer a {
    color: white;
    text-decoration: underline;
}

.footer a:hover {
    color: #e2e8f0;
}

.footer .quirky {
    font-style: italic;
    opacity: 0.8;
    margin-top: 10px;
}

.footer .warning {
    background: rgba(255, 255, 255, 0.1);
    padding: 15px;
    border-radius: 8px;
    margin: 15px 0;
    font-size: 0.85rem;
}

.card {
    background: white;
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.card h3 {
    margin-bottom: 1.4rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    margin-bottom: 1.4rem;
    position: relative;
    z-index: 5;
}

.card-header h3 {
    margin: 0;
    flex: 1;
}

.collapse-icon {
    font-size: 1.2rem;
    transition: transform 0.3s;
    margin-left: 10px;
    position: relative;
    z-index: 10;
}

.collapse-icon.collapsed {
    transform: rotate(-90deg);
}

.card-content {
    max-height: none;
    overflow: visible;
    transition: max-height 0.3s ease-out, opacity 0.3s ease-out;
    opacity: 1;
}

.card-content.collapsed {
    max-height: 0;
    opacity: 0;
}

.filter-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.filter-btn {
    padding: 10px 20px;
    border: 2px solid #e2e8f0;
    background: white;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
}

.filter-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.btn {
    background: #667eea;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

.btn:hover {
    background: #5568d3;
}

.btn-small {
    padding: 6px 12px;
    font-size: 14px;
}

.btn-success {
    background: #48bb78;
}

.btn-success:hover {
    background: #38a169;
}

.btn-danger {
    background: #f56565;
}

.btn-danger:hover {
    background: #e53e3e;
}

.btn-warning {
    background: #ed8936;
}

.btn-warning:hover {
    background: #dd6b20;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

label {
    margin-bottom: 5px;
    font-weight: 600;
    color: #4a5568;
}

input, select {
    padding: 10px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    font-size: 14px;
}

.medicine-item {
    background: #f7fafc;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 15px;
    border-left: 4px solid #667eea;
    transition: all 0.3s ease;
}

.medicine-item.collapsed {
    padding: 10px 15px;
}

.medicine-item.editing {
    border-left-color: #ed8936;
    background: #fff9f0;
}

.medicine-item.low-stock {
    border-left-color: #f56565;
    background: #fff5f5;
}

.medicine-header-clickable {
    position: relative;
}

.medicine-header-clickable:hover {
    background: rgba(102, 126, 234, 0.05);
    border-radius: 6px;
    margin: -5px;
    padding: 5px;
}

.collapse-icon-med {
    color: #667eea;
    font-size: 0.9rem;
}

.medicine-details {
    transition: all 0.3s ease;
}

.edit-form, .pickup-form {
    display: none;
    background: white;
    padding: 15px;
    margin-top: 15px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.edit-form.active, .pickup-form.active {
    display: block;
}

.pickup-form {
    background: #f0fff4;
    border: 1px solid #9ae6b4;
}

.pickup-history, .dose-history {
    background: #f7fafc;
    padding: 10px;
    margin-top: 10px;
    border-radius: 6px;
    border-left: 3px solid #48bb78;
}

.pickup-record, .dose-record {
    font-size: 0.8rem;
    color: #4a5568;
    margin-bottom: 5px;
}

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

.medicine-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: #2d3748;
}

.person-badge {
    background: #667eea;
    color: white;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    margin-left: 10px;
}

.status-badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-urgent {
    background: #fed7d7;
    color: #c53030;
}

.status-upcoming {
    background: #feebc8;
    color: #c05621;
}

.status-good {
    background: #c6f6d5;
    color: #2f855a;
}

.quantity-display {
    background: white;
    padding: 15px;
    border-radius: 8px;
    margin: 10px 0;
    border: 2px solid #e2e8f0;
}

.quantity-bar {
    width: 100%;
    height: 30px;
    background: #e2e8f0;
    border-radius: 15px;
    overflow: hidden;
    margin: 10px 0;
}

.quantity-fill {
    height: 100%;
    background: linear-gradient(90deg, #48bb78, #38a169);
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
}

.quantity-fill.low {
    background: linear-gradient(90deg, #f56565, #e53e3e);
}

.quantity-fill.medium {
    background: linear-gradient(90deg, #ed8936, #dd6b20);
}

.dose-tracker {
    background: #f0fff4;
    padding: 15px;
    border-radius: 8px;
    margin-top: 10px;
    border: 2px solid #9ae6b4;
}

.dose-buttons {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.message {
    padding: 10px 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    display: none;
}

.message.success {
    background: #c6f6d5;
    color: #2f855a;
}

.message.error {
    background: #fed7d7;
    color: #c53030;
}

.message.show {
    display: block;
}

.people-manager {
    background: #f7fafc;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
}

.person-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: white;
    padding: 6px 12px;
    border-radius: 20px;
    margin: 5px;
}

.remove-btn {
    background: #f56565;
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 3000;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow-y: auto;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 15px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    max-height: 90vh;
    overflow-y: auto;
    margin: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.modal-icon {
    font-size: 3rem;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: #2d3748;
}

.modal-body {
    margin-bottom: 25px;
    color: #4a5568;
    line-height: 1.6;
    max-height: 60vh;
    overflow-y: auto;
}

.modal-warning {
    background: #fff5f5;
    border-left: 4px solid #f56565;
    padding: 15px;
    margin: 15px 0;
    border-radius: 6px;
}

.modal-warning strong {
    color: #c53030;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.modal-btn-cancel {
    background: #e2e8f0;
    color: #4a5568;
}

.modal-btn-cancel:hover {
    background: #cbd5e0;
}

.modal-btn-delete {
    background: #f56565;
}

.modal-btn-delete:hover {
    background: #e53e3e;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.dashboard-card {
    background: white;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.dashboard-card h3 {
    color: #667eea;
    margin-bottom: 15px;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: #718096;
}

/* Simple View Styles */
#simple-view {
    padding-bottom: 30px;
}

#simple-view .header {
    margin-bottom: 20px;
}

#simple-view .header h1 {
    font-size: 2rem;
}

.person-tabs {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    background: white;
    padding: 15px;
    border-radius: 15px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.person-tab {
    flex: 1;
    min-width: 120px;
    padding: 15px 20px;
    border: 2px solid #e2e8f0;
    background: white;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    text-align: center;
    transition: all 0.3s;
    font-size: 1rem;
}

.person-tab:hover {
    border-color: #667eea;
    transform: translateY(-2px);
}

.person-tab.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.med-list {
    background: white;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.med-list h2 {
    margin-bottom: 15px;
    color: #2d3748;
    font-size: 1.3rem;
}

.med-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    margin-bottom: 12px;
    background: #f7fafc;
    border-radius: 12px;
    border-left: 5px solid #667eea;
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.med-item:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    transform: translateX(5px);
}

.med-item.taken-today {
    opacity: 0.65;
    border-left-color: #48bb78;
    background: #f0fff4;
}

.med-item.low-stock {
    border-left-color: #f56565;
    background: #fff5f5;
}

.med-info {
    flex: 1;
    padding-right: 15px;
}

.med-name {
    font-size: 1.15rem;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 6px;
    line-height: 1.3;
}

.med-dosage {
    font-size: 0.95rem;
    color: #718096;
    margin-bottom: 4px;
}

.med-stock {
    font-size: 0.85rem;
    color: #4a5568;
    font-weight: 500;
}

.med-stock.low {
    color: #c53030;
    font-weight: 600;
}

.take-btn {
    background: #48bb78;
    color: white;
    padding: 14px 28px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1.05rem;
    transition: all 0.3s;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(72, 187, 120, 0.3);
}

.take-btn:hover {
    background: #38a169;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(72, 187, 120, 0.4);
}

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

.take-btn.taken {
    background: #e2e8f0;
    color: #718096;
    cursor: default;
    box-shadow: none;
}

.take-btn.taken:hover {
    transform: none;
    background: #e2e8f0;
}

.summary {
    background: white;
    border-radius: 15px;
    padding: 25px 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 20px;
    text-align: center;
}

.summary-stat {
    padding: 10px;
}

.summary-number {
    font-size: 2.5rem;
    font-weight: 700;
    color: #667eea;
    line-height: 1;
    margin-bottom: 5px;
}

.summary-label {
    font-size: 0.9rem;
    color: #718096;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.empty-simple {
    text-align: center;
    padding: 60px 20px;
    color: #718096;
}

.empty-simple-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-simple h3 {
    font-size: 1.3rem;
    margin-bottom: 10px;
    color: #2d3748;
}

.empty-simple p {
    font-size: 1rem;
    margin-bottom: 20px;
}

@media (max-width: 768px) {
    body {
        padding-top: max(env(safe-area-inset-top, 0px), 130px);
        padding-bottom: max(env(safe-area-inset-bottom, 0px), 20px);
    }
    
    /* Adjust for standalone mode */
    @media all and (display-mode: standalone) {
        body {
            padding-top: max(env(safe-area-inset-top, 0px) + 20px, 140px);
        }
    }
    
    /* Hide main header on mobile */
    #full-view .header,
    #simple-view .header {
        display: none;
    }
    
    #mobile-logo {
        display: block !important;
    }
    
    .header h1 {
        font-size: 2rem;
    }
    
    .medicine-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .dose-buttons {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .person-tab {
        min-width: 100%;
    }
    
    .med-item {
        flex-direction: column;
        gap: 10px;
    }
    
    .take-btn {
        width: 100%;
    }
    
    /* Keep header buttons fixed at top on mobile */
    body > div[style*="position: fixed"][style*="top: 20px"] {
        position: fixed !important;
        top: max(env(safe-area-inset-top, 0px), 10px) !important;
        left: max(env(safe-area-inset-left, 0px), 10px);
        right: max(env(safe-area-inset-right, 0px), 10px);
        width: auto;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        background: rgba(102, 126, 234, 0.98);
        padding: 15px 10px 10px 10px;
        border-radius: 10px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    }
    
    body > div[style*="position: fixed"][style*="top: 20px"] .btn {
        width: auto;
        flex: 1;
        font-size: 0.75rem;
        padding: 8px 10px;
        white-space: nowrap;
    }
    
    .modal-content {
        padding: 20px;
        width: 95%;
        max-height: 85vh;
    }
    
    .modal-body {
        max-height: 55vh;
    }
}

@media (min-width: 800px) {
    #medicine-list {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    .medicine-item {
        margin-bottom: 0;
    }
}