body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.card {
    border: 0;
}

.navbar-brand {
    letter-spacing: 0.3px;
}

a {
    color: var(--bs-primary);
}

/* Super User role — blue text/badge */
.super-user-text {
    color: #0d6efd;
    font-weight: 600;
}

/* Super Organisation username — purple to match the organisation badge. */
.super-org-text {
    color: #7c3aed;
    font-weight: 600;
}

.super-user-badge {
    background: linear-gradient(135deg, #4f86f7 0%, #0d6efd 100%);
    color: #fff;
    font-weight: 600;
    border: 1px solid #0a58ca;
}

/* Official (staff-published) — gold text/badge */
.official-text {
    color: #c9a227;
    font-weight: 600;
}

.official-badge {
    background: linear-gradient(135deg, #f6d365 0%, #d4af37 100%);
    color: #fff;
    font-weight: 600;
    border: 1px solid #b8912b;
}

/* On the dark navbar the verified/official name must stay white — the blue
   / purple / gold accent colours are designed for light backgrounds. */
.navbar .super-user-text,
.navbar .super-org-text,
.navbar .publisher-text,
.navbar .official-text {
    color: #fff !important;
}

/* Navbar username: keep on one line, shrink gracefully when long. */
.navbar-username {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
    display: inline-block;
    vertical-align: middle;
    font-size: 0.85rem;
}
@media (max-width: 991px) {
    .navbar-username {
        max-width: 140px;
        font-size: 0.78rem;
    }
}

/* Organisation-role accounts — violet badge */
.organization-badge {
    background: linear-gradient(135deg, #a78bfa 0%, #7c3aed 100%);
    color: #fff;
    font-weight: 600;
    border: 1px solid #6d28d9;
}

/* Publisher role — green badge */
.publisher-badge {
    background: linear-gradient(135deg, #34d399 0%, #059669 100%);
    color: #fff !important;
    font-weight: 600;
    border: 1px solid #047857;
}
.publisher-text {
    color: #059669;
    font-weight: 600;
}

/* LinkedIn icon shown next to a user's name (only when a LinkedIn URL is set) */
.linkedin-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid #d7dce5;
    color: #0a66c2;
    line-height: 1;
    text-decoration: none;
    transition: background 0.15s ease, transform 0.15s ease;
}

.linkedin-icon:hover {
    background: #0a66c2;
    color: #fff;
    border-color: #0a66c2;
    transform: scale(1.08);
    text-decoration: none;
}

/* Admin-set embed slot (e.g. Google Ads / AdSense snippet).
   An empty placeholder ad unit would otherwise render as a bare white box,
   so the slot gets a label and a minimum height. */
.embed-slot {
    position: relative;
    background: #fafafa;
    border: 1px dashed #d7dce5;
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
    min-height: 70px;
}

.embed-slot::before {
    content: "Advertisement";
    display: block;
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #9aa3af;
    margin-bottom: 8px;
    text-align: center;
}

.embed-slot ins {
    display: block;
    margin: 0 auto;
}

/* Smaller navbar links when the UI language is English only. */
html:lang(en) .navbar .nav-link {
    font-size: 0.85rem;
}

/* Publisher row: avatar + username + LinkedIn icon aligned on one baseline */.user-display {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    vertical-align: middle;
}
/* Extra breathing room around badges (avatar → badge → username). */
.user-display .badge,
.navbar .nav-link .badge {
    margin-right: 6px;
    margin-left: 6px;
}
.user-display .default-avatar {
    flex: 0 0 auto;
}
.user-display .linkedin-icon {
    flex: 0 0 auto;
}

/* Show / hide password toggle */
.password-field-wrap {
    position: relative;
    display: block;
}
.password-field-wrap input[type="password"],
.password-field-wrap input[type="text"] {
    padding-right: 2.6rem;
}
.password-toggle-btn {
    position: absolute;
    top: 50%;
    right: 0.5rem;
    transform: translateY(-50%);
    border: none;
    background: transparent;
    color: #6c757d;
    padding: 0.25rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
}
.password-toggle-btn:hover {
    color: #212529;
    background: rgba(0, 0, 0, 0.06);
}

/* ===== Advertisement styling — gold ===== */
.ad-badge {
    background-color: #b8912b;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.22rem 0.5rem;
    border-radius: 0.375rem;
    letter-spacing: 0.05em;
    white-space: nowrap;
}
.ad-title { color: #b8912b; }
.ad-muted { color: #8a6d1d; }
.ad-section-title { color: #b8912b; }
.ad-card { border-left-color: #b8912b !important; overflow: hidden; transition: max-height 0.45s ease, opacity 0.35s ease, margin 0.35s ease; }
.ad-border { border-left-color: #b8912b !important; }
.ad-link-btn, .ad-hide-btn, .ad-show-btn {
    border: 1px solid #b8912b;
    color: #b8912b;
    background: transparent;
    font-size: 0.78rem;
}
.ad-link-btn:hover, .ad-hide-btn:hover, .ad-show-btn:hover {
    background: #b8912b;
    color: #fff;
}
.ad-show-bar { text-align: left; }

/* ===== Dark mode =====
   Bootstrap 5.3's .bg-light / .bg-white utilities ship with !important and
   keep their light palette in dark mode, so plain overrides lose. These
   rules must also use !important (or higher specificity + !important) to win.
   Palette: bg #212529, surface #262d3a, inputs #1e242e, borders #3a4356,
   primary text #e9ecef, muted #aab4c2 (>= 7:1 on #212529). */
html[data-bs-theme="dark"] body,
html[data-bs-theme="dark"] body.bg-light {
    background-color: #212529 !important;
    color: #e9ecef;
}

html[data-bs-theme="dark"] .site-footer.bg-white,
html[data-bs-theme="dark"] .bg-white {
    background-color: #212529 !important;
    color: #adb5bd !important;
}
html[data-bs-theme="dark"] .site-footer .text-muted,
html[data-bs-theme="dark"] .text-muted {
    color: #aab4c2 !important;
}
html[data-bs-theme="dark"] .text-secondary {
    color: #aab4c2 !important;
}

html[data-bs-theme="dark"] .embed-slot {
    background: #1e242e;
    border-color: #3a4356;
}
html[data-bs-theme="dark"] .embed-slot::before {
    color: #aab4c2;
}

html[data-bs-theme="dark"] .password-toggle-btn {
    color: #aab4c2;
}
html[data-bs-theme="dark"] .password-toggle-btn:hover {
    color: #e9ecef;
    background: rgba(255, 255, 255, 0.08);
}

html[data-bs-theme="dark"] .linkedin-icon {
    background: #343a44;
    border-color: #3a4356;
}

/* Gold advertisement styling in dark mode — brightened for contrast. */
html[data-bs-theme="dark"] .ad-title { color: #e3bc5f; }
html[data-bs-theme="dark"] .ad-muted { color: #d4a93a; }
html[data-bs-theme="dark"] .ad-section-title { color: #e3bc5f; }
html[data-bs-theme="dark"] .ad-link-btn,
html[data-bs-theme="dark"] .ad-hide-btn,
html[data-bs-theme="dark"] .ad-show-btn {
    border-color: #e3bc5f;
    color: #e3bc5f;
}
html[data-bs-theme="dark"] .ad-link-btn:hover,
html[data-bs-theme="dark"] .ad-hide-btn:hover,
html[data-bs-theme="dark"] .ad-show-btn:hover {
    background: #e3bc5f;
    color: #212529;
}
html[data-bs-theme="dark"] .ad-card { border-left-color: #e3bc5f !important; }
html[data-bs-theme="dark"] .ad-border { border-left-color: #e3bc5f !important; }
/* Dark mode: the ad photo banner keeps a visible but dark frame instead of the
   bright gold border used in light mode. */
html[data-bs-theme="dark"] .ad-banner {
    border-color: #4a4636 !important;
    background: #2a2723 !important;
}
html[data-bs-theme="dark"] .ad-banner .ad-banner-link img {
    border-color: #4a4636 !important;
}

/* The whole site must switch — not just Bootstrap components. */
html[data-bs-theme="dark"] .card.bg-light {
    background-color: #262d3a !important;
    border-color: #3a4356;
}
html[data-bs-theme="dark"] .alert-light {
    background-color: #262d3a !important;
    color: #dbe4ef;
    border-color: #3a4356;
}
html[data-bs-theme="dark"] .alert-light a { color: #93c5fd; }
html[data-bs-theme="dark"] .badge.text-bg-light {
    background-color: #3a4356 !important;
    color: #e2e8f0 !important;
}
html[data-bs-theme="dark"] .table {
    --bs-table-bg: transparent;
    color: var(--bs-body-color);
}
html[data-bs-theme="dark"] .form-control,
html[data-bs-theme="dark"] .form-select {
    background-color: #1e242e !important;
    border-color: #3a4356 !important;
    color: #e9ecef !important;
}
html[data-bs-theme="dark"] .form-control:focus,
html[data-bs-theme="dark"] .form-select:focus {
    background-color: #1e242e !important;
    color: #e9ecef !important;
}
html[data-bs-theme="dark"] .form-control::placeholder {
    color: #8a94a6;
}

/* Custom table: Bootstrap draws row borders on <tr>, which border-collapse:separate
   (needed for rounded corners) ignores. Draw the row lines on the cells instead. */
.custom-post-table td {
    border: 2px solid var(--bs-border-color) !important;
}
.custom-post-table tr:last-child td {
    border-bottom: 2px solid var(--bs-border-color) !important;
}

/* Custom table editor: highlighted cell ready to merge/split. */
#ct-table td.ct-selected {
    outline: 2px solid #0d6efd;
    outline-offset: -2px;
}

/* Custom tables take 80% of the post width by default; long content can
   still stretch them wider because min-width is only a floor. */
.custom-post-table {
    width: 80%;
}

/* Give every custom-table cell a minimum width so empty cells still show the
   full grid instead of collapsing into a thin strip. */
.custom-post-table td {
    min-width: 120px;
    white-space: pre-wrap;
}

/* The in-post editor mirrors the same generous cell width. */
#ct-table {
    width: 80%;
}
#ct-table td {
    min-width: 120px;
}

/* Table-level alignment inside the post: centre or right the whole table. */
.custom-post-table.ct-tcenter {
    margin-left: auto;
    margin-right: auto;
}
.custom-post-table.ct-tright {
    margin-left: auto;
    margin-right: 0;
}

/* Google AdSense: collapse the empty ad slot to zero height when no ad is
   served (data-ad-status="unfilled"), so a blank white box never shows. */
ins.adsbygoogle[data-ad-status="unfilled"] {
    display: none !important;
}
ins.adsbygoogle[data-ad-status="unfilled"] ~ .adsbygoogle-placeholder {
    display: none !important;
}

/* Homepage featured-tutor grid: empty slots render a dashed placeholder card
   so the 8-per-row grid shape is visible even when few tutors exist. */
.tutor-slot-empty {
    border: 1px dashed #adb5bd !important;
    background: #f8f9fa !important;
    min-height: 180px;
}

/* Homepage featured grids (tutors & organisations): equal-height cards
   per row so every card has the same fixed size. */
.home-grid .col > .card {
    height: 100%;
    min-height: 180px;
}

/* Register page: full-page illustration background. */
body.register-bg {
    background-image: url('/static/img/register-bg.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Content area grows so the footer sticks to the bottom of the viewport
   and no background shows below the footer. */
body.register-bg main {
    flex-grow: 1;
}

/* The footer stays solid white — the illustration background must not
   show through the page footer. */
body.register-bg footer {
    background-color: #fff !important;
}


/* ---- Chat message gear (edit/delete) ---- */
.msgs-gear {
    color: var(--bs-secondary-color, #6c757d);
    background: transparent;
    border: none;
    padding: 0 6px;
    font-size: 1rem;
    line-height: 1;
    opacity: .55;
    transition: opacity .15s;
}
.msgs-gear:hover, .msgs-gear:focus {
    opacity: 1;
    background: transparent;
}
[data-bs-theme="dark"] .msgs-gear { color: #adb5bd; }

/* ---- Chat edited marker ---- */
.msg-edited {
    font-style: italic;
    opacity: .75;
}

/* ---- Chat voice recording ---- */
.rec-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #dc3545;
    animation: recPulse 1.2s ease-in-out infinite;
    flex: 0 0 auto;
}
@keyframes recPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .35; transform: scale(.8); }
}
.msg-audio { width: 220px; max-width: 100%; height: 36px; }

/* ---- Chat voice waveform ---- */
.msg-wave {
    width: 220px;
    max-width: 100%;
    height: 30px;
    margin-top: 4px;
}
.wave-svg {
    display: block;
    width: 100%;
    height: 100%;
}
/* ---- Voice message player (play + waveform + progress) ---- */
.voice-player {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 240px;
    max-width: 100%;
    margin-top: 4px;
    cursor: pointer;
}
.vp-play {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid currentColor;
    background: transparent;
    color: #0d6efd;
    border-color: rgba(13,110,253,.4);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .8rem;
    line-height: 1;
    padding: 0;
}
.voice-player .vp-play-own { color: #fff; border-color: rgba(255,255,255,.5); }
.vp-wave {
    position: relative;
    flex: 1 1 auto;
    height: 30px;
    overflow: hidden;
}
.vp-wave .wave-svg { position: absolute; inset: 0; }
.vp-prog {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    overflow: hidden;
    width: 0%;
}
.vp-prog .wave-svg { position: absolute; inset: 0; }
.vp-time {
    flex: 0 0 auto;
    font-size: .75rem;
    color: #6c757d;
    min-width: 34px;
}
.vp-time-own { color: rgba(255,255,255,.85); }

/* ---- Live recording preview ---- */
.rec-preview {
    margin-top: 6px;
    height: 30px;
    width: 100%;
    background: rgba(13,110,253,.06);
    border-radius: 6px;
    padding: 2px;
}
#recWave .wave-svg { height: 100%; width: 100%; }

/* Links inside chat bubbles: white so they stand out on the dark-green bubble */
.chat-bubble a {
    color: #ffffff;
    text-decoration: underline;
    font-weight: 600;
}
.chat-bubble a:hover { color: #bbf7d0; }

/* Gender selection square-box blocks (radio inside the box) */
.gender-boxes { display: flex; gap: .5rem; flex-wrap: nowrap; }
.gender-box {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    flex: 1 1 0; min-width: 0; padding: .45rem .5rem;
    border: 2px solid #dee2e6; border-radius: .375rem;
    font-size: .875rem; color: #495057; background: #fff;
    cursor: pointer; user-select: none;
    transition: border-color .15s ease, background .15s ease;
}
.gender-box input { margin: 0; cursor: pointer; accent-color: #0d6efd; }
.gender-box:hover:not(:has(input:disabled)) { border-color: #0d6efd; }
.gender-box:has(input:checked) {
    border-color: #0d6efd; background: #e7f1ff; font-weight: 600; color: #0d6efd;
}

/* Homepage post grids: masonry-style two columns so cards of different
   heights do not leave vertical gaps inside a row. */
#student-grid, #tutor-grid { columns: 1; column-gap: 1rem; }
#student-grid > .col, #tutor-grid > .col {
    break-inside: avoid;
    width: 100%;
    margin-bottom: 1rem;
}
@media (min-width: 768px) {
    #student-grid, #tutor-grid { columns: 2; }
}
.gender-box:has(input:disabled) { background: #e9ecef; color: #adb5bd; cursor: not-allowed; }
.gender-box:has(input:disabled) input { cursor: not-allowed; }
.gender-box:has(input:checked:disabled) { border-color: #adb5bd; background: #e9ecef; color: #adb5bd; font-weight: 400; }
/* 圖片防拖曳 / 防選取（右鍵與拖拽保護） */
img {
    -webkit-user-drag: none;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
}
