/* =====================================================
   NurtureLink Parent Portal – Mobile-first stylesheet
   ===================================================== */

:root {
    --portal-primary:       #2d7a4f;
    --portal-primary-light: #e8f5ee;
    --portal-primary-dark:  #1f5c39;
    --portal-accent:        #f0a500;
    --portal-bg:            #f4f6f8;
    --portal-card-shadow:   0 2px 12px rgba(0,0,0,0.07);
    --portal-nav-h:         64px;
    --portal-header-h:      56px;
}

/* ── Reset / base ── */
*, *::before, *::after { box-sizing: border-box; }

body.portal-body {
    background: var(--portal-bg);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    margin: 0;
    padding-bottom: var(--portal-nav-h);   /* room for bottom nav */
    min-height: 100vh;
    color: #333;
}

/* ── Top header ── */
.portal-header {
    background: var(--portal-primary);
    color: #fff;
    height: var(--portal-header-h);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 900;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}

.portal-header .portal-logo {
    height: 44px;
    width: auto;
    object-fit: contain;
}

.portal-header .portal-user-info {
    text-align: right;
    line-height: 1.2;
}

.portal-header .portal-user-info .user-name {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
}

.portal-header .portal-user-info .signout-link {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
}

.portal-header .portal-user-info .signout-link:hover {
    color: #fff;
    text-decoration: underline;
}

/* ── Bottom navigation (mobile + tablet) ── */
.portal-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--portal-nav-h);
    background: #fff;
    border-top: 1px solid #dde0e4;
    display: flex;
    z-index: 900;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.07);
}

.portal-bottom-nav .pnav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    text-decoration: none;
    color: #999;
    font-size: 0.68rem;
    font-weight: 500;
    border: none;
    background: none;
    padding: 8px 4px;
    transition: color 0.15s;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.portal-bottom-nav .pnav-item i {
    font-size: 1.45rem;
    line-height: 1;
}

.portal-bottom-nav .pnav-item.active,
.portal-bottom-nav .pnav-item:hover {
    color: var(--portal-primary);
}

.portal-bottom-nav .pnav-item.active {
    font-weight: 700;
}

/* ── Desktop layout (lg and up) ── */
@media (min-width: 992px) {
    body.portal-body {
        padding-bottom: 0;
        display: flex;
        flex-direction: column;
    }

    .portal-bottom-nav {
        display: none;
    }

    .portal-desktop-wrap {
        display: flex;
        flex: 1;
        min-height: calc(100vh - var(--portal-header-h));
    }

    /* Sidebar */
    .portal-sidebar {
        width: 230px;
        flex-shrink: 0;
        background: #fff;
        border-right: 1px solid #e4e8ec;
        padding: 20px 0;
    }

    .portal-sidebar .psidebar-section {
        padding: 6px 16px 2px;
        font-size: 0.68rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        color: #aaa;
        margin-top: 8px;
    }

    .portal-sidebar .psidebar-item {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 11px 20px;
        color: #555;
        text-decoration: none;
        font-size: 0.88rem;
        border-left: 3px solid transparent;
        transition: background 0.15s, color 0.15s, border-color 0.15s;
    }

    .portal-sidebar .psidebar-item i {
        font-size: 1.1rem;
        width: 22px;
        text-align: center;
        flex-shrink: 0;
    }

    .portal-sidebar .psidebar-item:hover {
        background: var(--portal-primary-light);
        color: var(--portal-primary);
        border-left-color: var(--portal-primary);
    }

    .portal-sidebar .psidebar-item.active {
        background: var(--portal-primary-light);
        color: var(--portal-primary);
        border-left-color: var(--portal-primary);
        font-weight: 600;
    }

    /* Main content */
    .portal-content {
        flex: 1;
        padding: 28px 32px;
        overflow-x: hidden;
        max-width: 1100px;
    }
}

/* ── Mobile/tablet content ── */
@media (max-width: 991px) {
    .portal-sidebar {
        display: none;
    }

    .portal-content {
        padding: 16px;
    }
}

/* ── Page heading ── */
.portal-page-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 2px;
}

.portal-page-subtitle {
    font-size: 0.83rem;
    color: #888;
    margin-bottom: 20px;
}

/* ── Cards ── */
.portal-card {
    background: #fff;
    border-radius: 14px;
    padding: 20px;
    box-shadow: var(--portal-card-shadow);
    margin-bottom: 16px;
}

.portal-card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: #222;
    margin-bottom: 2px;
}

.portal-card-subtitle {
    font-size: 0.78rem;
    color: #999;
    margin-bottom: 14px;
}

/* ── Stat tiles ── */
.portal-stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

@media (min-width: 576px) {
    .portal-stat-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.portal-stat {
    background: #fff;
    border-radius: 14px;
    padding: 18px 14px;
    box-shadow: var(--portal-card-shadow);
    text-align: center;
}

.portal-stat .stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 10px;
    font-size: 1.3rem;
}

.portal-stat .stat-icon.green  { background: var(--portal-primary-light); color: var(--portal-primary); }
.portal-stat .stat-icon.amber  { background: #fff8e6; color: #d97706; }
.portal-stat .stat-icon.blue   { background: #eff6ff; color: #2563eb; }
.portal-stat .stat-icon.purple { background: #f5f3ff; color: #7c3aed; }

.portal-stat .stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: #1a1a2e;
    line-height: 1;
}

.portal-stat .stat-label {
    font-size: 0.72rem;
    color: #888;
    margin-top: 4px;
}

/* ── Child item ── */
.child-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 0;
    border-bottom: 1px solid #f0f0f0;
}

.child-row:last-child { border-bottom: none; }

.child-avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--portal-primary-light);
    color: var(--portal-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.05rem;
    flex-shrink: 0;
    text-transform: uppercase;
}

.child-avatar.boy   { background: #dbeafe; color: #1d4ed8; }
.child-avatar.girl  { background: #fce7f3; color: #be185d; }

.child-info .child-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: #222;
    margin: 0;
}

.child-info .child-meta {
    font-size: 0.78rem;
    color: #888;
    margin: 0;
}

/* ── Status badges ── */
.badge-portal {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
}

.badge-present  { background: #d1fae5; color: #065f46; }
.badge-absent   { background: #fee2e2; color: #991b1b; }
.badge-pending  { background: #fef3c7; color: #92400e; }
.badge-paid     { background: #d1fae5; color: #065f46; }
.badge-overdue  { background: #fee2e2; color: #991b1b; }
.badge-sent     { background: #eff6ff; color: #1e40af; }

/* ── Table wrapper (horizontal scroll on mobile) ── */
.portal-table-wrap {
    overflow-x: auto;
    border-radius: 10px;
    -webkit-overflow-scrolling: touch;
}

.portal-table-wrap table {
    min-width: 520px;
    width: 100%;
}

.portal-table-wrap th {
    background: #f8f9fb;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #777;
    border-bottom: 1px solid #eee;
    padding: 10px 14px;
    white-space: nowrap;
}

.portal-table-wrap td {
    padding: 12px 14px;
    font-size: 0.87rem;
    border-bottom: 1px solid #f4f4f4;
    vertical-align: middle;
}

/* ── Buttons ── */
.btn-portal-primary {
    background: var(--portal-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    text-decoration: none;
    display: inline-block;
}

.btn-portal-primary:hover {
    background: var(--portal-primary-dark);
    color: #fff;
}

.btn-portal-outline {
    background: transparent;
    color: var(--portal-primary);
    border: 1.5px solid var(--portal-primary);
    border-radius: 8px;
    padding: 9px 18px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    display: inline-block;
}

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

/* ── Form controls ── */
.portal-form-control {
    border-radius: 8px;
    padding: 10px 14px;
    border: 1.5px solid #e0e4e8;
    font-size: 0.9rem;
    width: 100%;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: #fff;
}

.portal-form-control:focus {
    outline: none;
    border-color: var(--portal-primary);
    box-shadow: 0 0 0 3px rgba(45,122,79,0.12);
}

.portal-form-label {
    font-size: 0.83rem;
    font-weight: 600;
    color: #444;
    margin-bottom: 5px;
    display: block;
}

/* ── Empty state ── */
.portal-empty {
    text-align: center;
    padding: 40px 20px;
    color: #aaa;
}

.portal-empty i {
    font-size: 3rem;
    margin-bottom: 12px;
    display: block;
}

.portal-empty p {
    font-size: 0.9rem;
    margin: 0;
}

/* ── Login page ── */
body.portal-login-body {
    background: linear-gradient(135deg, var(--portal-primary-dark) 0%, var(--portal-primary) 60%, #3a9a60 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

.portal-login-card {
    background: #fff;
    border-radius: 18px;
    padding: 36px 32px 32px;
    width: 100%;
    max-width: 430px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.22);
}

@media (max-width: 480px) {
    .portal-login-card { padding: 28px 20px 24px; }
}

.portal-login-card .login-logo {
    max-height: 60px;
    width: auto;
    margin-bottom: 26px;
}

.portal-login-card h1 {
    font-size: 1.55rem;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 4px;
}

.portal-login-card .login-sub {
    font-size: 0.83rem;
    color: #888;
    margin-bottom: 28px;
}

.portal-login-card .form-group {
    margin-bottom: 18px;
}

.portal-login-card .form-group label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #444;
    display: block;
    margin-bottom: 6px;
}

.portal-login-card .form-group input {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid #e0e4e8;
    border-radius: 9px;
    font-size: 0.95rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.portal-login-card .form-group input:focus {
    outline: none;
    border-color: var(--portal-primary);
    box-shadow: 0 0 0 3px rgba(45,122,79,0.13);
}

.btn-portal-login {
    width: 100%;
    padding: 13px;
    background: var(--portal-primary);
    color: #fff;
    border: none;
    border-radius: 9px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s;
    margin-top: 8px;
}

.btn-portal-login:hover { background: var(--portal-primary-dark); }

.portal-login-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 0.8rem;
    color: #aaa;
}

.portal-login-footer a {
    color: var(--portal-primary);
    text-decoration: none;
    font-weight: 600;
}

/* ── Alerts ── */
.portal-alert {
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 0.87rem;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.portal-alert.alert-danger  { background: #fee2e2; color: #991b1b; }
.portal-alert.alert-success { background: #d1fae5; color: #065f46; }
.portal-alert.alert-info    { background: #eff6ff; color: #1e40af; }

/* ── Document icon sizing ── */
.doc-icon { font-size: 1.4rem; }

/* ── Responsive utilities ── */
@media (max-width: 575px) {
    .portal-page-title { font-size: 1.15rem; }
    .portal-card { padding: 16px; }
}

/* ── 7-tab bottom nav: reduce icon size to fit ── */
.portal-bottom-nav .pnav-item i {
    font-size: 1.2rem;
}

/* ── Nav badges (unread count) ── */
.pnav-badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 20px);
    background: #dc2626;
    color: #fff;
    border-radius: 10px;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 1px 5px;
    line-height: 1.4;
    pointer-events: none;
}

.portal-nav-badge {
    margin-left: auto;
    background: #dc2626;
    color: #fff;
    border-radius: 10px;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 1px 7px;
    line-height: 1.4;
}

/* ── Activity Feed ── */
.feed-date-sep {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #aaa;
    padding: 4px 4px 8px;
    margin-top: 8px;
}

.feed-card {
    margin-bottom: 10px;
}

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

.feed-type-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.feed-meta {
    flex: 1;
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.feed-child-name {
    font-size: 0.82rem;
    font-weight: 700;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.feed-time {
    font-size: 0.75rem;
    color: #bbb;
    margin-left: auto;
    flex-shrink: 0;
}

.feed-content {
    padding-left: 46px;
}

.feed-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #1a1a2e;
    margin-bottom: 3px;
}

.feed-body-text {
    font-size: 0.83rem;
    color: #666;
    line-height: 1.5;
}

.feed-photo {
    width: 100%;
    border-radius: 10px;
    margin-top: 10px;
    display: block;
}

@media (max-width: 575px) {
    .feed-content { padding-left: 0; margin-top: 6px; }
}

/* ── Chat / Messages ── */
.chat-thread {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
}

.chat-bubble {
    max-width: 78%;
    display: flex;
    flex-direction: column;
}

.chat-bubble.mine   { align-self: flex-end;   align-items: flex-end; }
.chat-bubble.theirs { align-self: flex-start; align-items: flex-start; }

.bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 0.88rem;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap; /* preserve line breaks in messages */
}

.chat-bubble.mine   .bubble { background: var(--portal-primary); color: #fff; border-bottom-right-radius: 4px; }
.chat-bubble.theirs .bubble { background: #f0f0f0; color: #333; border-bottom-left-radius: 4px; }

.bubble-sender {
    font-size: 0.72rem;
    font-weight: 700;
    color: #888;
    margin-bottom: 3px;
    padding: 0 4px;
}

.bubble-meta {
    font-size: 0.7rem;
    color: #bbb;
    margin-top: 4px;
    padding: 0 4px;
}

.chat-input-wrap {
    border-top: 1px solid #f0f0f0;
    padding: 12px 16px;
    background: #fff;
    border-radius: 0 0 14px 14px;
}

.chat-form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-textarea {
    flex: 1;
    border: 1.5px solid #e0e4e8;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 0.9rem;
    resize: none;
    outline: none;
    font-family: inherit;
    transition: border-color 0.15s;
}

.chat-textarea:focus { border-color: var(--portal-primary); }

.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: none;
    background: var(--portal-primary);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.chat-send-btn:hover { background: var(--portal-primary-dark); }

/* ── CRM Messages layout ── */
.crm-msg-wrap {
    display: flex;
    height: calc(100vh - 180px);
    min-height: 500px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.07);
    overflow: hidden;
}

.crm-msg-sidebar {
    width: 300px;
    flex-shrink: 0;
    border-right: 1px solid #eee;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.crm-msg-sidebar-header {
    padding: 14px 16px;
    font-weight: 700;
    font-size: 0.9rem;
    color: #333;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 8px;
}

.crm-unread-badge {
    background: #dc2626;
    color: #fff;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 1px 7px;
}

.crm-msg-empty {
    padding: 40px 20px;
    text-align: center;
    color: #aaa;
    font-size: 0.85rem;
}

.crm-conv-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid #f5f5f5;
    text-decoration: none;
    color: inherit;
    transition: background 0.12s;
    cursor: pointer;
}

.crm-conv-item:hover  { background: #f8f8f8; }
.crm-conv-item.active { background: #e8f5ee; }
.crm-conv-item.unread .crm-conv-name { font-weight: 700; }

.crm-conv-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #e8f5ee;
    color: #2d7a4f;
    font-weight: 700;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.crm-conv-info { flex: 1; min-width: 0; }
.crm-conv-name    { font-size: 0.88rem; color: #222; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crm-conv-preview { font-size: 0.76rem; color: #999; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

.crm-conv-meta { text-align: right; flex-shrink: 0; }
.crm-conv-time { font-size: 0.7rem; color: #bbb; }
.crm-unread-dot {
    display: inline-block;
    background: #dc2626;
    color: #fff;
    border-radius: 10px;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 5px;
    margin-top: 4px;
}

.crm-msg-thread {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.crm-thread-header {
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    background: #fff;
    flex-shrink: 0;
}

.crm-thread-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #fafafa;
}

.crm-thread-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
}

.crm-reply-wrap {
    border-top: 1px solid #eee;
    padding: 12px 16px;
    background: #fff;
    flex-shrink: 0;
}

/* CRM chat bubbles: staff = right/green, parent = left/gray */
.crm-thread-messages .chat-bubble.mine   .bubble { background: #2d7a4f; color: #fff; }
.crm-thread-messages .chat-bubble.theirs .bubble { background: #f0f0f0; color: #333; }

@media (max-width: 767px) {
    .crm-msg-sidebar { width: 100%; border-right: none; }
    .crm-msg-thread  { width: 100%; }
}
