/* =========================================================
   Layout: topbar, drawer, main, footer — Nature Theme
   Mobile-first, stable across breakpoints
   ========================================================= */

/* ============== TOPBAR ============== */
.topbar {
    position: sticky; top: 0; z-index: 100;
    background: linear-gradient(180deg, #0F2A1D 0%, #163C28 100%);
    color: var(--ivory);
    border-bottom: 1px solid rgba(221,161,94,.45);
    box-shadow: 0 8px 24px rgba(15,42,29,.18);
}
.topbar-inner {
    width: min(100%, var(--container));
    margin: 0 auto;
    padding: 10px var(--content-pad);
    min-height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

/* Hamburger */
.menu-toggle {
    display: none;
    background: transparent; border: 0; padding: 8px;
    color: var(--ivory); cursor: pointer; border-radius: var(--r);
}
.menu-toggle:hover { background: rgba(221,161,94,.18); }
.menu-toggle i { width: 24px; height: 24px; }

/* Brand */
.brand {
    display: flex; align-items: center; gap: 10px;
    color: var(--ivory);
    flex: 0 1 auto;
    min-width: 0;
}
.brand:hover { color: var(--gold-soft); }
.brand-logo svg { display: block; filter: drop-shadow(0 4px 8px rgba(221,161,94,.35)); }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand-name {
    font-family: var(--font-serif); font-size: 1.25rem; font-weight: 800;
    color: var(--gold-soft); white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
    max-width: 220px;
}
.brand-tag {
    font-family: var(--font-body); font-style: italic; font-size: .75rem;
    color: rgba(251,252,244,.7); white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; max-width: 200px;
}

/* Top navigation */
.topnav {
    display: flex; gap: 2px; flex: 1 1 auto;
    justify-content: center;
    overflow: hidden;
    min-width: 0;
}
.topnav a {
    color: var(--ivory);
    padding: 8px 12px;
    border-radius: var(--r);
    font-family: var(--font-ui);
    font-weight: 500;
    font-size: .88rem;
    display: inline-flex; align-items: center; gap: 6px;
    white-space: nowrap;
    transition: background .15s, color .15s;
}
.topnav a i { width: 16px; height: 16px; }
.topnav a:hover { background: rgba(221,161,94,.15); color: var(--gold-soft); }

/* Right side */
.topbar-right {
    display: flex; align-items: center; gap: 6px; justify-content: flex-end;
    flex: 0 0 auto;
    margin-left: auto;
    flex-wrap: nowrap;
    min-width: 0;
}

.search-mini {
    display: flex; align-items: center; gap: 8px;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(221,161,94,.3);
    padding: 7px 14px; border-radius: 999px;
    width: 220px;
    transition: border-color .15s, background .15s;
}
.search-mini:focus-within { border-color: var(--gold); background: rgba(255,255,255,.13); }
.search-mini i { width: 16px; height: 16px; color: var(--gold-soft); flex-shrink: 0; }
.search-mini input {
    background: transparent; border: 0; outline: none;
    color: var(--ivory); font-family: var(--font-ui); font-size: .88rem;
    width: 100%;
}
.search-mini input::placeholder { color: rgba(251,252,244,.55); }

/* Search trigger button (mobile) */
.search-trigger { display: none; }

.icon-btn {
    position: relative;
    width: 40px; height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--ivory);
    border-radius: 50%;
    background: transparent; border: 0; cursor: pointer;
    transition: background .15s;
    flex-shrink: 0;
    text-decoration: none;
}
.icon-btn:hover { background: rgba(221,161,94,.18); color: var(--gold-soft); }
.icon-btn i { width: 20px; height: 20px; }
.icon-btn .dot {
    position: absolute; top: 2px; right: 2px;
    background: var(--burgundy); color: white;
    font-family: var(--font-ui); font-size: .65rem; font-weight: 700;
    min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 9px; display: inline-flex; align-items: center; justify-content: center;
    border: 2px solid var(--ink);
}

.profile-dd { position: relative; }
.profile-btn {
    display: flex; align-items: center; gap: 8px;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(221,161,94,.3);
    color: var(--ivory);
    padding: 4px 10px 4px 4px;
    border-radius: 999px;
    cursor: pointer;
    font-family: var(--font-ui); font-size: .88rem;
    transition: background .15s, border-color .15s;
    max-width: 200px;
}
.profile-btn:hover { background: rgba(221,161,94,.14); border-color: var(--gold); }
.profile-btn img {
    width: 30px; height: 30px; border-radius: 50%; object-fit: cover;
    border: 1px solid var(--gold-soft); flex-shrink: 0;
}
.profile-btn span {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 110px;
}
.profile-btn i { width: 14px; height: 14px; flex-shrink: 0; }

.profile-menu {
    position: absolute; right: 0; top: calc(100% + 8px);
    background: var(--surface); color: var(--ink);
    min-width: 240px;
    max-width: calc(100vw - 24px);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 8px;
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
}
.profile-menu a {
    padding: 10px 12px; border-radius: var(--r);
    display: flex; align-items: center; gap: 10px;
    font-family: var(--font-ui); font-size: .9rem; color: var(--text);
    text-decoration: none;
}
.profile-menu a:hover { background: var(--parchment); }
.profile-menu a.danger { color: var(--burgundy); }
.profile-menu a.danger:hover { background: rgba(168,66,28,.08); }
.profile-menu a i { width: 16px; height: 16px; }
.profile-menu .role-badge {
    align-self: flex-start;
    margin: 6px 8px;
}
.profile-menu hr { margin: 6px 4px; }
.profile-dd.open .profile-menu { display: flex; }

/* ============== MOBILE DRAWER ============== */
.drawer-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(15,42,29,.55);
    backdrop-filter: blur(2px);
    z-index: 199;
}
.drawer-backdrop.show { display: block; }

.drawer {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(88vw, 340px);
    background: linear-gradient(180deg, #0F2A1D 0%, #1B4332 100%);
    color: var(--ivory);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform .25s ease;
    display: flex; flex-direction: column;
    border-right: 2px solid var(--gold);
    box-shadow: 12px 0 40px rgba(0,0,0,.4);
}
.drawer.show { transform: translateX(0); }
.drawer-head {
    padding: 18px 20px;
    border-bottom: 1px solid rgba(221,161,94,.3);
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px;
    min-width: 0;
}
.drawer-head .brand-name { font-size: 1.2rem; }
.drawer-head .brand-tag { font-size: .72rem; }
.drawer-close {
    background: transparent; border: 0; color: var(--ivory); padding: 6px;
    border-radius: var(--r); cursor: pointer;
}
.drawer-close:hover { background: rgba(255,255,255,.08); }
.drawer-body { flex: 1; overflow-y: auto; padding: 12px 12px 24px; }
.drawer-body a {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px;
    color: var(--ivory);
    border-radius: var(--r);
    font-family: var(--font-ui);
    font-size: .95rem;
    margin-bottom: 2px;
    min-width: 0;
    text-decoration: none;
}
.drawer-body a:hover, .drawer-body a.active {
    background: rgba(221,161,94,.15); color: var(--gold-soft);
}
.drawer-body a i { width: 20px; height: 20px; flex-shrink: 0; }
.drawer-body hr { border-color: rgba(221,161,94,.2); margin: 12px 0; }
.drawer-body .group-title {
    padding: 10px 14px 6px;
    font-size: .72rem; letter-spacing: .15em; text-transform: uppercase;
    color: var(--gold-soft); opacity: .85;
}
.drawer-search {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(221,161,94,.2);
}
.drawer-search form {
    display: flex; align-items: center; gap: 8px;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(221,161,94,.3);
    padding: 8px 12px; border-radius: 999px;
}
.drawer-search input {
    background: transparent; border: 0; outline: none;
    color: var(--ivory); font-family: var(--font-ui); font-size: .9rem;
    width: 100%;
}
.drawer-search input::placeholder { color: rgba(251,252,244,.55); }
.drawer-search i { color: var(--gold-soft); width: 16px; height: 16px; }

/* ============== FLASH ============== */
.flash-wrap {
    width: min(100%, var(--container));
    margin: 16px auto 0;
    padding: 0 var(--content-pad);
    display: flex; flex-direction: column; gap: 8px;
}
.flash {
    padding: 12px 16px; border-radius: var(--r);
    font-family: var(--font-ui); font-size: .92rem;
    border-left: 4px solid var(--gold); background: var(--parchment);
    color: var(--ink);
}
.flash-success { border-left-color: var(--success); background: #E7F2EA; color: #1d4d3a; }
.flash-error   { border-left-color: var(--danger);  background: #FBEBE3; color: #6e2e15; }
.flash-info    { border-left-color: var(--ink-3);   background: #E5EFE6; color: var(--ink); }

/* ============== MAIN ============== */
.main {
    width: min(100%, var(--container));
    margin: 24px auto 48px;
    padding: 0 var(--content-pad);
    min-height: 60vh;
    min-width: 0;
}

/* Chat-page: no margin, no footer, fixed-height layout */
body.chat-page .main {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
    height: calc(100vh - var(--topbar-h));
    height: calc(100dvh - var(--topbar-h));
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
body.chat-page .footer { display: none; }
body.chat-page .flash-wrap { width: 100%; max-width: none; padding: 8px 12px; margin: 0; }

/* ============== FOOTER ============== */
.footer {
    background: linear-gradient(180deg, #0F2A1D 0%, #07190E 100%);
    color: var(--ivory);
    border-top: 1px solid rgba(221,161,94,.55);
    margin-top: 60px;
    position: relative;
}
.footer::before {
    content: '';
    position: absolute; left: 0; right: 0; top: 0;
    height: 8px;
    background: linear-gradient(90deg, var(--emerald), var(--gold), var(--burgundy), var(--emerald));
    opacity: .6;
}
.footer-inner {
    width: min(100%, var(--container)); margin: 0 auto;
    padding: 40px var(--content-pad) 24px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 32px;
}
.footer-about { max-width: 360px; }
.footer-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.footer-name  { font-family: var(--font-serif); font-size: 1.3rem; color: var(--gold-soft); line-height: 1.1; }
.footer-tag   { font-style: italic; color: rgba(251,252,244,.65); font-size: .85rem; }
.footer-desc {
    color: rgba(251,252,244,.72);
    font-size: .92rem; line-height: 1.65; margin: 0;
    font-family: var(--font-body);
}
.footer-col h4 {
    color: var(--gold-soft); font-family: var(--font-ui); font-size: .78rem;
    letter-spacing: .18em; text-transform: uppercase; margin-bottom: 14px;
    position: relative; padding-bottom: 8px;
}
.footer-col h4::after {
    content: ''; position: absolute; left: 0; bottom: 0;
    width: 28px; height: 2px; background: var(--gold);
}
.footer-col a {
    display: block; color: rgba(251,252,244,.78);
    padding: 5px 0; font-family: var(--font-ui); font-size: .92rem;
    transition: color .15s, padding-left .15s;
    text-decoration: none;
}
.footer-col a:hover { color: var(--gold-soft); padding-left: 4px; }
.footer-bottom {
    width: min(100%, var(--container)); margin: 0 auto;
    padding: 16px var(--content-pad); border-top: 1px solid rgba(221,161,94,.2);
    color: rgba(251,252,244,.55);
    font-family: var(--font-ui); font-size: .82rem;
    display: flex; flex-direction: column; gap: 6px;
    align-items: center; text-align: center;
}
.footer-meta { color: rgba(251,252,244,.4); font-size: .78rem; }
@media (min-width: 720px) {
    .footer-inner {
        grid-template-columns: minmax(0, 1.6fr) repeat(3, minmax(0, 1fr));
        gap: 40px;
        padding: 48px 24px 28px;
    }
    .footer-bottom {
        flex-direction: row; justify-content: space-between;
        text-align: left; padding: 18px 24px;
    }
}

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

/* Hide brand tagline if not enough room */
@media (max-width: 1280px) {
    .brand-tag { display: none; }
}

/* Hide topnav under 1100, switch to drawer */
@media (max-width: 1100px) {
    .topnav { display: none; }
    .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
    body.guest .topnav {
        display: flex;
        flex: 0 1 auto;
        justify-content: flex-end;
    }
}

/* Trim search-mini at narrower widths */
@media (max-width: 1024px) {
    .search-mini { width: 180px; }
}

/* When topnav is shown, brand text shouldn't dominate */
@media (min-width: 1101px) {
    .brand-name { max-width: 180px; }
    .brand-text { flex-shrink: 0; }
}

/* Tablet: search becomes icon */
@media (max-width: 900px) {
    .search-mini { display: none; }
    .search-trigger { display: inline-flex; }
    .profile-btn { max-width: 140px; }
    .profile-btn span { max-width: 80px; }
}

/* Mobile */
@media (max-width: 640px) {
    :root { --topbar-h: 60px; }
    .topbar-inner { padding: 8px 12px; gap: 6px; min-height: 60px; }
    .brand { gap: 8px; }
    .brand-name { font-size: 1.02rem; max-width: 140px; }
    .brand-logo svg { width: 30px; height: 30px; }
    body.guest .topnav { display: none; }
    .profile-btn { padding: 3px 8px 3px 3px; }
    .profile-btn span { display: none; }
    .profile-btn i { display: none; }
    .profile-btn img { width: 26px; height: 26px; }
    .icon-btn { width: 36px; height: 36px; }
    .icon-btn i { width: 18px; height: 18px; }
    .main { margin: 16px auto 32px; padding: 0 14px; }
    .footer-inner { padding: 32px 16px 20px; gap: 24px; }
    .footer-bottom { padding: 14px 16px; }
}

@media (max-width: 430px) {
    body.auth .brand-text { display: none; }
    body.guest .brand-text { display: flex; }
    body.guest .brand-name { max-width: clamp(118px, 38vw, 150px); }
    .topbar-right { gap: 4px; }
    .icon-btn { width: 34px; height: 34px; }
    .icon-btn i { width: 17px; height: 17px; }
}

@media (max-width: 360px) {
    body.guest .brand-text { display: none; }
}

@media (max-width: 340px) {
    .brand-text { display: none; }
}

/* Desktop padding bumps */
@media (min-width: 900px) {
    .topbar-inner { padding-top: 12px; padding-bottom: 12px; }
    .main { margin: 32px auto 64px; }
}
