/* mediCron - Main Stylesheet */
/* Supports Arabic (RTL) and English (LTR) */

:root {
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --primary-dark: #3730a3;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --header-bg: #4f46e5;
    --header-text: #ffffff;
    --nav-bg: #ffffff;
    --nav-active: #eef2ff;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #334155;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.3);
    --header-bg: #1e293b;
    --header-text: #f1f5f9;
    --nav-bg: #1e293b;
    --nav-active: #334155;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans Arabic', 'Noto Kufi Arabic', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* RTL support */
html[dir="rtl"] body { font-family: 'Noto Sans Arabic', 'Noto Kufi Arabic', Tahoma, -apple-system, BlinkMacSystemFont, sans-serif; }

/* Screen management */
.screen { display: none; }
.screen.active { display: flex; }

/* Auth Screen */
#auth-screen {
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    padding: 20px;
}

.auth-container {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}

.auth-brand { text-align: center; margin-bottom: 30px; }
.auth-brand h1 { font-size: 2rem; color: var(--primary); }
.auth-brand p { color: var(--text-secondary); margin-top: 5px; }

.auth-tabs { display: flex; margin-bottom: 25px; border-bottom: 2px solid var(--border); }
.auth-tab {
    flex: 1;
    padding: 12px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}
.auth-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.auth-form { display: none; }
.auth-form.active { display: block; }

/* Forms */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; color: var(--text); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.error-message { color: var(--danger); margin-top: 10px; font-size: 0.9rem; }
.success-message { color: var(--success); margin-top: 10px; font-size: 0.9rem; }

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--text-secondary); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 6px 14px; font-size: 0.85rem; }
.btn-full { width: 100%; justify-content: center; padding: 14px; }
.btn-xs { padding: 4px 10px; font-size: 0.8rem; }

/* Main App Layout */
#main-screen { display: none; flex-direction: column; min-height: 100vh; }
#main-screen.active { display: flex; }

/* Header */
#app-header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}
#app-header h2 { font-size: 1.3rem; }
.header-right { display: flex; align-items: center; gap: 10px; }
.user-name { font-weight: 500; }
.btn-logout { background: rgba(255,255,255,0.2); color: #fff; }
.btn-logout:hover { background: rgba(255,255,255,0.3); }

/* Navigation */
#app-nav {
    display: flex;
    overflow-x: auto;
    background: var(--nav-bg);
    border-bottom: 1px solid var(--border);
    padding: 5px;
    gap: 2px;
    position: sticky;
    top: 52px;
    z-index: 99;
}
.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 14px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all 0.2s;
    min-width: 65px;
    flex-shrink: 0;
}
.nav-item:hover { background: var(--nav-active); color: var(--primary); }
.nav-item.active { background: var(--nav-active); color: var(--primary); }
.nav-icon { font-size: 1.4rem; }
.nav-label { font-size: 0.7rem; margin-top: 2px; font-weight: 500; }

/* Content */
#content-area { flex: 1; padding: 20px; max-width: 1200px; margin: 0 auto; width: 100%; }
.page { display: none; }
.page.active { display: block; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}
.page-header h2 { font-size: 1.4rem; }
.header-actions { display: flex; gap: 10px; align-items: center; }

/* Dashboard Stats */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 25px;
}
.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    box-shadow: var(--shadow);
}
.stat-card h3 { font-size: 2rem; color: var(--primary); }
.stat-card p { color: var(--text-secondary); margin-top: 5px; }

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 15px;
    border: 1px solid var(--border);
}
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-header h3 { font-size: 1.1rem; }

/* Medications */
.medicine-card {
    border-left: 5px solid;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 10px;
}
.medicine-info h4 { margin-bottom: 5px; }
.medicine-meta { color: var(--text-secondary); font-size: 0.9rem; }
.medicine-image { width: 60px; height: 60px; object-fit: cover; border-radius: var(--radius-sm); }
.medicine-actions { display: flex; gap: 5px; flex-wrap: wrap; }
.medicine-times { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.time-badge {
    background: var(--nav-active);
    color: var(--primary);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}

/* Dose List */
.dose-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 8px;
}
.dose-item:last-child { border-bottom: none; }
.dose-status {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}
.status-taken { background: #dcfce7; color: #166534; }
.status-skipped { background: #fee2e2; color: #991b1b; }
.status-pending { background: #fef3c7; color: #92400e; }
[data-theme="dark"] .status-taken { background: #14532d; color: #dcfce7; }
[data-theme="dark"] .status-skipped { background: #450a0a; color: #fee2e2; }
[data-theme="dark"] .status-pending { background: #451a03; color: #fef3c7; }

.dose-actions { display: flex; gap: 5px; align-items: center; }
.dose-recorder { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; }

/* Care Network */
.care-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 10px;
    border: 1px solid var(--border);
}
.care-info { display: flex; align-items: center; gap: 12px; }
.care-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: var(--primary-light);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: bold;
}
.share-code-box {
    background: var(--nav-active);
    padding: 15px;
    border-radius: var(--radius-sm);
    text-align: center;
    font-family: monospace;
    font-size: 1.5rem;
    letter-spacing: 3px;
    margin: 15px 0;
    user-select: all;
}

/* Messages */
.message-item {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.message-item:hover { background: var(--nav-active); }
.message-bubble {
    flex: 1;
    padding: 10px 14px;
    border-radius: var(--radius);
    max-width: 70%;
}
.message-bubble.sent { background: var(--primary); color: #fff; }
.message-bubble.received { background: var(--border); }
.message-meta { font-size: 0.75rem; color: var(--text-secondary); margin-top: 4px; }
.unread-dot {
    width: 8px; height: 8px; border-radius: 50%; background: var(--danger); display: inline-block;
}

/* AI Chat */
.ai-container {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    border: 1px solid var(--border);
}
.ai-chat {
    height: 400px;
    overflow-y: auto;
    padding: 20px;
}
.ai-message { margin-bottom: 15px; padding: 12px; border-radius: var(--radius); max-width: 80%; }
.ai-message.user { background: var(--primary); color: #fff; margin-left: auto; }
.ai-message.bot { background: var(--border); }
.ai-input-area {
    display: flex;
    gap: 10px;
    padding: 15px;
    border-top: 1px solid var(--border);
}
.ai-input-area textarea {
    flex: 1;
    padding: 10px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    resize: none;
    height: 45px;
}
.ai-input-area textarea:focus { outline: none; border-color: var(--primary); }

/* Settings */
.settings-sections { max-width: 600px; }
.settings-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 15px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
.settings-section h3 { margin-bottom: 15px; }
.setting-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border-bottom: none; }
.setting-row label { font-weight: 500; }

/* Toggle Switch */
.toggle { position: relative; width: 48px; height: 26px; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--border);
    border-radius: 26px;
    transition: 0.3s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    height: 20px; width: 20px;
    left: 3px; bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(22px); }

/* Range */
input[type="range"] { accent-color: var(--primary); }

/* Admin */
.admin-nav { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.data-table th, .data-table td {
    padding: 12px 15px;
    text-align: right;
    border-bottom: 1px solid var(--border);
}
.data-table th { background: var(--nav-active); font-weight: 600; }
.data-table tr:hover { background: var(--nav-active); }

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
}
.modal {
    background: var(--surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 550px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 { font-size: 1.2rem; }
.modal-body { padding: 20px; }
.modal-footer { padding: 15px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.modal-close {
    background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-secondary);
}

/* File upload */
.file-input-wrapper { position: relative; overflow: hidden; display: inline-block; }
.file-input-wrapper input[type=file] { position: absolute; left: 0; top: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

/* Loading */
.loading { text-align: center; padding: 40px; color: var(--text-secondary); }

/* Empty state */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-secondary); }
.empty-state .icon { font-size: 3rem; margin-bottom: 10px; }

/* Responsive */
@media (max-width: 768px) {
    .auth-container { padding: 25px; }
    .dashboard-stats { grid-template-columns: repeat(2, 1fr); }
    .page-header { flex-direction: column; align-items: flex-start; }
    .medicine-card { flex-direction: column; }
    .ai-message { max-width: 90%; }
    .header-right { gap: 5px; }
}

@media (max-width: 480px) {
    .dashboard-stats { grid-template-columns: 1fr; }
    .nav-label { display: none; }
    .nav-item { min-width: 50px; padding: 8px 10px; }
}

/* Notification animation */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}
.notification-pulse { animation: pulse 0.5s ease-in-out; }

/* Sound indicator */
.sound-indicator {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: var(--primary);
    color: #fff;
    padding: 10px 15px;
    border-radius: 50%;
    font-size: 1.2rem;
    display: none;
    z-index: 50;
    box-shadow: var(--shadow-lg);
}
.sound-indicator.active { display: block; animation: pulse 0.5s; }
