/* ===========================================================
   HKU Co-Learning KBot — Shared Theme
   Colour palette modelled on HKU Moodle (https://moodle.hku.hk/)
   =========================================================== */

:root {
    /* HKU brand palette */
    --hku-green:       #006b3f;
    --hku-green-dark:  #004d2c;
    --hku-green-light: #00874a;
    --hku-gold:        #cba052;
    --hku-cream:       #f5f5f0;

    /* Neutrals */
    --bg:          #ffffff;
    --bg-soft:     #f8faf9;
    --bg-card:     #ffffff;
    --border:      #e2e8e0;
    --border-soft: #edf0eb;

    /* Text */
    --text:        #1a1a1a;
    --text-soft:   #4a5568;
    --text-muted:  #6b7280;

    /* States */
    --primary:        var(--hku-green);
    --primary-hover:  var(--hku-green-light);
    --primary-active: var(--hku-green-dark);
    --success:        #00874a;
    --error:          #c53030;
    --warning:        #d97706;
    --info:           #0369a1;

    /* Shadow */
    --shadow-sm:  0 1px 3px rgba(0,0,0,0.06);
    --shadow:     0 4px 12px rgba(0, 77, 44, 0.08);
    --shadow-lg:  0 8px 30px rgba(0, 77, 44, 0.12);

    /* Radius */
    --radius:     8px;
    --radius-lg:  12px;
}

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

html, body {
    font-family: "Segoe UI", "PingFang HK", "Microsoft YaHei",
                 -apple-system, BlinkMacSystemFont, "Helvetica Neue",
                 Arial, sans-serif;
    color: var(--text);
    background: var(--bg-soft);
    line-height: 1.55;
    font-size: 15px;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

h1, h2, h3, h4 { color: var(--text); font-weight: 600; line-height: 1.3; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

button, input { font: inherit; }
button { cursor: pointer; }

.hidden { display: none !important; }

/* ============================================================
   LOGIN PAGE — HKU Portal–style centred card on grey background
   ============================================================ */

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    background: #ebeef0;
}

.auth-card {
    background: #fff;
    width: 100%;
    max-width: 500px;
    border-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.10);
    padding: 32px 40px 28px;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ===== Brand header — logos left, site name right (same row) ===== */
.brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.brand__logos {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.brand__crest {
    image-rendering: -webkit-optimize-contrast;
    flex-shrink: 0;
}
.brand__crest--hku {
    height: 52px;
    width: auto;
}
.brand__crest--ece {
    height: 38px;
    width: auto;
    max-width: 140px;
}

.brand__name {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--hku-green-dark);
    text-align: right;
    line-height: 1.25;
    margin: 0;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 58%;
}

/* ===== Divider ===== */
.hr {
    border: none;
    border-top: 1px solid #e0e0e0;
    margin: 20px 0;
}

/* ===== Tab switcher (Login / Register) ===== */
.tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 18px;
}

.tab {
    border: 1px solid #c5c8cc;
    border-radius: 3px;
    background: white;
    color: var(--text-soft);
    min-height: 38px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.15s;
    font-family: inherit;
}

.tab.active {
    color: white;
    background: #00874a;
    border-color: #00874a;
}
.tab.active:hover { background: #007a42; }

/* ===== Material-style outlined input ===== */
.m-field {
    position: relative;
    margin-bottom: 18px;
}

.m-field input {
    width: 100%;
    padding: 14px 12px 8px 12px;
    border: 1px solid #c5c8cc;
    border-radius: 3px;
    background: #fff;
    font-size: 0.95rem;
    color: #1a1a1a;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}
.m-field input:focus {
    outline: none;
    border-color: var(--hku-green);
    border-width: 2px;
    padding: 13px 11px 7px 11px;
    box-shadow: 0 0 0 1px var(--hku-green);
}

.m-field label {
    position: absolute;
    left: 13px;
    top: 14px;
    font-size: 0.95rem;
    color: #6a737d;
    pointer-events: none;
    transition: all 0.15s;
    background: transparent;
    /* Prevent label overflow */
    max-width: calc(100% - 26px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.m-field input:focus + label,
.m-field input:not(:placeholder-shown) + label {
    top: 4px;
    font-size: 0.72rem;
    color: var(--hku-green);
    font-weight: 600;
}

/* ===== Submit button ===== */
.btn-login {
    display: block;
    width: 100%;
    padding: 11px 18px;
    background: #00874a;
    color: #fff;
    border: none;
    border-radius: 3px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    margin-top: 4px;
    transition: background 0.15s;
    font-family: inherit;
}
.btn-login:hover { background: #007a42; }
.btn-login:active { background: #006b3f; }
.btn-login:disabled { background: #a0aec0; cursor: not-allowed; }

/* ===== Bottom links ===== */
.link-line {
    text-align: center;
    margin-top: 14px;
}
.link-line a {
    color: #00874a;
    text-decoration: none;
    font-size: 0.88rem;
}
.link-line a:hover { text-decoration: underline; }

.demo-hint {
    text-align: center;
    font-size: 0.78rem;
    color: #8a8f95;
    margin-top: 10px;
    line-height: 1.5;
}
.demo-hint a {
    color: #00874a;
    text-decoration: none;
}
.demo-hint a:hover { text-decoration: underline; }

/* ===== Messages ===== */
.msg {
    padding: 10px 14px;
    border-radius: 3px;
    margin-bottom: 14px;
    font-size: 0.85rem;
    font-weight: 500;
    display: none;
    border-left: 3px solid;
    word-break: break-word;
}
.msg--error   { background: #fff5f5; color: #c53030; border-color: #c53030; }
.msg--success { background: #f0fff4; color: #276749; border-color: #00874a; }

/* ===== Footer note ===== */
.legal-line {
    text-align: center;
    margin-top: 6px;
}
.legal-line a {
    color: #00874a;
    text-decoration: none;
    font-size: 0.82rem;
}
.legal-line a:hover { text-decoration: underline; }

/* ============================================================
   DASHBOARD — Post-login home view
   ============================================================ */

.home-shell {
    min-height: 100vh;
    background: #f6f8fc;
}

/* ----------- Topbar (HKU green header) ----------- */
.topbar {
    background: var(--hku-green-dark);
    color: #fff;
    padding: 10px 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    border-bottom: 4px solid var(--hku-green);
    flex-wrap: wrap;
}

.brand-line {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.user-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.topbar__logo {
    border-radius: 6px;
    background: rgba(255,255,255,0.95);
    padding: 3px;
    box-shadow: var(--shadow-sm);
    image-rendering: -webkit-optimize-contrast;
    flex-shrink: 0;
}
.topbar__logo--hku {
    height: 40px;
    width: 40px;
}
.topbar__logo--ece {
    height: 32px;
    width: auto;
    max-width: 120px;
}

.topbar__divider {
    width: 1px;
    height: 30px;
    background: rgba(255,255,255,0.25);
    margin: 0 2px;
    flex-shrink: 0;
}

.topbar__sitename {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--hku-gold);
    letter-spacing: 0.2px;
    line-height: 1.25;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 280px;
}

#welcome-text {
    color: #d6e7dd;
    font-size: 0.88rem;
    white-space: nowrap;
}

#logout-button {
    padding: 7px 14px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    background: #c53030;
    color: #fff;
    transition: background 0.2s;
    font-family: inherit;
    white-space: nowrap;
}
#logout-button:hover { background: #9b2525; }

/* ----------- Dashboard content ----------- */
.dashboard {
    max-width: 1120px;
    margin: 0 auto;
    padding: 42px 20px;
}

.dashboard-heading h1 {
    margin: 0 0 8px;
    font-size: clamp(28px, 4vw, 44px);
    line-height: 1.15;
}

.dashboard-heading p {
    color: var(--text-muted);
    line-height: 1.7;
    margin-bottom: 8px;
}

/* ----------- App card grid ----------- */
.app-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    margin-top: 28px;
}

.app-card {
    display: grid;
    gap: 10px;
    min-height: 210px;
    padding: 22px;
    border-radius: var(--radius-lg);
    background: white;
    color: inherit;
    text-decoration: none;
    border: 1px solid var(--border-soft);
    box-shadow: var(--shadow);
    transition: transform 160ms ease, box-shadow 160ms ease;
}

.app-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.app-card.muted { opacity: 0.72; }

.app-icon {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: var(--hku-green);
    color: white;
    font-weight: 800;
    font-size: 18px;
}

.app-card small {
    color: var(--hku-green);
    font-weight: 800;
}

.app-card h2 {
    margin: 0;
    font-size: 22px;
    word-break: break-word;
}

.app-card p {
    margin: 0;
    color: var(--text-muted);
    line-height: 1.7;
    word-break: break-word;
}

.app-card strong {
    align-self: end;
    color: var(--hku-green);
}

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

@media (max-width: 820px) {
    .app-grid {
        grid-template-columns: 1fr;
    }

    .topbar {
        flex-direction: column;
        align-items: flex-start;
        padding: 14px 16px;
        gap: 10px;
    }

    .topbar__sitename {
        max-width: 100%;
    }
}

@media (max-width: 520px) {
    .auth-card {
        padding: 24px 20px 22px;
    }

    .brand {
        gap: 10px;
    }

    .brand__crest--hku { height: 40px; }
    .brand__crest--ece { height: 30px; max-width: 100px; }
    .brand__name { font-size: 1.05rem; max-width: 55%; }
}

/* ============================================================
   MODAL
   ============================================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease-out;
}

.modal-card {
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 28px 32px 22px;
    max-width: 440px;
    width: 90%;
}

.modal-card h2 {
    margin-bottom: 16px;
    color: var(--hku-green-dark);
}

.modal-body {
    font-size: 0.95rem;
    line-height: 1.8;
    color: var(--text-soft);
    margin-bottom: 18px;
}

.modal-body p {
    margin-bottom: 6px;
}

.modal-actions {
    text-align: right;
}

.modal-actions .btn-login {
    display: inline-block;
    width: auto;
    padding: 8px 24px;
}
