/* Consolidated app styles moved from layout.php */
:root {
    --bs-primary: #0d9488; /* teal-ish */
    --accent: #0f766e;
    --muted: #6b7280;
    --surface: #ffffff;
    --card-bg: #ffffff;
    --glass: rgba(255,255,255,0.6);
}
html,body { height:100%; }
body {
    padding-top: 72px;
    font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
    background: linear-gradient(180deg,#f6fbfb 0%, #ffffff 100%);
    color: #0f172a;
    transition: background-color .2s, color .2s;
}
/* Make sure main content does not overflow the viewport and allow
   internal scroll when necessary. Also ensure flex children can shrink
   to avoid overflowing due to long content. */
#app-content-debug {
    max-width: 100vw; /* never exceed viewport width */
    overflow-x: auto; /* allow internal horizontal scrolling */
    -webkit-overflow-scrolling: touch;
}

/* Common fix: allow flex items to shrink instead of forcing parent width */
.flex-1, .flex > .flex-1, .flex > .min-w-0 {
    min-width: 0 !important;
}
/* Mobile responsive tweaks */
@media (max-width: 767px) {
    body { padding-top: 64px; }
    /* Hide desktop sidebar only when it has not been moved into the drawer */
    /* The sidebar element will be given class .mobile-original-sidebar and when moved it will receive .in-drawer */
    #sidebar.mobile-original-sidebar:not(.in-drawer) { display: none !important; }
    /* Make header content compact */
    nav .w-full { padding-left: 0.5rem; padding-right: 0.5rem; }
    /* Allow content to be full-width on mobile */
    .md\\:ml-64 { margin-left: 0 !important; }
}

/* Off-canvas mobile sidebar styles */
.mobile-drawer-backdrop { display: none; }
.mobile-drawer { display:none; }
@media (max-width: 767px) {
    /* Backdrop sits below the top navbar (navbar uses z-40). Keep it above page content. */
    .mobile-drawer-backdrop { position: fixed; left: 0; right: 0; top: 64px; bottom: 0; background: rgba(0,0,0,0.45); z-index: 25; display: none; opacity: 0; transition: opacity 180ms ease; }

    /* Drawer positioned directly below the fixed navbar so it doesn't cover it visually. */
    .mobile-drawer { display: block; position: fixed; top: 64px; left: 0; height: calc(100vh - 64px); width: 80vw; max-width: 320px; background: var(--card-bg); z-index: 30; transform: translateX(-110%); transition: transform 260ms ease, box-shadow 220ms ease; padding-top: 0; overflow-y: auto; box-shadow: 6px 0 22px rgba(2,6,23,0.12); border-radius: 0; }

    .mobile-drawer.open { transform: translateX(0%); }

    /* Slight visual polish when open */
    .mobile-drawer.open { outline: none; background: linear-gradient(180deg, #ffffff, #fbfdff); }

     /* Keep hidden elements actually hidden to avoid layout gaps. Previously we
         forced .hidden to display:block which caused dropdown panels to occupy
         space even when closed. Instead, be explicit about which elements should
         be flex and visible in the drawer (links and buttons). */

     /* Sidebar links and toggle button should remain flex so icons and text sit
         inline (no unwanted linebreaks). Make padding consistent between anchors
         and the postsToggle button. */
     .mobile-drawer #sidebar nav a,
     .mobile-drawer #sidebar button {
          display: flex !important;
          align-items: center;
          gap: 12px;
          padding: 12px 16px !important;
          text-decoration: none;
          color: inherit;
     }

     /* Ensure closed dropdown panels don't take vertical space inside the drawer */
     .mobile-drawer #postsMenuFlow.hidden,
     .mobile-drawer #postsMenuFlow.scale-y-0 {
          display: none !important;
          height: 0; overflow: hidden;
          padding: 0; margin: 0;
     }

     /* When the real sidebar is moved into the drawer, make sure it displays properly
         and reset heights so it doesn't force a full viewport and create extra scrolling. */
     .mobile-drawer #sidebar { position: static; width: 100%; height: auto; min-height: 0; top: auto; left: auto; padding-top: 1.6rem; box-shadow: none; border-radius: 0; overflow: visible; }
    .mobile-drawer #sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 12px 16px; }
    .mobile-drawer #sidebar .chev { display: inline-block; transform: rotate(0); margin-left: auto; }

    .mobile-drawer-backdrop.open { display:block; opacity: 1; }

    /* ensure main content is scrollable when drawer closed; lock when open via JS */
}

/* Small-screen search input stretch */
@media (max-width: 640px) {
    form[action="/users"] { width: 100%; }
    form[action="/users"] input[type="search"] { width: 100%; }
}
.card-tiles { gap: 1rem; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* Navbar */
.navbar {
    background: linear-gradient(90deg, rgba(13,148,136,0.95), rgba(8,120,113,0.95));
    box-shadow: 0 4px 18px rgba(15,23,42,0.06);
}
.navbar .navbar-brand { font-weight:700; letter-spacing:0.2px; color: #fff; }
.navbar .nav-link, .navbar .dropdown-item { color: rgba(255,255,255,0.95); }

/* Icon-only navbar buttons (user, language, theme) should be circular and centered */
nav button.rounded-full, nav .rounded-full {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0; /* use fixed size instead of padding so shape is consistent */
}
nav button.rounded-full i.bi, nav .rounded-full i.bi {
    font-size: 18px;
    line-height: 1;
}

/* Desktop-only sidebar: keep fixed and scrollable on md+ screens only to avoid
    creating a separate scroll container on small devices (which caused double
    vertical scrollbars on mobile when the page also scrolls). */
@media (min-width: 768px) {
    /* Sidebar */
    #sidebar {
        width: 260px;
        /* fit exactly beneath the fixed header (64px tall) so we don't create an extra document scrollbar */
        height: calc(100vh - 64px);
        position: fixed;
        top: 64px;
        left: 0;
        padding-top: 2rem;
        background: linear-gradient(180deg, #ffffff, #fbfdff);
        border-right: none;
        box-shadow: 2px 0 12px rgba(15,23,42,0.04);
        border-radius: 0 12px 12px 0;
        padding-bottom: 2rem;
        overflow: auto;
    }
    #sidebar .nav-link { color: #0f172a; border-radius:8px; padding:10px 16px; }
    #sidebar .nav-link:hover { background: rgba(13,148,136,0.06); color: var(--accent); }

    /* Ensure sidebar anchors and toggle buttons are horizontally aligned (icon + text inline) */
    #sidebar nav a,
    #sidebar nav button,
    #sidebar a {
        display: flex !important;
        align-items: center;
        gap: 10px;
        padding: 10px 16px !important;
    }
}
/* (sidebar rules are defined inside the media query above) */

/* Posts history: prevent row overflow by allowing content to shrink and wrapping long text.
   This targets the history list container in app/Views/posts/history.php. */
.bg-white.border.rounded-lg.shadow-sm { overflow: hidden; }
.bg-white.border.rounded-lg.shadow-sm .divide-y > .p-4 { min-width: 0; }
.bg-white.border.rounded-lg.shadow-sm .p-4 .flex-1 { min-width: 0; }
.bg-white.border.rounded-lg.shadow-sm .p-4 img,
.bg-white.border.rounded-lg.shadow-sm .p-4 video { max-width: 100%; width: 56px; height: 56px; object-fit: cover; }
.bg-white.border.rounded-lg.shadow-sm .p-4 .truncate {
    /* Desktop: keep single-line truncation. Mobile: allow wrapping and clamping. */
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bg-white.border.rounded-lg.shadow-sm .p-4 .text-sm { word-break: break-word; }

/* On small screens allow the snippet/title to wrap instead of forcing the row wider */
@media (max-width: 640px) {
    .bg-white.border.rounded-lg.shadow-sm .p-4 .truncate {
        white-space: normal; /* allow wrapping */
        display: -webkit-box;
    -webkit-line-clamp: 3; /* clamp to ~3 lines */
    line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    .bg-white.border.rounded-lg.shadow-sm .p-4 .flex-1 { overflow-wrap: anywhere; }
    .bg-white.border.rounded-lg.shadow-sm .p-4 img,
    .bg-white.border.rounded-lg.shadow-sm .p-4 video { width: 56px; height: 56px; max-width: 56px; }
}

/* postsToggle button styling parity with anchors */
#postsToggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    padding: 10px 16px;
    background: transparent;
    border: 0;
}

/* Ensure the main post textarea can scroll internally when the content gets long.
   This prevents the whole page from growing and creates a contained scroll area. */

/* Feed page small improvements */
.page-title {
    letter-spacing: -0.01em;
}
.panel {
    background: #fff;
    border: 1px solid #e5e7eb;
    padding: 1rem;
    border-radius: .5rem;
}
.feed-post-card {
    border: 1px solid #e6edf3;
    border-radius: .5rem;
    padding: .5rem;
    background: #fafafa;
}
#postText {
    max-height: 40vh; /* won't grow beyond ~40% of viewport height */
    min-height: 6rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

#postText:focus {
    outline: none;
}

/* Chevron alignment and transition */
.chev { display: inline-block; transition: transform 180ms ease; }

/* Ensure posts menu flow does not take up space when closed */
#postsMenuFlow.hidden,
#postsMenuFlow.scale-y-0 {
    display: none !important;
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
}

/* Cards and controls */
.card { border-radius: 12px; background: var(--card-bg); box-shadow: 0 6px 18px rgba(15,23,42,0.04); border: 1px solid rgba(15,23,42,0.04); }
.card .card-body h1.h5 { font-size: 1.05rem; }

/* Buttons */
.btn-primary { background: var(--bs-primary); border-color: var(--bs-primary); }
.btn-outline-primary { color: var(--bs-primary); border-color: rgba(13,148,136,0.15); }

/* Inputs */
.form-control:focus { box-shadow: 0 0 0 0.15rem rgba(13,148,136,0.12); border-color: var(--bs-primary); }

/* Dark theme overrides */
body.dark {
    background: linear-gradient(180deg,#071018,#071218);
    color: #e6eef0;
}
body.dark .navbar { background: linear-gradient(90deg,#0b1220,#08121a); }
body.dark #sidebar { background: #071018; box-shadow: none; }
body.dark .card { background:#0d1113; color:#e6eef0; border-color: rgba(255,255,255,0.03); }
body.dark .nav-link, body.dark .dropdown-item { color: #cfe7e4; }
/* Mobile drawer dark mode: ensure off-canvas drawer matches dark theme */
body.dark .mobile-drawer { background: #0b1113 !important; box-shadow: none !important; color: #e6eef0 !important; }
body.dark .mobile-drawer.open { background: #0b1113 !important; }
body.dark .mobile-drawer #sidebar nav a,
body.dark .mobile-drawer #sidebar button { color: #dbeef0 !important; }
body.dark .mobile-drawer-backdrop { background: rgba(0,0,0,0.6) !important; }
/* Preview frame (live preview area) */
.preview-frame { background: #f8f9f9; border: 1px dashed rgba(15,23,42,0.04); }
.preview-frame.bg-gray-50 { background: #f8f9f9; }
body.dark .preview-frame { background: #071018; border-color: rgba(255,255,255,0.03); }
body.dark .preview-frame.bg-gray-50 { background: #071018; }
/* Map common Tailwind utility classes to dark theme equivalents for consistency */
body.dark .bg-white { background-color: #0b1113 !important; }
body.dark .bg-gray-50 { background-color: #071018 !important; }
body.dark .bg-gray-100 { background-color: #071018 !important; }
body.dark .bg-gray-200 { background-color: #0b1316 !important; }
body.dark .bg-white\/10 { background-color: rgba(255,255,255,0.06) !important; }
body.dark .hover\:bg-white\/20:hover { background-color: rgba(255,255,255,0.12) !important; }
/* Sidebar hover mapping: ensure hover backgrounds are subtle in dark mode */
body.dark .hover\:bg-gray-50:hover { background-color: rgba(255,255,255,0.02) !important; }
body.dark .hover\:bg-gray-100:hover { background-color: rgba(255,255,255,0.03) !important; }
body.dark a:hover, body.dark button:hover { opacity: 0.95; }
body.dark .text-gray-700, body.dark .text-gray-800 { color: #dbeef0 !important; }
body.dark .text-gray-600, body.dark .text-gray-500 { color: #9fb7b5 !important; }
body.dark .text-gray-400 { color: #8aa7a5 !important; }
body.dark .border-gray-100, body.dark .border-gray-200, body.dark .border-gray-300, body.dark .border { border-color: rgba(255,255,255,0.04) !important; }
body.dark .hover\:bg-gray-100:hover { background-color: rgba(255,255,255,0.02) !important; }
body.dark .bg-teal-50 { background-color: rgba(13,148,136,0.04) !important; }
body.dark .bg-white\/10 { background-color: rgba(255,255,255,0.06) !important; }
body.dark .focus\:ring-teal-300:focus { box-shadow: 0 0 0 0.2rem rgba(13,148,136,0.12) !important; }
body.dark .bg-emerald-600, body.dark .bg-blue-600, body.dark .bg-red-600 { box-shadow: none; }
/* Schedule toggle (small switch) - make knob and track visible in dark mode */
body.dark #scheduleToggle { background-color: rgba(255,255,255,0.06) !important; }
body.dark #scheduleToggle[aria-pressed] { background-color: var(--bs-primary) !important; }
body.dark #scheduleToggleKnob { background-color: #ffffff !important; box-shadow: 0 1px 2px rgba(0,0,0,0.4); }
body.dark #scheduleToggleKnob.translate-x-5 { transform: translateX(1.25rem) !important; }
/* Keep primary buttons filled in dark mode so CTAs remain visible */
body.dark .bg-primary, body.dark .btn-primary, body.dark .btn-primary:hover {
    background-color: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
    color: #fff !important;
    box-shadow: none !important;
}
/* Ensure .bg-teal-50 accent still looks subtle in dark */
body.dark .bg-teal-50 { background-color: rgba(13,148,136,0.12) !important; }
/* Form control dark-mode overrides */
body.dark input, body.dark textarea, body.dark select, body.dark .form-control {
    background-color: #071018 !important;
    color: #e6eef0 !important;
    border-color: rgba(255,255,255,0.06) !important;
}
body.dark input::placeholder, body.dark textarea::placeholder { color: rgba(255,255,255,0.45) !important; }
body.dark .shadow-sm { box-shadow: none !important; }

/* Sidebar active accent */
#sidebar a.active { position: relative; padding-left: 0.75rem; }
#sidebar a.active::before {
    content: '';
    position: absolute;
    left: 0.35rem;
    top: 0.6rem;
    bottom: 0.6rem;
    width: 3px;
    border-radius: 3px;
    background: linear-gradient(180deg,#0d9488,#0f766e);
}

/* postsToggle padding parity and chevron */
#postsToggle { padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#postsToggle .chev { margin-left: 6px; transition: transform 160ms ease; }
#postsToggle.open .chev { transform: rotate(90deg); }

/* posts menu: hidden by default so it doesn't create layout gaps; shown when scale-y-100 present */
#postsMenuFlow {
    display: none;
    transform-origin: top right;
    transition: transform 220ms cubic-bezier(.2,.9,.2,1), opacity 180ms ease;
}
#postsMenuFlow.scale-y-100 { display: block; transform: scaleY(1); opacity: 1; }
#postsMenuFlow.scale-y-0, #postsMenuFlow.hidden { display: none !important; height: 0; padding: 0; margin: 0; overflow: hidden; }

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    .transition-all, .transition-transform { transition: none !important; }
}

/* Toast enter/leave helpers */
.toast-enter { transform: translateY(-8px) scale(.98); opacity: 0; }
.toast-leave { transform: translateY(-8px) scale(.98); opacity: 0; }

/* Mobile-only: make tables scroll horizontally inside their card so the
   page doesn't get a horizontal scrollbar. Targets the .overflow-x-auto
   wrapper used in users/index.php. */
@media (max-width: 640px) {
    .overflow-x-auto {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    .overflow-x-auto table.min-w-full {
        width: max-content !important; /* table grows to its content */
        min-width: max-content !important;
        table-layout: auto !important;
    }
    /* prevent ancestor clipping from hiding the scrollbar */
    .bg-white.shadow.rounded-md.overflow-hidden {
        overflow-x: visible !important;
    }
}

/* Mobile safety: prevent the entire page from scrolling horizontally while
   allowing internal scrollable containers to present their own scrollbars. */
@media (max-width: 640px) {
    /* ensure our specific wrappers can still scroll */
    .overflow-x-auto { overflow-x: auto !important; }
}

/* Footer safe-area handling for mobile devices (iPhone X and newer, Android inset) */
footer.fixed.left-0.right-0.bottom-0,
footer.fixed {
    /* legacy iOS constant() fallback and modern env() */
    padding-bottom: constant(safe-area-inset-bottom, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
    /* ensure background extends into the safe area */
    background-clip: padding-box;
}

/* Add bottom padding to the main content on small screens so content doesn't
   appear separated from the footer when scrolling (accounts for footer height
   + the safe-area inset). Use a conservative footer height of 48px. */
@media (max-width: 767px) {
    /* target the main content area */
    .flex-1.md\:ml-64 > main, .flex-1 > main {
        padding-bottom: calc(48px + env(safe-area-inset-bottom, 0));
    }
    /* Keep toasts visible above the footer */
    #toast-container { margin-bottom: calc(8px + env(safe-area-inset-bottom, 0)); }

    /* Add a little extra breathing room to the footer on mobile devices */
    footer.fixed.left-0.right-0.bottom-0,
    footer.fixed {
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0));
    }

    /* Prevent the brand text from being overlapped by the menu button on very small screens.
       Limit its width and ellipsize the text; keep the logo visible. */
    .navbar .navbar-brand {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        max-width: calc(100vw - 120px); /* leave room for icon buttons */
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .navbar .navbar-brand img { flex: 0 0 auto; }
    .navbar .navbar-brand span { display: inline-block; vertical-align: middle; }
}
