/* ===========================================
   Motelo Student Accommodation — main.css
   worksolutions.co.za/student-accommodation
   Mobile-first, CSS custom properties
   =========================================== */

/* --- Variables --- */
:root {
    --color-primary:    #1a3c5e;
    --color-primary-lt: #2563a8;
    --color-primary-deep: #0f2440;
    --color-accent:     #f59e0b;
    --color-success:    #16a34a;
    --color-danger:     #dc2626;
    --color-warning:    #f97316;
    --color-info:       #0891b2;
    --color-bg:         #f4f7fc;
    --color-surface:    #ffffff;
    --color-border:     #dde5f0;
    --color-text:       #1e293b;
    --color-muted:      #64748b;
    --color-sky:         #e8f1fb;
    
    --font-display:     'DM Serif Display', Georgia, serif;
    --font-body:        'DM Sans', system-ui, sans-serif;
    --font-mono:        'JetBrains Mono', monospace;
    
    --radius:           8px;
    --radius-lg:        16px;
    --shadow:           0 1px 3px rgba(15,36,64,.08), 0 1px 2px rgba(15,36,64,.05);
    --shadow-md:        0 4px 16px rgba(15,36,64,.10);
    --shadow-lg:        0 12px 40px rgba(15,36,64,.15);
    --transition:       0.2s ease;
    --bottom-nav-h:     64px;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body { 
    font-family: var(--font-body); 
    background: var(--color-bg); 
    color: var(--color-text); 
    line-height: 1.65; 
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--color-primary-lt); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Top Bar --- */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    height: 56px;
    background: var(--color-primary);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-md);
}
.top-bar__brand { display: flex; align-items: center; gap: .5rem; }
.brand-link { text-decoration: none; }
.brand-name { font-family: var(--font-display); font-size: 1.4rem; color: #fff; letter-spacing: .5px; }
.hamburger { 
    display: none; 
    background: none; 
    border: none; 
    color: #fff; 
    font-size: 1.5rem; 
    cursor: pointer;
    padding: .25rem;
}
.top-bar__actions { display: flex; align-items: center; gap: .75rem; }

.unread-badge {
    background: var(--color-accent);
    color: #000;
    font-size: .7rem;
    font-weight: 700;
    border-radius: 99px;
    padding: 2px 7px;
    min-width: 20px;
    text-align: center;
}

/* --- Layout --- */
.layout { display: flex; min-height: calc(100vh - 56px); }

/* --- Sidebar (manager/access) --- */
.sidebar {
    width: 220px;
    background: var(--color-primary);
    color: #fff;
    flex-shrink: 0;
    padding: 1.5rem 0;
    display: none;
}
.sidebar__nav { 
    list-style: none; 
    display: flex;
    flex-direction: column;
    height: 100%;
}
.sidebar__nav li a {
    display: block;
    padding: .75rem 1.5rem;
    color: rgba(255,255,255,.85);
    font-size: .95rem;
    transition: background var(--transition);
    border-left: 3px solid transparent;
    text-decoration: none;
}
.sidebar__nav li a:hover,
.sidebar__nav li a.active {
    background: rgba(255,255,255,.1);
    border-left-color: var(--color-accent);
    color: #fff;
    text-decoration: none;
}

/* --- Main content --- */
.main-content {
    flex: 1;
    padding: 1.25rem 1rem 5rem;
    max-width: 100%;
    overflow-x: hidden;
}

/* --- Bottom nav (student, mobile) --- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-h);
    background: var(--color-primary);
    display: flex;
    z-index: 100;
    box-shadow: 0 -2px 8px rgba(0,0,0,.15);
}
.bottom-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,.75);
    font-size: .65rem;
    gap: 2px;
    transition: background var(--transition);
    text-decoration: none;
}
.bottom-nav__item:hover, 
.bottom-nav__item.active {
    background: rgba(255,255,255,.1);
    color: #fff;
    text-decoration: none;
}
.nav-icon { font-size: 1.3rem; line-height: 1; }

/* --- Cards --- */
.card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}
.card__title {
    font-family: var(--font-display);
    font-size: 1.25rem;
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--color-primary-deep);
}
.card__link { font-size: .8rem; font-weight: 400; }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .5rem 1rem;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    font-size: .9rem;
    font-weight: 500;
    line-height: 1.4;
    transition: opacity var(--transition), transform var(--transition);
    text-decoration: none;
    white-space: nowrap;
    font-family: var(--font-body);
}
.btn:hover { opacity: .88; text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn--primary  { background: var(--color-primary-lt); color: #fff; }
.btn--secondary{ background: var(--color-accent); color: #000; }
.btn--success  { background: var(--color-success); color: #fff; }
.btn--danger   { background: var(--color-danger); color: #fff; }
.btn--ghost    { background: transparent; color: var(--color-primary-lt); border: 1px solid var(--color-border); }
.btn--sm       { padding: .3rem .7rem; font-size: .8rem; }
.btn--large    { padding: .75rem 1.5rem; font-size: 1rem; }
.btn--full     { width: 100%; }

/* --- Forms --- */
.form-card { display: flex; flex-direction: column; gap: 1rem; }
.form-group { display: flex; flex-direction: column; gap: .3rem; }
.form-group label { font-size: .875rem; font-weight: 500; color: var(--color-text); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-inline { display: flex; flex-direction: column; gap: .75rem; }

input[type="text"], input[type="email"], input[type="tel"], input[type="password"],
input[type="date"], input[type="time"], input[type="number"],
select, textarea {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: .95rem;
    font-family: inherit;
    color: var(--color-text);
    background: var(--color-surface);
    transition: border-color var(--transition), box-shadow var(--transition);
    appearance: auto;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary-lt);
    box-shadow: 0 0 0 3px rgba(37,99,168,.15);
}
input.input--large { font-size: 1.25rem; padding: .75rem 1rem; }
.form-hint { font-size: .8rem; color: var(--color-muted); }
.form-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: .5rem; }
.form-status { font-size: .875rem; }
.form-status--success { color: var(--color-success); }
.form-status--error   { color: var(--color-danger); }

fieldset { border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1rem; }
legend   { padding: 0 .5rem; font-weight: 600; font-size: .9rem; color: var(--color-primary); }

/* --- Alerts --- */
.alert {
    padding: .875rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: .9rem;
}
.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.alert-error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* --- Tables --- */
.table-wrap { overflow-x: auto; }
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}
.table th, .table td {
    padding: .65rem .75rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}
.table th { font-weight: 600; background: var(--color-bg); white-space: nowrap; }
.table tbody tr:hover { background: #f8fafc; }
.table--live tbody tr:nth-child(odd) { background: #fffbeb; }
.row--inactive { opacity: .55; }
.actions { white-space: nowrap; }
.actions .btn { margin-right: .25rem; }

/* --- Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: .2rem .55rem;
    border-radius: 99px;
    font-size: .75rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}
.badge--success { background: #dcfce7; color: #15803d; }
.badge--warning { background: #fff7ed; color: #c2410c; }
.badge--info    { background: #e0f2fe; color: #0369a1; }
.badge--neutral { background: #f1f5f9; color: #475569; }
.badge--danger  { background: #fee2e2; color: #dc2626; }

/* --- Stats grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.stat-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: .25rem;
    border-top: 3px solid var(--color-primary-lt);
}
.stat-card--warning { border-left: none; border-top-color: var(--color-accent); }
.stat-card--info    { border-left: none; border-top-color: var(--color-info); }
.stat-icon  { font-size: 1.75rem; line-height: 1; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--color-primary); line-height: 1.1; }
.stat-label { font-size: .75rem; color: var(--color-muted); }

/* --- Detail list --- */
.detail-list { display: grid; grid-template-columns: auto 1fr; gap: .35rem .75rem; font-size: .9rem; }
.detail-list dt { font-weight: 600; color: var(--color-muted); }
.detail-list dd { color: var(--color-text); }

/* --- Dashboard --- */
.welcome-banner {
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-lt));
    color: #fff;
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
}
.welcome-banner h2 { font-size: 1.25rem; margin-bottom: .25rem; }
.room-info { font-size: .875rem; opacity: .85; }

/* --- Login page --- */
.login-page { 
    min-height: 100vh; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    background: linear-gradient(140deg, var(--color-primary-deep) 0%, var(--color-primary) 50%, var(--color-primary-lt) 100%);
    padding: 1rem; 
}
.login-container { width: 100%; max-width: 400px; }
.login-card {
    background: var(--color-surface);
    border-radius: 20px;
    padding: 2rem 1.5rem;
    box-shadow: var(--shadow-lg);
}
.login-logo { width: 64px; height: 64px; margin: 0 auto 1rem; }
.login-title { 
    text-align: center; 
    font-family: var(--font-display);
    font-size: 2rem; 
    color: var(--color-primary); 
}
.login-subtitle { text-align: center; color: var(--color-muted); font-size: .9rem; margin-bottom: 1.5rem; }
.login-form { display: flex; flex-direction: column; gap: 1rem; margin-bottom: 1rem; }
.login-footer { text-align: center; font-size: .8rem; color: var(--color-muted); }

/* --- Modal --- */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal[hidden] { display: none; }
.modal__overlay { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.modal__box {
    position: relative;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    max-width: 640px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
    padding: 1.5rem;
}
.modal__header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.modal__header h3 { font-size: 1.1rem; font-weight: 600; }
.modal__close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--color-muted); line-height: 1; }

/* --- Pagination --- */
.pagination { display: flex; gap: .5rem; justify-content: center; margin-top: 1.5rem; flex-wrap: wrap; }
.pagination__item {
    padding: .4rem .75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: .875rem;
    color: var(--color-primary-lt);
}
.pagination__item--active { background: var(--color-primary-lt); color: #fff; border-color: transparent; }

/* --- Messages --- */
.message-list { display: flex; flex-direction: column; gap: .75rem; max-height: 400px; overflow-y: auto; padding-right: .5rem; }
.message-bubble { padding: .75rem 1rem; border-radius: var(--radius); max-width: 85%; }
.message-bubble--received { background: var(--color-bg); align-self: flex-start; border-bottom-left-radius: 0; }
.message-bubble--sent     { background: var(--color-primary); color: #fff; align-self: flex-end; border-bottom-right-radius: 0; }
.message-meta { font-size: .75rem; opacity: .7; display: flex; justify-content: space-between; margin-bottom: .25rem; }
.message-bubble p { font-size: .9rem; }

/* --- Issue list --- */
.issue-list { display: flex; flex-direction: column; gap: 1rem; }
.issue-item { border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1rem; }
.issue-item__header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.issue-photo { max-height: 200px; border-radius: var(--radius); margin-top: .5rem; }
.issue-item--resolved { opacity: .65; }

/* --- Checkout --- */
.checkout-card { max-width: 480px; margin: 0 auto; }
.live-count-bar { text-align: center; padding: 1rem; background: var(--color-surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-top: 1rem; display: flex; justify-content: center; align-items: center; gap: 1rem; }
.checkout-success { margin-bottom: 1.5rem; }

/* --- Empty states --- */
.empty-state { color: var(--color-muted); font-size: .9rem; padding: 1rem 0; }
.empty-state-large { text-align: center; padding: 3rem 1rem; color: var(--color-muted); }
.empty-icon { font-size: 3rem; display: block; margin-bottom: .75rem; }

/* --- Filter bar --- */
.filter-bar { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; background: var(--color-surface); padding: 1rem; border-radius: var(--radius); box-shadow: var(--shadow); }
.filter-bar .form-group { flex: 1; min-width: 140px; }

/* --- Search bar --- */
.search-bar { display: flex; gap: .5rem; margin-bottom: 1rem; }
.search-bar input { flex: 1; }

/* --- Quick actions --- */
.quick-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1.25rem; }

/* --- Page header --- */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; flex-wrap: wrap; gap: .5rem; }
.page-header h2 { font-size: 1.25rem; font-weight: 700; }
.page-meta { font-size: .8rem; color: var(--color-muted); margin-bottom: .75rem; }
.page-desc { color: var(--color-muted); margin-bottom: 1.25rem; }

/* --- Live visitors --- */
.live-controls { display: flex; align-items: center; gap: .75rem; }
.live-badge { background: var(--color-success); color: #fff; padding: .25rem .75rem; border-radius: 99px; font-size: .8rem; font-weight: 600; }
.auto-refresh-note { font-size: .75rem; color: var(--color-muted); margin-top: .75rem; }

/* --- App footer --- */
.app-footer { text-align: center; padding: 1.5rem; font-size: .8rem; color: var(--color-muted); background: var(--color-surface); border-top: 1px solid var(--color-border); }

/* --- File upload --- */
.file-upload {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
}
.file-upload:hover {
    border-color: var(--color-primary-lt);
    background: var(--color-sky);
}
.file-upload input { display: none; }
.file-upload-icon { font-size: 2rem; margin-bottom: .5rem; }
.file-upload-text { font-size: .875rem; color: var(--color-muted); }

/* --- Chart placeholder --- */
.chart-area {
    background: linear-gradient(to top, var(--color-sky), transparent);
    border-radius: var(--radius);
    height: 120px;
    display: flex;
    align-items: flex-end;
    padding: .5rem;
    gap: .25rem;
    margin: 1rem 0;
}
.chart-bar {
    flex: 1;
    background: var(--color-primary-lt);
    border-radius: 4px 4px 0 0;
    min-height: 10px;
}
.chart-labels {
    display: flex;
    justify-content: space-between;
    font-size: .7rem;
    color: var(--color-muted);
    padding: 0 .5rem;
}

/* ===== RESPONSIVE BREAKPOINTS ===== */

/* Tablet + Desktop: show sidebar, hide hamburger/bottom-nav */
@media (min-width: 769px) {
    .bottom-nav  { display: none; }
    .hamburger   { display: none; }
    .main-content { padding: 1.5rem; }
}

@media (min-width: 1024px) {
    .sidebar { display: block; }
    .main-content { padding: 2rem; }
    .stats-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

/* Mobile: student portal adjustments */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .hamburger { display: block; }
    .form-row { grid-template-columns: 1fr; }
    .modal__box { padding: 1rem; }
    .filter-bar--wide { flex-direction: column; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .role-student .top-bar__actions .btn--ghost:not(.logout-btn) { display: none; }
    
    /* Student-only: enforce mobile max width */
    .role-student .main-content { 
        max-width: 480px; 
        margin: 0 auto; 
    }
    
    /* Mobile logout button styling - show for all roles */
    .logout-btn {
        display: inline-flex !important;
        padding: 0.4rem 0.6rem;
        font-size: 0.75rem;
        background: rgba(255,255,255,0.15);
        border: 1px solid rgba(255,255,255,0.3);
        border-radius: 8px;
        min-width: auto;
    }
    
    .logout-btn::before {
        content: '🚪';
        margin-right: 0.25rem;
    }
    
    /* Hide text on very small screens */
    @media (max-width: 360px) {
        .logout-btn {
            font-size: 0;
            padding: 0.5rem;
        }
        .logout-btn::before {
            margin-right: 0;
            font-size: 1rem;
        }
    }
}

/* Mobile: sidebar as overlay when open */
@media (max-width: 1023px) {
    .sidebar.open {
        display: block;
        position: fixed;
        top: 56px;
        left: 0;
        bottom: 0;
        z-index: 150;
        width: 240px;
        overflow-y: auto;
    }
}

/* ===== MANAGER & ACCESS BRANDING ===== */
.role-manager .top-bar,
.role-access .top-bar {
    background: var(--brand-primary, #1a3c5e);
}

.role-manager .sidebar,
.role-access .sidebar {
    background: var(--brand-primary, #1a3c5e);
}

.role-manager .sidebar__nav li a.active,
.role-access .sidebar__nav li a.active {
    border-left-color: var(--brand-accent, #f59e0b);
    background: rgba(255,255,255,0.15);
}

.role-manager .brand-logo-img,
.role-access .brand-logo-img {
    max-height: 32px;
    width: auto;
    filter: brightness(0) invert(1);
}

.role-manager .brand-name,
.role-access .brand-name {
    color: #fff;
    font-size: 1.3rem;
    font-weight: 700;
}

/* ===== UTILITY CLASSES ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.hidden { display: none; }
