/* ============================================
   MARAL HNOS SAS — Sistema de Gestión
   Tema: Industrial / Profesional
   ============================================ */

:root {
    --navy: #1a2744;
    --navy-light: #243058;
    --blue: #2563eb;
    --blue-light: #3b82f6;
    --accent: #f59e0b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #f0f2f7;
    --surface: #ffffff;
    --surface2: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --sidebar-w: 240px;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
    overflow-x: hidden;
}

body {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
    max-width: 100vw;
    overflow-x: hidden;
}

/* ---- SIDEBAR ---- */
.sidebar {
    width: var(--sidebar-w);
    background: var(--navy);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-logo img {
    width: 36px;
    height: 36px;
    object-fit: contain;
}

.sidebar-logo span {
    font-family: 'Barlow', sans-serif;
    font-weight: 700;
    font-size: 15px;
    color: #fff;
    letter-spacing: .3px;
}

.sidebar-menu {
    list-style: none;
    padding: 12px 0;
    flex: 1;
    overflow-y: auto;
}

.sidebar-menu .menu-section {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1.2px;
    color: rgba(255,255,255,.3);
    padding: 16px 20px 6px;
    text-transform: uppercase;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    color: rgba(255,255,255,.65);
    text-decoration: none;
    font-size: 14px;
    font-weight: 400;
    transition: all .15s;
    border-left: 3px solid transparent;
}

.sidebar-menu a svg {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
}

.sidebar-menu a:hover {
    color: #fff;
    background: rgba(255,255,255,.06);
}

.sidebar-menu a.active {
    color: #fff;
    background: rgba(37, 99, 235, .25);
    border-left-color: var(--blue-light);
}

.sidebar-footer {
    padding: 14px 20px;
    border-top: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-footer span {
    color: rgba(255,255,255,.6);
    font-size: 13px;
}

.logout-btn {
    color: rgba(255,255,255,.4);
    transition: color .15s;
}
.logout-btn:hover { color: var(--danger); }
.logout-btn svg { width: 18px; height: 18px; }

/* ---- MAIN CONTENT ---- */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    padding: 32px;
    min-height: 100vh;
}

/* ---- PAGE HEADER ---- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
}

.page-header h1 {
    font-family: 'Barlow', sans-serif;
    font-size: 24px;
    font-weight: 700;
    color: var(--navy);
}

.page-header p {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 2px;
}

/* ---- CARDS ---- */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.card-body { padding: 24px; }
.card-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-header h2 {
    font-family: 'Barlow', sans-serif;
    font-size: 16px;
    font-weight: 700;
    color: var(--navy);
}

/* ---- STATS GRID ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; }
.stat-icon.blue { background: #dbeafe; color: var(--blue); }
.stat-icon.green { background: #d1fae5; color: var(--success); }
.stat-icon.amber { background: #fef3c7; color: var(--warning); }
.stat-icon.navy { background: #e0e7ff; color: var(--navy); }

.stat-info p { font-size: 12px; color: var(--text-muted); }
.stat-info h3 { font-family: 'Barlow', sans-serif; font-size: 22px; font-weight: 700; color: var(--navy); }

/* ---- BUTTONS ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 18px;
    border-radius: 8px;
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: all .15s;
    line-height: 1;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--navy); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn-outline {
    background: transparent;
    color: var(--navy);
    border: 1.5px solid var(--border);
}
.btn-outline:hover { border-color: var(--blue); color: var(--blue); }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-sm svg { width: 14px; height: 14px; }

/* ---- TABLE ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

thead th {
    background: var(--surface2);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .7px;
    text-transform: uppercase;
    padding: 11px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:hover { background: var(--surface2); }
tbody tr:last-child { border-bottom: none; }
tbody td { padding: 12px 16px; color: var(--text); }

/* ---- BADGES ---- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-approved { background: #d1fae5; color: #065f46; }
.badge-rejected { background: #fee2e2; color: #991b1b; }
.badge-active { background: #d1fae5; color: #065f46; }
.badge-inactive { background: #f1f5f9; color: #64748b; }

/* ---- FORMS ---- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 18px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }

label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="password"],
input[type="date"],
select,
textarea {
    padding: 9px 13px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    transition: border-color .15s;
    outline: none;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

textarea { resize: vertical; min-height: 80px; }

/* ---- PRESUPUESTO BUILDER ---- */
.items-table { width: 100%; border-collapse: collapse; }
.items-table th {
    background: var(--navy);
    color: rgba(255,255,255,.7);
    font-size: 11px;
    letter-spacing: .7px;
    text-transform: uppercase;
    padding: 10px 12px;
    text-align: left;
}
.items-table td { padding: 8px 6px; vertical-align: middle; }
.items-table tr { border-bottom: 1px solid var(--border); }
.items-table input, .items-table select {
    padding: 7px 10px;
    font-size: 13px;
}

.totals-box {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    min-width: 280px;
}

.totals-box .row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 14px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}
.totals-box .row:last-child { border-bottom: none; }
.totals-box .row.total {
    font-weight: 700;
    font-size: 18px;
    color: var(--navy);
    font-family: 'Barlow', sans-serif;
    padding-top: 12px;
}

/* ---- ALERT ---- */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 18px;
    border-left: 4px solid;
}
.alert-success { background: #f0fdf4; border-color: var(--success); color: #166534; }
.alert-error { background: #fef2f2; border-color: var(--danger); color: #991b1b; }

/* ---- LOGIN ---- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--navy);
}

.login-box {
    background: var(--surface);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.login-box .logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-box .logo img { width: 64px; margin-bottom: 12px; }
.login-box .logo h1 {
    font-family: 'Barlow', sans-serif;
    font-size: 20px;
    font-weight: 800;
    color: var(--navy);
}
.login-box .logo p { color: var(--text-muted); font-size: 13px; }

/* ---- UTILITIES ---- */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); font-size: 13px; }
.w-full { width: 100%; }

/* ---- SEARCH BAR ---- */
.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}
.search-bar input { flex: 1; }

/* ---- EMPTY STATE ---- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: .3; }
.empty-state p { font-size: 15px; }

/* Hidden by default — shown only on mobile via media query */
.mobile-header, .bottom-nav { display: none; }

/* ============================================
   MOBILE — App-native layout
   ============================================ */
@media (max-width: 768px) {

    /* Hide desktop sidebar */
    .sidebar { display: none; }

    /* Top fixed bar */
    .mobile-header {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        position: fixed;
        top: 0; left: 0; right: 0;
        height: 56px;
        background: var(--navy);
        padding: 0 16px;
        z-index: 200;
        box-shadow: 0 2px 8px rgba(0,0,0,.2);
    }

    .mobile-header-brand {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .mobile-header-brand img {
        width: 30px;
        height: 30px;
        object-fit: contain;
    }

    .mobile-header-brand span {
        font-family: 'Barlow', sans-serif;
        font-weight: 700;
        font-size: 16px;
        color: #fff;
        letter-spacing: .3px;
    }

    .mobile-header-logout {
        color: rgba(255,255,255,.5);
        display: flex;
        align-items: center;
        padding: 8px;
        border-radius: 8px;
        transition: color .15s, background .15s;
    }
    .mobile-header-logout:hover { color: var(--danger); background: rgba(255,255,255,.06); }
    .mobile-header-logout svg { width: 20px; height: 20px; }

    /* Main content adjustments */
    .main-content {
        margin-left: 0;
        padding: 16px;
        padding-top: calc(56px + 16px);
        padding-bottom: calc(64px + env(safe-area-inset-bottom) + 16px);
        min-height: 100vh;
        overflow-x: hidden;
        width: 100%;
        max-width: 100vw;
    }

    /* Bottom tab bar */
    .bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: calc(64px + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        background: var(--navy);
        border-top: 1px solid rgba(255,255,255,.08);
        z-index: 200;
    }

    .bottom-nav a {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        color: rgba(255,255,255,.45);
        text-decoration: none;
        font-size: 10px;
        font-weight: 500;
        letter-spacing: .2px;
        transition: color .15s;
        position: relative;
        padding-bottom: 4px;
    }

    .bottom-nav a svg {
        width: 22px;
        height: 22px;
        transition: transform .15s;
    }

    .bottom-nav a.active {
        color: #fff;
    }

    .bottom-nav a.active svg {
        transform: translateY(-1px);
    }

    .bottom-nav a.active::before {
        content: '';
        position: absolute;
        top: 0; left: 25%; right: 25%;
        height: 2px;
        background: var(--blue-light);
        border-radius: 0 0 2px 2px;
    }

    /* Layout adjustments */
    .stats-grid { grid-template-columns: 1fr 1fr; }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 20px;
    }

    .page-header > .flex,
    .page-header > a,
    .page-header > .btn {
        align-self: stretch;
        justify-content: center;
    }

    .form-grid { grid-template-columns: 1fr; }

    .search-bar { flex-wrap: wrap; }

    /* Presupuesto builder */
    div[style*="grid-template-columns:1fr 360px"],
    div[style*="grid-template-columns:1fr 300px"] {
        display: block !important;
    }

    .totals-box { min-width: unset; margin-top: 20px; }

    /* Hide secondary table columns to prevent horizontal overflow */
    .col-mobile-hide { display: none !important; }

    /* Ensure cards don't overflow */
    .card { max-width: 100%; overflow: hidden; }

    /* Ensure stat info text wraps */
    .stat-info { min-width: 0; overflow: hidden; }
    .stat-info h3 { font-size: 18px; }

    /* Inputs don't exceed viewport */
    input, select, textarea { max-width: 100%; }
}

