/* ═══════════════════════════════════════════════════════════════════
   SAAFF ERP SYSTEM
   main.css  ·  Global Layout, Authentication, & Dashboard (Responsive)
   ═══════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

/* ─── DESIGN TOKENS (SAAFF Logo Palette) ─────────────────────────── */
:root {
    /* Brand palette */
    --saaff-slate: #3b7396;    /* From the 'aa' and left swoosh */
    --saaff-light: #0099cc;    /* From the arrow and bottom swoosh */
    --saaff-dark: #22445c;     /* Deepened slate for high-contrast areas like sidebars */
    --saaff-black: #1a1a1a;    /* From the 's', 'f', 'f' */
    --white: #FFFFFF;

    /* Surfaces */
    --bg: #f4f7f8;
    --sidebar: #22445c;
    --card: #FFFFFF;

    /* Typography */
    --text: #2d3748;
    --muted: #718096;
    --border: #e2e8f0;

    /* Status */
    --danger: #e53e3e;
    --success: #38a169;
    --warning: #d69e2e;

    /* Layout */
    --sidebar-w: 260px;
    --topbar-h: 68px;

    /* Radius & Shadows */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 12px 30px rgba(34, 68, 92, 0.1);

    /* Transitions */
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* Fonts */
    --font-base: 'Inter', Segoe UI, Arial, sans-serif;
}

/* ─── RESET & BASE ────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 14px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-base);
    color: var(--text);
    background-color: var(--bg);
    line-height: 1.55;
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

a {
    color: var(--saaff-light);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover { color: var(--saaff-slate); }
h1, h2, h3, h4, h5, h6 { font-weight: 700; line-height: 1.2; color: var(--saaff-black); }

/* ══════════════════════════════════════════════════════════════════
   AUTHENTICATION PAGE (Login)
══════════════════════════════════════════════════════════════════ */
.auth-page {
    width: 100vw;
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--saaff-slate), var(--saaff-dark));
    padding: 20px;
}

.auth-shell {
    width: 100%;
    max-width: 480px;
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 40px;
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.25);
}

.brand-block {
    text-align: center;
    margin-bottom: 30px;
}

.brand-logo-img {
    height: 60px;
    margin-bottom: 15px;
}

.brand-block h1 { font-size: 22px; color: var(--saaff-slate); }
.brand-block p { margin-top: 5px; color: var(--muted); font-size: 13px; }

.login-switch {
    display: flex;
    background: #edf2f7;
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 24px;
}

.switch-btn {
    flex: 1;
    border: 0;
    background: transparent;
    padding: 10px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    color: var(--muted);
    transition: 0.2s ease;
    font-size: 13px;
}

.switch-btn.active {
    background: var(--white);
    color: var(--saaff-slate);
    box-shadow: var(--shadow-sm);
}

.login-form { display: none; flex-direction: column; gap: 16px; animation: fadeIn 0.3s ease; }
.login-form.active { display: flex; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-weight: 600; font-size: 13px; color: var(--saaff-dark); }

.form-group input, .form-group select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fafbfc;
    font: inherit;
    outline: none;
    transition: 0.2s ease;
}

.form-group input:focus, .form-group select:focus {
    border-color: var(--saaff-light);
    box-shadow: 0 0 0 3px rgba(0, 153, 204, 0.15);
    background: var(--white);
}

.btn-primary {
    border: 0;
    border-radius: 8px;
    padding: 12px 16px;
    font-weight: 700;
    cursor: pointer;
    background: var(--saaff-slate);
    color: var(--white);
    transition: 0.2s ease;
    width: 100%;
    font-size: 14px;
    margin-top: 10px;
}

.btn-primary:hover { background: var(--saaff-dark); }

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 13px;
    font-weight: 500;
    text-align: center;
}

.alert.error { background: #fff0ef; color: var(--danger); border: 1px solid #feb2b2; }

/* ══════════════════════════════════════════════════════════════════
   ERP SHELL (Sidebar & Topbar)
══════════════════════════════════════════════════════════════════ */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    background: var(--sidebar);
    color: var(--white);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    transition: transform var(--transition);
}

.sidebar-logo {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-logo img {
    height: 35px;
    display: block;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); }

.nav-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.4);
    padding: 10px 24px;
    margin-top: 10px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.75);
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    text-decoration: none;
    font-weight: 500;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--white);
}

.nav-item.active {
    background: rgba(0, 153, 204, 0.15);
    border-left-color: var(--saaff-light);
    color: var(--white);
}

.sidebar-user {
    padding: 20px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.15);
}

.sidebar-user .user-name { font-weight: 600; font-size: 14px; color: var(--white); word-break: break-all;}
.sidebar-user .user-role { font-size: 11px; color: var(--saaff-light); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px; word-break: break-all;}

.main-wrapper {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left var(--transition);
    min-width: 0; /* Prevents flex blowout */
}

.topbar {
    height: var(--topbar-h);
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0; /* Allows text truncation if needed */
}

.topbar-title { font-size: 18px; font-weight: 700; color: var(--saaff-slate); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}
.topbar-actions a { color: var(--danger); font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 6px;}

.content {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
}

/* ══════════════════════════════════════════════════════════════════
   DASHBOARD / HOME (index.html)
══════════════════════════════════════════════════════════════════ */
.hero {
    background: linear-gradient(120deg, var(--saaff-slate), var(--saaff-dark));
    color: var(--white);
    border-radius: var(--radius-lg);
    padding: 32px;
    margin-bottom: 32px;
    position: relative;
    overflow: hidden;
}

.hero::after {
    content: '';
    position: absolute;
    right: 0; top: 0; bottom: 0;
    width: 300px;
    background: linear-gradient(90deg, transparent, rgba(0, 153, 204, 0.3));
    pointer-events: none;
}

.hero h1 { color: var(--white); font-size: 28px; margin-bottom: 8px; }
.hero p { opacity: 0.9; font-size: 15px; max-width: 600px; line-height: 1.6;}

.tool-grid {
    display: grid;
    /* min() ensures it doesn't break on extremely small screens */
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
    gap: 24px;
}

.tool-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    text-decoration: none;
    color: inherit;
}

.tool-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: var(--saaff-light);
}

.tool-icon {
    width: 54px;
    height: 54px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin-bottom: 20px;
}

.icon-rmt { background: rgba(59, 115, 150, 0.1); color: var(--saaff-slate); }
.icon-docs { background: rgba(0, 153, 204, 0.1); color: var(--saaff-light); }
.icon-customs { background: rgba(34, 68, 92, 0.1); color: var(--saaff-dark); }

.tool-card h2 { font-size: 18px; margin-bottom: 8px; color: var(--saaff-black); }
.tool-card p { font-size: 13px; color: var(--muted); margin-bottom: 20px; flex: 1; line-height: 1.5;}
.tool-card .enter-link { font-weight: 700; color: var(--saaff-light); font-size: 13px; display: flex; align-items: center; gap: 5px; }


/* ══════════════════════════════════════════════════════════════════
   COLLAPSIBLE SIDEBAR & RESPONSIVE LOGIC
══════════════════════════════════════════════════════════════════ */

/* The Hamburger Button */
.sidebar-toggle-btn {
    background: transparent;
    border: none;
    color: var(--saaff-slate);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle-btn:hover {
    background: #edf2f7;
    color: var(--saaff-dark);
}

/* --- DESKTOP BEHAVIOR (Above 1024px) --- */
/* By default, sidebar is visible. Toggling hides it to the left. */
body.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
}
body.sidebar-collapsed .main-wrapper {
    margin-left: 0;
}

/* --- TABLET BEHAVIOR (Below 1024px) --- */
@media screen and (max-width: 1024px) {
    /* By default on tablet/mobile, sidebar is HIDDEN */
    .sidebar { 
        transform: translateX(-100%); 
        box-shadow: 4px 0 15px rgba(0,0,0,0.3); /* Adds depth when opened as overlay */
    }
    
    /* Main wrapper always takes full width */
    .main-wrapper { 
        margin-left: 0; 
    }
    
    /* Clicking the hamburger OPENS the sidebar as an overlay */
    body.sidebar-collapsed .sidebar {
        transform: translateX(0);
    }
    
    .content { padding: 24px; }
    .topbar { padding: 0 24px; }
}

/* --- MOBILE BEHAVIOR (Below 768px) --- */
@media screen and (max-width: 768px) {
    .content { padding: 16px; }
    .topbar { padding: 0 16px; }
    
    .hero { 
        padding: 24px 20px; 
        margin-bottom: 24px; 
    }
    .hero h1 { font-size: 22px; }
    .hero p { font-size: 14px; }
    
    .topbar-title { font-size: 16px; }
    .topbar-actions span { display: none; } /* Hides "Logout" text, keeps icon */
    
    .auth-shell { padding: 32px 24px; }
    .tool-grid { gap: 16px; }
}

/* --- SMALL MOBILE BEHAVIOR (Below 480px) --- */
@media screen and (max-width: 480px) {
    .topbar-title { font-size: 14px; }
    .hero h1 { font-size: 20px; }
    
    .tool-card { padding: 20px; }
    .tool-icon { 
        width: 44px; 
        height: 44px; 
        font-size: 20px; 
        margin-bottom: 16px;
    }
    .auth-shell { padding: 24px 20px; }
}