/* ============================================================
   YOAN MÉCANO — Admin styles
   Mobile-first, dark theme, optimized for iPhone
   ============================================================ */

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

:root {
    --bg: #04060d;
    --bg2: #070d1c;
    --bg3: #0a1530;
    --bg-card: #0d1525;
    --blue: #1d6dff;
    --blue-light: #4ea3ff;
    --blue-dark: #0a3a99;
    --white: #e6ecf5;
    --gray: #94a3b8;
    --gray-dark: #5a6678;
    --border: rgba(80, 150, 255, 0.15);
    --border-hover: rgba(80, 150, 255, 0.4);
    --green: #6fd690;
    --red: #ff8a8a;
    --orange: #ffc857;
}

html, body {
    background: var(--bg);
    color: var(--white);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
    min-height: 100vh;
}

body { overflow-x: hidden; }

a { color: var(--blue-light); text-decoration: none; }
a:hover { color: var(--blue); }
img { max-width: 100%; display: block; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background:
        radial-gradient(circle at top right, rgba(30, 110, 255, 0.15), transparent 50%),
        radial-gradient(circle at bottom left, rgba(10, 58, 153, 0.2), transparent 50%),
        var(--bg);
    position: relative;
}
.login-page::before {
    content: "";
    position: absolute; inset: 0;
    background-image:
        linear-gradient(rgba(60,120,255,0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(60,120,255,0.05) 1px, transparent 1px);
    background-size: 48px 48px;
    pointer-events: none;
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px 32px;
    box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.5), 0 0 60px -10px rgba(30, 110, 255, 0.2);
    position: relative;
    z-index: 2;
}
.login-logo {
    text-align: center;
    margin-bottom: 28px;
}
.login-logo img {
    width: 100px;
    height: 100px;
    margin: 0 auto 14px;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(80, 150, 255, 0.4), 0 10px 30px rgba(30, 110, 255, 0.3);
}
.login-logo .name {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 0.05em;
    color: white;
}
.login-logo .sub {
    font-size: 11px;
    color: var(--blue-light);
    letter-spacing: 0.25em;
    text-transform: uppercase;
    margin-top: 4px;
}
.login-card h1 {
    font-size: 22px;
    text-align: center;
    margin-bottom: 8px;
    color: white;
}
.login-card .subtitle {
    text-align: center;
    color: var(--gray);
    font-size: 14px;
    margin-bottom: 28px;
}

/* Forms */
.field { margin-bottom: 18px; }
label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--blue-light);
    margin-bottom: 8px;
}
input[type="text"], input[type="email"], input[type="password"],
input[type="tel"], input[type="number"], input[type="date"],
textarea, select {
    width: 100%;
    padding: 14px;
    background: var(--bg);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    color: white;
    font-size: 16px; /* 16px to prevent iOS zoom */
    font-family: inherit;
    transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(30, 110, 255, 0.15);
}
textarea { min-height: 100px; resize: vertical; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--blue);
    color: white;
    border: none;
    padding: 14px 24px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, transform 0.1s;
    font-family: inherit;
}
.btn:hover { background: var(--blue-light); }
.btn:active { transform: translateY(1px); }
.btn-block { width: 100%; }
.btn-secondary {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.05); }
.btn-danger { background: #c43838; }
.btn-danger:hover { background: #e54545; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-icon {
    padding: 10px;
    width: 40px; height: 40px;
}

/* Alerts */
.alert {
    padding: 14px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
    line-height: 1.5;
}
.alert-error { background: rgba(220, 40, 40, 0.12); border: 1px solid rgba(220, 40, 40, 0.4); color: var(--red); }
.alert-success { background: rgba(50, 200, 100, 0.1); border: 1px solid rgba(50, 200, 100, 0.4); color: var(--green); }
.alert-info { background: rgba(30, 110, 255, 0.1); border: 1px solid rgba(30, 110, 255, 0.4); color: var(--blue-light); }
.alert-warning { background: rgba(255, 180, 30, 0.1); border: 1px solid rgba(255, 180, 30, 0.4); color: var(--orange); }

.muted { color: var(--gray); font-size: 13px; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* ============================================================
   ADMIN LAYOUT (sidebar + main)
   ============================================================ */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--bg2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 30;
    transition: transform 0.3s;
}
.sidebar-header {
    padding: 22px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}
.sidebar-header img {
    width: 40px; height: 40px;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(80, 150, 255, 0.4);
}
.sidebar-header .name { font-weight: 800; color: white; line-height: 1; }
.sidebar-header .sub { font-size: 10px; color: var(--blue-light); letter-spacing: 0.2em; margin-top: 4px; }

.sidebar-nav {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
}
.sidebar-nav .group {
    padding: 12px 20px 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--gray);
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: rgba(255, 255, 255, 0.75);
    font-size: 14px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.sidebar-nav a:hover {
    background: rgba(30, 110, 255, 0.05);
    color: white;
}
.sidebar-nav a.active {
    background: rgba(30, 110, 255, 0.1);
    border-left-color: var(--blue);
    color: white;
}
.sidebar-nav a .icon {
    width: 20px; height: 20px;
    flex-shrink: 0;
    color: var(--blue-light);
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.sidebar-user .avatar {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}
.sidebar-user .info .name { font-weight: 600; font-size: 14px; color: white; line-height: 1.2; }
.sidebar-user .info .role { font-size: 11px; color: var(--gray); margin-top: 3px; }
.logout {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--gray);
    font-size: 13px;
    padding: 8px 0;
}
.logout:hover { color: var(--red); }

/* Main content */
.main {
    flex: 1;
    margin-left: 260px;
    padding: 30px 28px;
    min-height: 100vh;
}

/* Top bar (mobile) */
.topbar {
    display: none;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 14px 18px;
    position: sticky; top: 0;
    z-index: 25;
    align-items: center;
    justify-content: space-between;
}
.topbar .menu-toggle {
    background: transparent;
    border: 1px solid var(--border);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
}
.topbar .topbar-title { font-weight: 700; color: white; }

/* Page header */
.page-header {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 14px;
}
.page-header h1 {
    font-size: 28px;
    color: white;
    line-height: 1.2;
}
.page-header .subtitle {
    color: var(--gray);
    font-size: 14px;
    margin-top: 4px;
}

/* Cards / panels */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
}
.card h2 { font-size: 18px; margin-bottom: 14px; color: white; }

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 30px;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    transition: border-color 0.15s, transform 0.15s;
}
.stat-card:hover { border-color: var(--border-hover); transform: translateY(-2px); }
.stat-card .label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--blue-light);
    margin-bottom: 10px;
}
.stat-card .value {
    font-size: 32px;
    font-weight: 800;
    color: white;
    line-height: 1;
}
.stat-card .change {
    margin-top: 10px;
    font-size: 12px;
    color: var(--gray);
}

/* Tables */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-card);
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
thead {
    background: rgba(30, 110, 255, 0.05);
}
th {
    padding: 14px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--blue-light);
    border-bottom: 1px solid var(--border);
}
td {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(30, 110, 255, 0.04); }

/* Badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.badge-admin { background: rgba(30, 110, 255, 0.15); color: var(--blue-light); }
.badge-comptable { background: rgba(255, 180, 30, 0.12); color: var(--orange); }
.badge-mecano { background: rgba(50, 200, 100, 0.1); color: var(--green); }
.badge-success { background: rgba(50, 200, 100, 0.1); color: var(--green); }
.badge-warning { background: rgba(255, 180, 30, 0.12); color: var(--orange); }
.badge-danger { background: rgba(220, 40, 40, 0.12); color: var(--red); }

/* Forms grid */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

/* Empty states */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray);
}
.empty-state .icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}
.empty-state h3 {
    color: white;
    margin-bottom: 8px;
    font-size: 18px;
}

/* ============================================================
   MOBILE / RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
    }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; padding: 20px 16px; }
    .topbar { display: flex; }

    /* Overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed; inset: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 20;
    }
    .sidebar-overlay.open { display: block; }

    .page-header h1 { font-size: 22px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 500px) {
    .stats-grid { grid-template-columns: 1fr; }
    .card { padding: 18px; }
}

/* iOS safe areas */
@supports (padding: max(0px)) {
    .sidebar { padding-left: max(0px, env(safe-area-inset-left)); }
    .main { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
}
