/* ──────────────────────────────────────────────────────────────────────────── *
 *  Admin Panel — Professional Light Theme
 * ──────────────────────────────────────────────────────────────────────────── */

:root {
    --sidebar-w:      240px;
    --sidebar-bg:     #1e293b;
    --sidebar-border: #2d3f55;
    --sidebar-text:   #94a3b8;
    --sidebar-active: #3b82f6;
    --sidebar-hover:  rgba(59,130,246,.12);
    --top-h:          56px;
    --body-bg:        #f1f5f9;
    --card-bg:        #ffffff;
    --border-color:   #e2e8f0;
    --text:           #1e293b;
    --text-muted:     #64748b;
    --accent:         #3b82f6;
    --success:        #22c55e;
    --danger:         #ef4444;
    --warning:        #f59e0b;
    --radius:         8px;
    --shadow:         0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:      0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: .875rem;
    background: var(--body-bg);
    color: var(--text);
    min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.admin-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #2d3f55 transparent;
}

.sidebar-brand {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: .75rem;
    text-decoration: none;
}

.sidebar-brand-icon {
    width: 32px; height: 32px;
    background: var(--accent);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.sidebar-brand-icon svg { color: #fff; }

.sidebar-brand-text {
    font-size: .78rem;
    font-weight: 600;
    color: #f1f5f9;
    line-height: 1.3;
}

.sidebar-brand-sub {
    font-size: .65rem;
    color: var(--sidebar-text);
    font-weight: 400;
}

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

.nav-group-label {
    padding: .5rem 1.25rem .25rem;
    font-size: .63rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #475569;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .55rem 1.25rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 6px;
    margin: 1px .5rem;
    transition: background .15s, color .15s;
    font-size: .83rem;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: #e2e8f0;
}

.nav-item.active {
    background: rgba(59,130,246,.18);
    color: #93c5fd;
    font-weight: 600;
}

.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .8; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
    padding: .75rem 1.25rem;
    border-top: 1px solid var(--sidebar-border);
    font-size: .75rem;
    color: #475569;
}

/* ── Top bar ─────────────────────────────────────────────────────────────────── */
.admin-topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-w);
    right: 0;
    height: var(--top-h);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    z-index: 99;
    box-shadow: var(--shadow);
}

.topbar-title {
    font-weight: 600;
    font-size: 1rem;
    flex: 1;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: .75rem;
}

/* ── Topbar user dropdown ────────────────────────────────────────────────────── */
.topbar-user-wrap {
    position: relative;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .83rem;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    padding: .25rem .4rem;
    border-radius: 6px;
    transition: background .15s;
}

.topbar-user:hover { background: var(--hover-bg); }

.topbar-chevron {
    font-size: .65rem;
    color: var(--text-muted);
    transition: transform .2s;
}

.topbar-user-wrap.open .topbar-chevron { transform: rotate(180deg); }

.topbar-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: var(--accent);
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: .75rem;
    font-weight: 600;
    flex-shrink: 0;
}

.topbar-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 210px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
    z-index: 9999;
    overflow: hidden;
}

.topbar-user-wrap.open .topbar-dropdown { display: block; }

.topbar-dropdown-header {
    padding: .85rem 1rem .75rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--hover-bg);
}

.td-name {
    font-size: .88rem;
    font-weight: 600;
    color: var(--text-primary);
}

.td-role {
    font-size: .75rem;
    color: var(--text-muted);
    margin-top: .1rem;
}

.topbar-dropdown-body { padding: .4rem 0; }

.td-item {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: .55rem 1rem;
    font-size: .83rem;
    color: var(--text-primary);
    text-decoration: none;
    transition: background .12s;
}

.td-item:hover { background: var(--hover-bg); color: var(--text-primary); text-decoration: none; }
.td-item i { font-size: .85rem; color: var(--text-muted); }
.td-divider { height: 1px; background: var(--border-color); margin: .3rem 0; }
.td-logout { color: #ef4444; }
.td-logout i { color: #ef4444; }
.td-logout:hover { background: rgba(239,68,68,.06); color: #ef4444; }

/* ── Main content ────────────────────────────────────────────────────────────── */
.admin-main {
    margin-left: var(--sidebar-w);
    margin-top: var(--top-h);
    padding: 1.5rem;
    min-height: calc(100vh - var(--top-h));
}

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.admin-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.admin-card-header {
    padding: .9rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}

.admin-card-title {
    font-weight: 600;
    font-size: .9rem;
    margin: 0;
}

.admin-card-body {
    padding: 1.25rem;
}

/* ── Stats cards ─────────────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
    box-shadow: var(--shadow);
}

.stat-card-icon {
    width: 36px; height: 36px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: .25rem;
}

.stat-card-icon svg { width: 20px; height: 20px; }
.stat-card-icon.blue   { background: #dbeafe; color: #2563eb; }
.stat-card-icon.green  { background: #dcfce7; color: #16a34a; }
.stat-card-icon.yellow { background: #fef9c3; color: #ca8a04; }
.stat-card-icon.red    { background: #fee2e2; color: #dc2626; }
.stat-card-icon.purple { background: #f3e8ff; color: #9333ea; }

.stat-card-value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1;
    color: var(--text);
}

.stat-card-label {
    font-size: .75rem;
    color: var(--text-muted);
}

/* ── Tables ─────────────────────────────────────────────────────────────────── */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Fade hint on right edge when table overflows */
    background-image: linear-gradient(to right, var(--card-bg) 0%, transparent 4%),
                      linear-gradient(to left,  var(--card-bg) 0%, transparent 4%);
    background-size: 40px 100%, 40px 100%;
    background-position: left center, right center;
    background-repeat: no-repeat;
    background-attachment: local, local;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .83rem;
}

.admin-table th {
    background: #f8fafc;
    padding: .6rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.admin-table td {
    padding: .7rem 1rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.admin-table tbody tr:last-child td { border-bottom: none; }

.admin-table tbody tr:hover td { background: #f8fafc; }

/* ── Employee avatar ─────────────────────────────────────────────────────────── */
.emp-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.emp-avatar--initials {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #dbeafe;
    color: #2563eb;
    font-size: .78rem;
    font-weight: 700;
}

.emp-row {
    display: flex;
    align-items: center;
    gap: .6rem;
}

.emp-row-name   { font-weight: 500; color: var(--text); }
.emp-row-number { font-size: .73rem; color: var(--text-muted); }

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-section {
    margin-bottom: 1.5rem;
}

.form-section-title {
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    padding-bottom: .5rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}

.form-grid-full { grid-column: 1 / -1; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn-icon {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
}

.btn-icon svg { width: 15px; height: 15px; }

/* ── Export button group ──────────────────────────────────────────────────────── */
.export-btns {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.btn-export {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 7px;
    font-size: .7rem;
    font-weight: 500;
    line-height: 1.6;
    border-radius: 4px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: opacity .15s, background .15s;
    opacity: .82;
}
.btn-export:hover { opacity: 1; text-decoration: none; }
.btn-export i { font-size: .72rem; }

.btn-export-xl  { color: #fff; background: #217346; border-color: #1a5c38; }
.btn-export-xl:hover  { color: #fff; background: #1a5c38; }

.btn-export-pdf { color: #fff; background: #c0392b; border-color: #a93226; }
.btn-export-pdf:hover { color: #fff; background: #a93226; }

.btn-export-csv { color: #374151; background: #f1f5f9; border-color: #cbd5e1; }
.btn-export-csv:hover { color: #111; background: #e2e8f0; }

/* ── Search bar ─────────────────────────────────────────────────────────────── */
.search-bar {
    display: flex;
    gap: .5rem;
    align-items: center;
    flex-wrap: wrap;
}

.search-bar input[type=text],
.search-bar select {
    min-width: 180px;
}

/* ── Badges ──────────────────────────────────────────────────────────────────── */
.badge { font-size: .68rem; padding: .2rem .5rem; border-radius: 4px; font-weight: 600; }

/* ── Empty state ─────────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state svg {
    width: 48px; height: 48px;
    margin-bottom: .75rem;
    opacity: .4;
}

/* ── Pagination ──────────────────────────────────────────────────────────────── */
.pagination-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .75rem 1.25rem;
    border-top: 1px solid var(--border-color);
    font-size: .8rem;
    color: var(--text-muted);
}

/* ── Login page ──────────────────────────────────────────────────────────────── */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}

.login-card {
    background: #fff;
    border-radius: 12px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.login-brand {
    text-align: center;
    margin-bottom: 2rem;
}

.login-brand-icon {
    width: 56px; height: 56px;
    background: var(--accent);
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: .75rem;
}

.login-brand-icon svg { width: 32px; height: 32px; color: #fff; }

.login-brand h1 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0 0 .2rem;
    color: var(--text);
}

.login-brand p {
    font-size: .8rem;
    color: var(--text-muted);
    margin: 0;
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */

/* Sidebar overlay backdrop (CSS :has — widely supported 2024+) */
@media (max-width: 768px) {
    body:has(.admin-sidebar.open)::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.45);
        z-index: 98;
        backdrop-filter: blur(1px);
    }
}

/* --- Tablet / large phone (\u2264 768px) --- */
@media (max-width: 768px) {
    .admin-sidebar {
        transform: translateX(-100%);
        transition: transform .28s cubic-bezier(.4,0,.2,1);
        z-index: 200;           /* above backdrop */
    }
    .admin-sidebar.open { transform: translateX(0); }

    .admin-main   { margin-left: 0; padding: 1rem; }
    .admin-topbar { left: 0; padding: 0 1rem; }
    .topbar-title { font-size: .9rem; }

    /* Stats grid: 2 columns on tablet */
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: .75rem; }

    /* Full-width search bars */
    .search-bar { flex-direction: column; align-items: stretch; }
    .search-bar input[type=text],
    .search-bar select,
    .search-bar .btn { width: 100%; min-width: 0; }

    /* Page header stacks on tablet */
    .page-header { flex-direction: column; gap: .5rem; align-items: flex-start; }
    .page-header .btn  { align-self: flex-start; }

    /* Pagination stacks */
    .pagination-wrap { flex-direction: column; gap: .5rem; text-align: center; }

    /* Tighten card body padding */
    .admin-card-body { padding: 1rem; }
    .admin-card-header { padding: .75rem 1rem; }
}

/* --- Phone portrait (\u2264 576px) --- */
@media (max-width: 576px) {
    .admin-main { padding: .75rem; }

    /* Stats grid: 2 columns, compact */
    .stats-grid { gap: .5rem; }
    .stat-card  { padding: .875rem 1rem; }
    .stat-card-value { font-size: 1.35rem; }

    /* Form grid: always 1 column */
    .form-grid { grid-template-columns: 1fr; }

    /* Tighter form sections */
    .form-section      { margin-bottom: 1rem; }
    .admin-card-body   { padding: .875rem; }

    /* Table: make cells smaller */
    .admin-table th,
    .admin-table td { padding: .5rem .75rem; font-size: .78rem; }

    /* Login card */
    .login-card { padding: 1.75rem 1.25rem; }

    /* Topbar: hide user name text, keep avatar */
    .topbar-user span { display: none; }

    /* Page header title smaller */

}

/* --- Very small phones (\u2264 400px) --- */
@media (max-width: 400px) {
    .admin-main { padding: .5rem; }

    /* Stats: 1 column on tiny screens if 2 cols don't fit */
    .stats-grid { grid-template-columns: 1fr; }

    /* Topbar: minimal */
    .admin-topbar { padding: 0 .625rem; gap: .5rem; }
    .topbar-title { font-size: .82rem; }

    .admin-card-body    { padding: .75rem; }
    .admin-card-header  { padding: .6rem .75rem; }

    /* Tables: allow very narrow cells */
    .admin-table th,
    .admin-table td { padding: .45rem .5rem; font-size: .75rem; }

    /* Buttons: slim on tiny screens */
    .btn-sm { padding: .25rem .5rem; font-size: .75rem; }
}

/* --- Landscape phones (short viewport) --- */
@media (max-height: 500px) and (max-width: 900px) {
    .admin-topbar { height: 44px; }
    .admin-main   { margin-top: 44px; }
    :root         { --top-h: 44px; }
}

/* --- Larger than sidebar breakpoint, ensure sidebar always visible --- */
@media (min-width: 769px) {
    .admin-sidebar { transform: none !important; transition: none; }
}

/* ── Page header breadcrumb ──────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.page-header-sub   { font-size: .8rem; color: var(--text-muted); margin: 0; }

/* ── Timeline (employee view) ────────────────────────────────────────────────── */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline-item {
    display: flex;
    gap: .75rem;
    padding: .6rem 0;
    border-bottom: 1px solid var(--border-color);
    align-items: flex-start;
}
.timeline-item:last-child { border-bottom: none; }
.timeline-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 4px;
}
.timeline-dot.in  { background: var(--success); }
.timeline-dot.out { background: var(--accent); }
.timeline-text    { font-size: .83rem; line-height: 1.4; }
.timeline-time    { font-size: .75rem; color: var(--text-muted); margin-top: .1rem; }
