/* ===========================================================
   HKU PyAlgoSci — Shared Theme
   Colour palette modelled on HKU Moodle (https://moodle.hku.hk/)
   =========================================================== */

:root {
    /* HKU brand palette */
    --hku-green:       #006b3f;   /* HKU Green — primary */
    --hku-green-dark:  #004d2c;   /* darker — header background */
    --hku-green-light: #00874a;   /* hover / accent */
    --hku-gold:        #cba052;   /* subtle accent */
    --hku-cream:       #f5f5f0;   /* off-white background */

    /* 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: -apple-system, BlinkMacSystemFont, "Segoe UI",
                 "PingFang HK", "Microsoft YaHei", "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; }

/* ----------- Page wrapper ----------- */
.app-container {
    max-width: 1500px;
    margin: 0 auto;
    background: var(--bg);
    box-shadow: var(--shadow);
    min-height: 100vh;
}

/* ----------- Header (HKU green, mirrors moodle.hku.hk) ----------- */
.app-header {
    background: var(--hku-green-dark);
    color: #fff;
    padding: 14px 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    border-bottom: 4px solid var(--hku-green);
}

.app-header__brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.app-header__logos {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-header__logo {
    border-radius: 6px;
    background: rgba(255,255,255,0.95);
    padding: 4px;
    box-shadow: var(--shadow-sm);
    image-rendering: -webkit-optimize-contrast;
}

/* HKU 校徽: 方形 (实际像素约 1:1)
   ECE 系徽: 横幅 (实际像素约 3.5:1) — 用 width:auto 保持比例 */
.app-header__logo--hku {
    height: 48px;
    width: 48px;
}
.app-header__logo--ece {
    height: 40px;          /* 略矮一点，跟 HKU 视觉重量匹配 */
    width: auto;            /* 保持原图 3.5:1 横幅比例 */
    max-width: 160px;
}

.app-header__divider {
    width: 1px;
    height: 36px;
    background: rgba(255,255,255,0.25);
    margin: 0 4px;
}

.app-header__title {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    min-width: 0;
}

.app-header__title-main {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: 0.2px;
    color: #fff;
    white-space: nowrap;
}

.app-header__title-main .accent {
    color: var(--hku-gold);
}

.app-header__title-sub {
    font-size: 0.78rem;
    opacity: 0.8;
    color: #d6e7dd;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-header__actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.app-header__user {
    color: #d6e7dd;
    font-size: 0.9rem;
}
.app-header__user strong { color: #fff; font-weight: 600; }

.app-header__btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    background: rgba(255,255,255,0.12);
    color: #fff;
    transition: background 0.2s;
}
.app-header__btn:hover { background: rgba(255,255,255,0.22); }

.app-header__btn--danger { background: #c53030; }
.app-header__btn--danger:hover { background: #9b2525; }

/* ----------- Buttons ----------- */
.btn {
    padding: 9px 18px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.92rem;
    font-weight: 600;
    transition: all 0.2s;
    font-family: inherit;
}
.btn--primary {
    background: var(--primary);
    color: #fff;
}
.btn--primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}
.btn--primary:disabled {
    background: #a0aec0;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}
.btn--secondary {
    background: #fff;
    color: var(--primary);
    border-color: var(--primary);
}
.btn--secondary:hover {
    background: var(--bg-soft);
}
.btn--ghost {
    background: transparent;
    color: var(--text-soft);
}
.btn--ghost:hover { background: var(--bg-soft); }

/* ----------- Cards ----------- */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    border: 1px solid var(--border-soft);
}

.card--accent {
    border-left: 4px solid var(--primary);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ----------- Inputs ----------- */
.input, .select, textarea.input {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    background: var(--bg-card);
    transition: border-color 0.2s, box-shadow 0.2s;
}
.input:focus, .select:focus, textarea.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 107, 63, 0.12);
}

label.field-label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: var(--text-soft);
    font-size: 0.88rem;
}

/* ----------- Messages ----------- */
.msg {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 14px;
    font-size: 0.9rem;
    font-weight: 500;
    display: none;
    border-left: 4px solid;
}
.msg--error   { background: #fff5f5; color: var(--error);   border-color: var(--error); }
.msg--success { background: #f0fff4; color: var(--success); border-color: var(--success); }
.msg--info    { background: #ebf8ff; color: var(--info);    border-color: var(--info); }

/* ----------- Footer ----------- */
.app-footer {
    text-align: center;
    padding: 18px;
    background: var(--bg-soft);
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
}

/* ----------- Loading spinner ----------- */
.spinner {
    width: 44px; height: 44px;
    border: 4px solid var(--border-soft);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
    margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------- Responsive ----------- */
@media (max-width: 768px) {
    .app-header { padding: 12px 16px; flex-wrap: wrap; }
    .app-header__logo { height: 40px; width: 40px; }
    .app-header__title-main { font-size: 1.15rem; }
    .app-header__title-sub { font-size: 0.7rem; }
}

/* ----------- katex overrides ----------- */
.katex { font-size: 1em; }
.formula-box .katex-display { margin: 0.6em 0; }