/* ==========================================================================
   Hjältebyrån Portal – Central Stylesheet
   Grafisk profil: Montserrat + Hind, Rosa accent (#E854B1)
   ========================================================================== */

/* --------------------------------------------------------------------------
   Google Fonts
   -------------------------------------------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@500;600;700;800&family=Hind:wght@300;400;500;600;700&display=swap');

/* --------------------------------------------------------------------------
   CSS Custom Properties (Brand Tokens)
   -------------------------------------------------------------------------- */
:root {
    /* Brand colors */
    --color-primary: #E854B1;
    --color-primary-light: #F472C8;
    --color-primary-dark: #D03A96;
    --color-primary-50: #FDF2F8;
    --color-primary-100: #FCE7F3;
    --color-primary-200: #FBCFE8;
    --color-primary-hover: #D03A96;

    --color-secondary: #FBAFA9;
    --color-secondary-light: #FCCAC7;
    --color-secondary-dark: #F28B83;

    --color-text: #0C0C0C;
    --color-text-muted: #6B7280;
    --color-bg: #FFFFFF;
    --color-bg-soft: #F9FAFB;

    /* Fonts */
    --font-heading: 'Montserrat', sans-serif;
    --font-body: 'Hind', sans-serif;
    
    /* Sidebar width */
    --sidebar-width: 16rem;
    --mobile-header-height: 4rem;
}

/* --------------------------------------------------------------------------
   Base / Reset
   -------------------------------------------------------------------------- */
* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    color: var(--color-text);
    background-color: var(--color-bg-soft);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

h1, h2, h3, h4,
.font-heading {
    font-family: var(--font-heading);
}

/* Alpine cloak - hides elements until Alpine is loaded */
[x-cloak] { display: none !important; }

/* --------------------------------------------------------------------------
   Portal Layout – Mobile Header
   -------------------------------------------------------------------------- */
.portal-mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--mobile-header-height);
    background: white;
    border-bottom: 1px solid #E5E7EB;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 70;
}

.portal-mobile-header button {
    position: relative;
    z-index: 71;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* Mobile: show mobile header */
@media (max-width: 1023px) {
    .portal-mobile-header {
        display: flex !important;
    }
}

/* Desktop: hide mobile header */
@media (min-width: 1024px) {
    .portal-mobile-header {
        display: none !important;
    }
}

/* --------------------------------------------------------------------------
   Portal Layout – Sidebar
   -------------------------------------------------------------------------- */
.portal-sidebar {
    width: var(--sidebar-width);
    background: var(--color-bg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    flex-shrink: 0;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 60;
    transition: transform 0.3s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Mobile: Sidebar starts off-screen */
@media (max-width: 1023px) {
    .portal-sidebar {
        transform: translateX(-100%);
        width: 280px;
        max-width: 85vw;
        box-shadow: 4px 0 15px rgba(0,0,0,0.1);
    }

    .portal-sidebar.open {
        transform: translateX(0);
    }

    .portal-main-content {
        margin-left: 0 !important;
    }
}

/* Desktop: Sidebar is always visible */
@media (min-width: 1024px) {
    .portal-sidebar {
        position: relative;
        transform: translateX(0) !important;
    }
}

/* Sidebar Overlay */
.portal-sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    background: rgba(0,0,0,0.5);
    z-index: 55;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.portal-sidebar-overlay.active {
    display: block;
}

/* Prevent body scroll when menu is open */
body.menu-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

.portal-sidebar .brand-icon {
    width: 2.5rem;
    height: 2.5rem;
    background: var(--color-primary);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.25rem;
}

.portal-sidebar .nav-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    margin-bottom: 0.25rem;
    border-radius: 0.5rem;
    color: #374151;
    transition: all 0.15s ease;
    text-decoration: none;
}

.portal-sidebar .nav-link:hover {
    background: var(--color-primary-50);
    color: var(--color-primary);
}

.portal-sidebar .nav-link.active {
    background: var(--color-primary);
    color: white;
}

.portal-sidebar .user-avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 9999px;
    background: var(--color-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    font-family: var(--font-heading);
    flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Admin Layout – Sidebar
   -------------------------------------------------------------------------- */
.admin-sidebar {
    width: 260px;
    background: #111827;
    color: white;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.3s ease;
}

.admin-sidebar .brand-icon {
    width: 2.5rem;
    height: 2.5rem;
    background: var(--color-primary);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.125rem;
}

.admin-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

.admin-sidebar-overlay.active {
    display: block;
}

/* Mobile: hide sidebar by default */
@media (max-width: 1023px) {
    .admin-sidebar {
        transform: translateX(-100%);
    }
    .admin-sidebar.open {
        transform: translateX(0);
    }
    .admin-main-content {
        margin-left: 0 !important;
    }
    .admin-mobile-header {
        display: flex !important;
    }
}

/* Desktop: always show sidebar */
@media (min-width: 1024px) {
    .admin-sidebar {
        transform: translateX(0) !important;
    }
    .admin-mobile-header {
        display: none !important;
    }
}

.admin-main-content {
    margin-left: 260px;
    min-height: 100vh;
}

/* Admin menu items */
.admin-menu-label {
    font-size: 11px;
    text-transform: uppercase;
    color: #6b7280;
    font-weight: 600;
    padding: 16px 12px 8px;
    letter-spacing: 0.05em;
    font-family: var(--font-heading);
}

.admin-menu-section {
    padding: 0 12px;
    margin-bottom: 8px;
}

.admin-menu-link {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    margin: 2px 0;
    border-radius: 6px;
    color: #9ca3af;
    text-decoration: none;
    font-size: 14px;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.admin-menu-link:hover {
    background: #1f2937;
    color: white;
}

.admin-menu-link.active {
    background: #374151;
    color: white;
    border-left-color: var(--color-primary);
}

.admin-menu-link i {
    width: 24px;
    text-align: center;
    margin-right: 10px;
    font-size: 15px;
}

.admin-menu-link.active i {
    color: var(--color-primary);
}

.admin-submenu-link {
    padding-left: 45px;
    font-size: 13px;
}

.admin-badge {
    margin-left: auto;
    background: var(--color-primary);
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

/* --------------------------------------------------------------------------
   Admin Modal
   -------------------------------------------------------------------------- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 8px;
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}

/* Modal responsive */
@media (max-width: 640px) {
    .modal-overlay {
        padding: 10px;
        align-items: flex-end;
    }
    
    .modal-content {
        max-height: 90vh;
        border-radius: 12px 12px 0 0;
        animation: slideUp 0.3s ease;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1.5rem;
    background: var(--color-primary);
    color: white;
    border-radius: 0.5rem;
    font-weight: 600;
    font-family: var(--font-heading);
    transition: all 0.15s ease;
    border: none;
    cursor: pointer;
    text-decoration: none;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
}

.btn-primary:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-primary-200);
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1.5rem;
    background: transparent;
    color: var(--color-text);
    border: 1px solid #D1D5DB;
    border-radius: 0.5rem;
    font-weight: 500;
    transition: all 0.15s ease;
    cursor: pointer;
    text-decoration: none;
}

.btn-secondary:hover {
    background: #F3F4F6;
}

.btn-secondary:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
}

/* Button sizes */
.btn-sm {
    padding: 0.375rem 1rem;
    font-size: 0.875rem;
}

.btn-lg {
    padding: 0.75rem 2rem;
    font-size: 1.125rem;
}

/* Full width button on mobile */
@media (max-width: 640px) {
    .btn-mobile-full {
        width: 100%;
    }
}

/* --------------------------------------------------------------------------
   Auth Pages (login, forgot-password, reset-password)
   -------------------------------------------------------------------------- */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--color-primary-50) 0%, var(--color-bg) 50%, #FFF5F5 100%);
    padding: 1rem;
}

.auth-card {
    background: white;
    border-radius: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    padding: 2rem;
    width: 100%;
    max-width: 28rem;
}

@media (min-width: 640px) {
    .auth-card {
        padding: 2.5rem;
    }
}

.auth-card .brand-icon {
    width: 4rem;
    height: 4rem;
    background: var(--color-primary);
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.75rem;
    margin: 0 auto 1.5rem;
}

/* --------------------------------------------------------------------------
   Form Inputs (shared)
   -------------------------------------------------------------------------- */
.form-input {
    width: 100%;
    padding: 0.5rem 1rem;
    border: 1px solid #D1D5DB;
    border-radius: 0.5rem;
    font-family: var(--font-body);
    color: var(--color-text);
    transition: all 0.15s ease;
    font-size: 16px; /* Prevents zoom on iOS */
}

.form-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-200);
}

.form-input:read-only {
    background: #F9FAFB;
    color: #6B7280;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.25rem;
}

.form-group {
    margin-bottom: 1rem;
}

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.card {
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    border: 1px solid #E5E7EB;
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #E5E7EB;
}

@media (min-width: 640px) {
    .card-header {
        padding: 1rem 1.5rem;
    }
}

.card-body {
    padding: 1.25rem;
}

@media (min-width: 640px) {
    .card-body {
        padding: 1.5rem;
    }
}

/* --------------------------------------------------------------------------
   Impersonation Banner
   -------------------------------------------------------------------------- */
.impersonation-banner {
    background: #F59E0B;
    color: white;
    text-align: center;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

@media (max-width: 640px) {
    .impersonation-banner {
        font-size: 0.75rem;
        padding: 0.5rem;
    }
}

/* --------------------------------------------------------------------------
   Tables (Responsive)
   -------------------------------------------------------------------------- */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-responsive table {
    min-width: 640px;
}

/* Card-based table for mobile */
@media (max-width: 767px) {
    .table-cards thead {
        display: none;
    }
    
    .table-cards tbody tr {
        display: block;
        margin-bottom: 1rem;
        background: white;
        border-radius: 0.75rem;
        box-shadow: 0 1px 3px rgba(0,0,0,0.06);
        border: 1px solid #E5E7EB;
        padding: 1rem;
    }
    
    .table-cards tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 0;
        border-bottom: 1px solid #F3F4F6;
    }
    
    .table-cards tbody td:last-child {
        border-bottom: none;
    }
    
    .table-cards tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6B7280;
        font-size: 0.875rem;
    }
}

/* --------------------------------------------------------------------------
   Utilities
   -------------------------------------------------------------------------- */
.text-primary { color: var(--color-primary) !important; }
.bg-primary { background-color: var(--color-primary) !important; }
.border-primary { border-color: var(--color-primary) !important; }

.text-secondary { color: var(--color-secondary) !important; }
.bg-secondary { background-color: var(--color-secondary) !important; }

/* Touch-friendly tap targets */
.touch-target {
    min-height: 44px;
    min-width: 44px;
}

/* Safe area padding for notched devices */
@supports (padding: max(0px)) {
    .safe-area-inset {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    .safe-area-bottom {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

/* --------------------------------------------------------------------------
   Scrollbar Styling
   -------------------------------------------------------------------------- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Hide scrollbar on mobile for cleaner look */
@media (max-width: 1023px) {
    .portal-sidebar::-webkit-scrollbar {
        display: none;
    }
    
    .portal-sidebar {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
}

/* --------------------------------------------------------------------------
   Animations
   -------------------------------------------------------------------------- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.animate-fade-in {
    animation: fadeIn 0.2s ease;
}

/* --------------------------------------------------------------------------
   Print Styles
   -------------------------------------------------------------------------- */
@media print {
    .portal-sidebar,
    .portal-mobile-header,
    .admin-sidebar,
    .admin-mobile-header,
    .btn-primary,
    .btn-secondary {
        display: none !important;
    }
    
    main {
        margin-left: 0 !important;
        padding: 0 !important;
    }
}
