/**
 * IGA Portal — Admin Base Stylesheet
 * Always loaded on every admin/council page.
 * Contains layout, nav, breadcrumbs, stats grid, admin tables,
 * and shared utility classes (form controls, badges, modals).
 */
/**
 * IGA Portal — Admin Stylesheet
 * Supplements style.css for admin panel pages.
 */

/* ── Admin Layout ───────────────────────────────────────────── */
.admin-body {
    /* Cruinn brand palette — overrides public site variables */
    --color-text: #0c1614;
    --color-primary: #1d9e75;
    --color-primary-dark: #166b52;
    --color-primary-light: #5dcaa5;
    --color-bg-light: #f2f5f3;
    --color-bg-dark: #e5ede8;
    --color-border: #ccd9d3;
    background: #f2f5f3;
    margin: 0;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar + Right Column Wrapper ─────────────────────────── */
.admin-wrap {
    display: flex;
    height: 100vh;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    box-shadow: 0 0 60px rgba(0, 0, 0, .12);
    overflow: hidden;
}

/* Wide mode: remove outer constraint — toggled via html.admin-layout-wide */
html.admin-layout-wide .admin-wrap {
    max-width: none;
    box-shadow: none;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.admin-sidebar {
    width: 200px;
    flex-shrink: 0;
    background: var(--color-text, #2c3e50);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.admin-sidebar-hero {
    padding: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, .1);
}

.admin-sidebar-logo {
    display: block;
    color: #fff;
    font-family: var(--font-heading, system-ui);
    font-weight: 700;
    font-size: 1rem;
    text-decoration: none;
    letter-spacing: .02em;
}

.admin-sidebar-logo:hover {
    color: rgba(255, 255, 255, .85);
    text-decoration: none;
}

.admin-sidebar-nav {
    padding: 0.5rem 0;
    flex: 1;
}

.admin-sidebar-nav a {
    display: block;
    padding: 0.4rem 1rem;
    font-size: 0.82rem;
    color: rgba(255, 255, 255, .7);
    text-decoration: none;
    border-right: 3px solid transparent;
    transition: color .15s, border-color .15s, background .15s;
}

.admin-sidebar-nav a:hover {
    color: #fff;
    border-right-color: var(--color-primary, #4a90d9);
    background: rgba(255, 255, 255, .05);
    text-decoration: none;
}

.admin-sidebar-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: rgba(255, 255, 255, .35);
    padding: 0.6rem 1rem 0.2rem;
}

.admin-sidebar-sep {
    display: block;
    height: 1px;
    background: rgba(255, 255, 255, .1);
    margin: 0.5rem 1rem;
}

/* ── Sidebar Nav Groups (flyout children) ────────────────────── */
.admin-sidebar-group {
    position: relative;
}

.admin-sidebar-parent {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-caret {
    font-size: 0.6em;
    opacity: 0.5;
    transition: transform .15s;
}

.admin-sidebar-flyout {
    display: none;
    position: static;
    background: rgba(0, 0, 0, .18);
    border: none;
    border-radius: 0;
    min-width: 0;
    padding: 2px 0 4px;
    box-shadow: none;
}

.admin-sidebar-flyout a {
    display: block;
    padding: 0.3rem 0.9rem 0.3rem 1.4rem;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, .65);
    text-decoration: none;
    border-right: none;
    white-space: nowrap;
}

.admin-sidebar-flyout a:hover {
    color: #fff;
    background: rgba(255, 255, 255, .08);
    border-right: none;
}

.admin-sidebar-group.open>.admin-sidebar-flyout {
    display: block;
}

.admin-sidebar-group.open>.admin-sidebar-parent .sidebar-caret {
    transform: rotate(90deg);
    opacity: 0.8;
}

/* ── Sidebar Stats ───────────────────────────────────────────── */
.admin-sidebar-stats {
    padding: 0.5rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, .1);
}

.admin-sidebar-stat {
    font-size: 0.78rem;
    color: rgba(255, 255, 255, .45);
    padding: 0.15rem 0;
}

.admin-sidebar-stat-num {
    font-weight: 700;
    color: rgba(255, 255, 255, .8);
}

.admin-sidebar-footer {
    margin-top: auto;
    padding: 0.75rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, .1);
}

.admin-sidebar-viewsite {
    font-size: 0.78rem;
    color: rgba(255, 255, 255, .5);
    text-decoration: none;
}

.admin-sidebar-viewsite:hover {
    color: rgba(255, 255, 255, .85);
}

/* ── Right column ────────────────────────────────────────────── */
.admin-right {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* ── Top bar ─────────────────────────────────────────────────── */
.admin-topbar {
    background: var(--color-text, #2c3e50);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .15);
}

.admin-topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    height: 44px;
    gap: 1rem;
}

.admin-topbar-breadcrumb {
    flex: 1;
    min-width: 0;
}

.admin-topbar-breadcrumb .breadcrumb {
    margin-bottom: 0;
}

.admin-topbar-breadcrumb .breadcrumb-item a {
    color: rgba(255, 255, 255, .7);
}

.admin-topbar-breadcrumb .breadcrumb-item a:hover {
    color: #fff;
}

.admin-topbar-breadcrumb .breadcrumb-current span {
    color: rgba(255, 255, 255, .5);
}

.admin-topbar-breadcrumb .breadcrumb-item+.breadcrumb-item::before {
    color: rgba(255, 255, 255, .35);
}

.admin-topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.82rem;
    white-space: nowrap;
}

.admin-topbar-user {
    color: rgba(255, 255, 255, .6);
}

.admin-topbar-right a {
    color: rgba(255, 255, 255, .7);
    text-decoration: none;
}

.admin-topbar-right a:hover {
    color: #fff;
}

.admin-topbar-cms-link {
    color: var(--color-primary-light, #5dcaa5) !important;
    font-size: 0.78rem;
    white-space: nowrap;
}

.admin-topbar-cms-link:hover {
    color: #fff !important;
}

/* ── Layout width toggle ─────────────────────────────────────── */
.admin-width-toggle {
    background: none;
    border: 1px solid rgba(255, 255, 255, .2);
    color: rgba(255, 255, 255, .55);
    font-size: 0.75rem;
    padding: 0.2rem 0.45rem;
    border-radius: 3px;
    cursor: pointer;
    line-height: 1;
    transition: color .15s, border-color .15s;
    font-family: inherit;
}

.admin-width-toggle:hover {
    color: #fff;
    border-color: rgba(255, 255, 255, .45);
}

/* ── Main content area ───────────────────────────────────────── */
.admin-main {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Normal pages: admin-content scrolls within admin-main */
.admin-content {
    padding: var(--space-xl) var(--space-md);
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

/* Full-bleed layouts (editor, 3-panel): no padding, no scroll — child fills 100% */
.admin-content.admin-content--flush {
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.admin-flash {
    padding: var(--space-md) var(--space-md) 0;
}

/* ── Modules banner ──────────────────────────────────────────── */
.modules-banner {
    background: #fef3c7;
    color: #92400e;
    border-bottom: 1px solid #fcd34d;
    padding: 0.6rem 1.25rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.modules-banner a {
    color: #b45309;
    font-weight: 600;
}

.modules-banner-close {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    color: #b45309;
    padding: 0 0.25rem;
}

/* ──────────────────────────────────────────────────────────────
   Responsive Sidebar — collapseable (desktop) + off-canvas (mobile/tablet)
   ────────────────────────────────────────────────────────────── */

/* ── Sidebar toggle button (in topbar) ─────────────────────── */
.admin-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: rgba(255, 255, 255, .7);
    font-size: 1.15rem;
    cursor: pointer;
    padding: 0.3rem 0.55rem;
    border-radius: 4px;
    line-height: 1;
    flex-shrink: 0;
    opacity: .7;
    transition: background .15s, opacity .15s;
}

.admin-sidebar-toggle:hover {
    background: rgba(255, 255, 255, .12);
    opacity: 1;
}

/* ── Sidebar: transition for smooth collapse ────────────────── */
.admin-sidebar {
    overflow: hidden;
    transition: width .25s ease;
}

/* ── Desktop collapse: toggled via html.admin-sidebar-collapsed ── */
html.admin-sidebar-collapsed .admin-sidebar {
    width: 0;
    border-right: none;
}

/* ── Backdrop — only visible on mobile/tablet ───────────────── */
.admin-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 199;
}

.admin-sidebar-backdrop.active {
    display: block;
}

@media (min-width: 1024px) {
    .admin-sidebar-backdrop {
        display: none !important;
    }
}

/* ── Mobile / Tablet: off-canvas drawer ─────────────────────── */
@media (max-width: 1023px) {

    /* Sidebar leaves flex flow — becomes a fixed overlay drawer */
    .admin-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 200;
        width: 200px !important;
        overflow: hidden;
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform .25s ease;
    }

    .admin-sidebar.open {
        transform: translateX(0);
    }

    /* Desktop collapse class has no effect on mobile */
    html.admin-sidebar-collapsed .admin-sidebar {
        width: 200px !important;
    }

    .admin-content {
        padding: 1.25rem 1rem;
    }
}

@media (max-width: 480px) {
    .admin-content {
        padding: 1rem 0.75rem;
    }
}

/* ── Nav Dropdown ───────────────────────────────────────────── */
.admin-nav-group {
    position: relative;
}

.admin-nav-trigger {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    font-family: var(--font-heading);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0;
}

.admin-nav-trigger:hover {
    color: white;
}

.nav-caret {
    font-size: 0.7em;
}

.admin-nav-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--color-text);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    min-width: 160px;
    padding: 4px 0;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    margin-top: 6px;
}

.admin-nav-group:hover .admin-nav-dropdown,
.admin-nav-group:focus-within .admin-nav-dropdown {
    display: block;
}

.admin-nav-dropdown a {
    display: block;
    padding: 6px 14px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.85rem;
    white-space: nowrap;
}

.admin-nav-dropdown a:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    text-decoration: none;
}

.admin-nav-sep {
    width: 1px;
    height: 18px;
    background: rgba(255, 255, 255, 0.2);
    align-self: center;
}

/* ── Breadcrumbs ────────────────────────────────────────────── */
.breadcrumb {
    margin-bottom: var(--space-md);
}

.breadcrumb-list {
    display: flex;
    align-items: center;
    gap: 4px;
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.85rem;
}

.breadcrumb-item+.breadcrumb-item::before {
    content: '›';
    color: var(--color-text-light);
    margin-right: 4px;
}

.breadcrumb-item a {
    color: var(--color-primary);
    text-decoration: none;
}

.breadcrumb-item a:hover {
    text-decoration: underline;
}

.breadcrumb-current span {
    color: var(--color-text-light);
}

/* ── Scrollable Activity ────────────────────────────────────── */
.activity-section {
    margin-top: var(--space-lg);
}

.activity-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-sm);
}

.activity-header h2 {
    margin: 0;
}

.activity-scroll {
    max-height: 340px;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: 8px;
}

.activity-scroll .admin-table {
    border: none;
    border-radius: 0;
    margin: 0;
}

.activity-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--color-bg-dark);
}

/* ── Stats Grid ─────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-2xl);
}

.stat-card {
    background: white;
    padding: var(--space-lg);
    border-radius: 8px;
    border: 1px solid var(--color-border);
    text-align: center;
}

.stat-number {
    display: block;
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-primary);
}

.stat-label {
    display: block;
    font-size: 0.85rem;
    color: var(--color-text-light);
    margin-bottom: var(--space-sm);
}

.stat-link {
    font-size: 0.8rem;
}

.stats-grid-compact {
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
}

.stats-grid-compact .stat-card {
    padding: var(--space-sm) var(--space-md);
}

.stats-grid-compact .stat-number {
    font-size: 1.4rem;
}

/* ── Admin Tables ───────────────────────────────────────────── */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.admin-table th,
.admin-table td {
    padding: 0.35rem 0.55rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
}

.admin-table th {
    background: var(--color-bg-dark);
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--color-text-light);
}

.admin-table code {
    background: var(--color-bg-light);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.8rem;
}

.actions-cell {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
    white-space: nowrap;
}

.actions-cell .inline-form {
    display: inline-flex;
    margin: 0;
}

.actions-cell .btn {
    padding: 0.15rem 0.45rem;
    font-size: 0.75rem;
    line-height: 1.25;
}

/* ── Page Header ────────────────────────────────────────────── */
.admin-page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-xl);
}


/* ──────────────────────────────────────────────────────────────
   Shared Utilities — form controls, badges, modals
   One canonical definition for each shared selector.
   ────────────────────────────────────────────────────────────── */

/* Side-by-side fields */
.form-row {
    display: flex;
    gap: 1.25rem;
}

.form-row>.form-group {
    flex: 1;
    min-width: 0;
}

.form-input {
    width: 100%;
    padding: 0.45rem 0.65rem;
    border: 1px solid var(--color-border, #dee2e6);
    border-radius: 4px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.15s;
}

.form-input:focus {
    border-color: var(--color-primary, #4a90d9);
    outline: none;
    box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.15);
}

select.form-input {
    appearance: auto;
}

textarea.form-input {
    resize: vertical;
    min-height: 3.5rem;
}

.form-help {
    display: block;
    margin-top: 0.3rem;
    font-size: 0.8rem;
    color: var(--color-text-light, #6c757d);
}

.form-help code {
    background: var(--color-bg-light, #f8f9fa);
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    font-size: 0.78rem;
}

.form-actions {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border, #dee2e6);
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: #fff;
    border-radius: 12px;
    padding: 1.5rem 2rem;
    max-width: 500px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal-content h3 {
    margin: 0 0 1rem;
}

/* Badges — base */
.badge {
    display: inline-block;
    padding: 0.2em 0.6em;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: 4px;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: var(--space-2xl);
    color: var(--color-text-muted, #6b7280);
}

.text-muted {
    color: var(--color-text-muted, #6b7280);
}

/* ── Toast notifications ────────────────────────────────── */
.iga-toast {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 9999;
    padding: 0.65rem 1.1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.4;
    max-width: 360px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

.iga-toast.iga-toast-visible {
    opacity: 1;
    transform: translateY(0);
}

.iga-toast-info {
    background: #1e3a5f;
    color: #fff;
}

.iga-toast-success {
    background: #166534;
    color: #fff;
}

.iga-toast-warning {
    background: #92400e;
    color: #fff;
}

.iga-toast-error {
    background: #7f1d1d;
    color: #fff;
}

/* ── Media Browser Modal ─────────────────────────────────────── */
.media-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.media-modal {
    background: #fff;
    border-radius: 8px;
    width: 720px;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.media-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e2e6ea;
}

.media-modal-header h2 {
    margin: 0;
    font-size: 1.1rem;
}

.media-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #6b7280;
    line-height: 1;
}

.media-modal-close:hover {
    color: #111;
}

.media-modal-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid #e2e6ea;
}

.media-modal-grid {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
    align-content: start;
}

.media-item {
    border: 2px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    background: #f9fafb;
    transition: border-color 0.1s;
    display: flex;
    flex-direction: column;
}

.media-item:hover {
    border-color: #1d9e75;
}

.media-item.selected {
    border-color: #1d9e75;
    background: #e0f2eb;
}

.media-item img {
    width: 100%;
    height: 90px;
    min-height: 90px;
    object-fit: cover;
    display: block;
    flex-shrink: 0;
}

.media-item-name {
    font-size: 0.68rem;
    padding: 2px 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #374151;
}

.media-item-size {
    font-size: 0.62rem;
    padding: 0 4px 3px;
    color: #9ca3af;
}

.media-loading,
.media-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: #9ca3af;
    padding: 2rem;
}

.media-modal-footer {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid #e2e6ea;
    justify-content: flex-end;
}

/* ── Media browser folder support ──────────────────────────── */

.media-modal-path {
    font-size: 0.78rem;
    color: #6b7280;
    font-family: monospace;
    flex: 1;
    margin: 0 0.75rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.media-item.media-folder {
    background: #f0f4f8;
    justify-content: center;
    align-items: center;
    padding: 0.5rem 0.25rem;
    text-align: center;
}

.media-item.media-folder:hover {
    background: #e0f2eb;
}

.media-folder-icon {
    font-size: 2rem;
    line-height: 1;
    margin-bottom: 4px;
}
