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

:root {
    --primary: #4f46e5;
    --primary-light: #6366f1;
    --primary-bg: #eef2ff;
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius: 14px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100%;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

.screen { height: 100%; }

/* ===== INSTALL SCREEN ===== */
.install-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 32px 24px;
    text-align: center;
    background: linear-gradient(160deg, #eef2ff 0%, #e0e7ff 50%, #c7d2fe 100%);
}

.install-logo { margin-bottom: 16px; }

.install-logo-circle {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    background: var(--primary);
    color: #fff;
    font-size: 36px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    box-shadow: 0 8px 32px rgba(79, 70, 229, 0.3);
}

.install-page h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.install-subtitle {
    color: var(--text-secondary);
    font-size: 15px;
    margin-bottom: 32px;
}

.install-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.06);
}

.install-text {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 20px;
}

.install-instructions {
    text-align: left;
    margin-top: 16px;
}

.install-instructions p {
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--text);
    line-height: 1.5;
}

/* ===== AUTH SCREEN ===== */
.auth-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 32px 24px;
    text-align: center;
    background: var(--bg);
}

.auth-page h2 {
    font-size: 22px;
    margin-top: 16px;
    margin-bottom: 8px;
}

.auth-message {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 24px;
    max-width: 300px;
    line-height: 1.5;
}

/* ===== BUTTONS ===== */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 14px 28px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    width: 100%;
}

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

.btn-lg { padding: 16px 32px; font-size: 16px; }

.btn-link {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    margin-top: 20px;
    text-decoration: underline;
}

/* ===== APP HEADER ===== */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    padding-top: env(safe-area-inset-top, 0px);
}

.header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 17px;
    font-weight: 600;
}

.header-logo {
    width: 30px;
    height: 30px;
    background: rgba(255,255,255,0.2);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
}

.header-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    transition: background 0.2s;
}

.header-btn:hover { background: rgba(255,255,255,0.25); }

/* ===== APP MAIN ===== */
.app-main {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: calc(60px + var(--safe-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-top: env(safe-area-inset-top, 0px);
}

.page { display: none; min-height: 100%; padding: 16px; }
.page.active { display: block; }

.page-loader {
    text-align: center;
    padding: 60px 0;
    color: var(--text-muted);
    font-size: 24px;
}

/* ===== BOTTOM NAV ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(60px + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 100;
}

.nav-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 10px;
    font-weight: 500;
    transition: color 0.2s;
    position: relative;
    padding: 8px 0;
}

.nav-tab i { font-size: 20px; }

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

.nav-badge {
    position: absolute;
    top: 4px;
    right: 50%;
    transform: translateX(14px);
    background: var(--danger);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* ===== EVENTS ===== */
.events-list { display: flex; flex-direction: column; gap: 12px; }

.event-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.04);
    border-left: 4px solid var(--primary);
}

.event-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.event-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--primary-bg);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.event-card-title {
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
}

.event-card-details {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-left: 50px;
}

.event-detail {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
}

.event-detail i {
    width: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.event-detail .event-time {
    font-weight: 600;
    color: var(--text);
}

.event-card-header {
    flex-wrap: wrap;
}

.event-status-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    margin-left: auto;
    white-space: nowrap;
}
.event-status-badge.status-completed {
    background: #dcfce7; color: #16a34a;
}
.event-status-badge.status-cancelled {
    background: #fee2e2; color: #dc2626;
}
.event-status-badge.status-rescheduled {
    background: #fef3c7; color: #d97706;
}
.event-status-badge.status-upcoming {
    background: #dbeafe; color: #2563eb;
}

.event-card.status-completed {
    border-left-color: #16a34a;
}
.event-card.status-cancelled {
    border-left-color: #dc2626;
    opacity: 0.7;
}
.event-card.status-rescheduled {
    border-left-color: #d97706;
}

.event-rescheduled-note {
    font-size: 12px !important;
    color: #d97706 !important;
    font-style: italic;
}

/* ===== CHAT ===== */
#page-chat {
    display: none;
    flex-direction: column;
    padding: 0;
    height: 100%;
}

#page-chat.active {
    display: flex;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.4;
    word-break: break-word;
}

.chat-msg.mine {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg.theirs {
    align-self: flex-start;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.chat-msg-sender {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 2px;
    opacity: 0.7;
}

.chat-msg-time {
    font-size: 10px;
    opacity: 0.6;
    text-align: right;
    margin-top: 4px;
}

.chat-input-bar {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    padding-bottom: calc(10px + var(--safe-bottom));
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#chat-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.2s;
}

#chat-input:focus { border-color: var(--primary); }

.btn-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: background 0.2s;
}

.btn-send:hover { background: var(--primary-light); }

/* ===== SERVICES ===== */
.services-list { display: flex; flex-direction: column; gap: 10px; }

.service-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.04);
    display: flex;
    align-items: center;
    gap: 12px;
}

.service-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #ecfdf5;
    color: var(--success);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.service-info { flex: 1; min-width: 0; }

.service-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
    margin-bottom: 2px;
}

.service-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.service-status {
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    flex-shrink: 0;
}

.service-status.active { background: #ecfdf5; color: #059669; }
.service-status.completed { background: #f0f9ff; color: #0284c7; }
.service-status.cancelled { background: #fef2f2; color: #dc2626; }

/* ===== EMPTY STATE ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 24px;
    color: var(--text-muted);
    text-align: center;
}

.empty-state i { font-size: 48px; margin-bottom: 16px; opacity: 0.4; }
.empty-state p { font-size: 15px; font-weight: 500; }
.empty-hint { font-size: 13px; margin-top: 4px; opacity: 0.7; }

/* ===== DATE SEPARATOR ===== */
.date-sep {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    padding: 12px 0 4px;
}

/* ===== HOMEWORK ===== */
.hw-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.04);
    border-left: 4px solid var(--primary);
    margin-bottom: 12px;
}
.hw-card.hw-done { border-left-color: #16a34a; }
.hw-card.hw-cancelled { border-left-color: #dc2626; opacity: 0.7; }

.hw-card-header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    flex-wrap: wrap;
}
.hw-card-icon {
    width: 38px; height: 38px;
    border-radius: 10px;
    background: #ede9fe; color: #7c3aed;
    display: flex; align-items: center; justify-content: center;
    font-size: 17px; flex-shrink: 0;
}
.hw-card-info { flex: 1; min-width: 0; }
.hw-card-title { font-weight: 600; font-size: 14px; color: var(--text); }
.hw-card-meta {
    display: flex; gap: 12px;
    font-size: 12px; color: var(--text-muted); margin-top: 3px;
}
.hw-card-meta i { margin-right: 3px; }

.hw-status-badge {
    font-size: 11px; font-weight: 600;
    padding: 3px 10px; border-radius: 20px;
    white-space: nowrap; flex-shrink: 0;
}
.hw-status-badge.hw-done { background: #dcfce7; color: #16a34a; }
.hw-status-badge.hw-cancelled { background: #fee2e2; color: #dc2626; }
.hw-status-badge.hw-pending { background: #dbeafe; color: #2563eb; }

.hw-card-desc {
    margin-top: 10px;
    padding: 10px 12px;
    background: #f9fafb;
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

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