:root {
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-active: #3b82f6;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #0891b2;
    --bg: #f1f5f9;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.08);
}

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

html { font-size: 15px; }

body {
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    min-height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    flex-shrink: 0;
}

.sidebar-brand {
    padding: 20px 20px;
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,.06);
}

.brand-dot {
    width: 14px; height: 14px;
    border-radius: 50%;
    background: var(--primary);
    display: inline-block;
}

.sidebar-nav { padding: 16px 0; flex: 1; }

.nav-section {
    display: block;
    padding: 12px 20px 4px;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .08em;
    color: #475569;
    text-transform: uppercase;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--sidebar-text);
    padding: 9px 20px;
    text-decoration: none;
    font-size: .92rem;
    border-left: 3px solid transparent;
    transition: all .15s;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,.05); text-decoration: none; }
.nav-link.active { color: #fff; background: rgba(59,130,246,.15); border-left-color: var(--sidebar-active); }

.nav-icon { width: 20px; text-align: center; font-size: 1rem; }

.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,.06); }
.user-card { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.user-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .9rem;
    text-transform: uppercase;
    flex-shrink: 0;
}
.user-info { overflow: hidden; }
.user-name { color: #fff; font-weight: 600; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-company { color: var(--sidebar-accent, #6ea8fe); font-size: .78rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: var(--sidebar-text); font-size: .75rem; }

.main-content { flex: 1; min-width: 0; padding: 28px 32px; }
.page-body { max-width: 1200px; margin: 0 auto; }

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; gap: 16px; flex-wrap: wrap; }
.page-header h1 { font-size: 1.6rem; font-weight: 700; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all .15s;
    line-height: 1.4;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-outline-light { background: transparent; color: var(--sidebar-text); border-color: rgba(255,255,255,.2); }
.btn-outline-light:hover { color: #fff; border-color: #fff; }
.btn-icon { padding: 4px 10px; font-size: 1rem; }
.btn-sm { padding: 4px 10px; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ---------- Cards ---------- */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    overflow: hidden;
}
.card-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 1.05rem; font-weight: 700; }
.card-empty { padding: 32px; text-align: center; color: var(--text-muted); }

/* ---------- Stats ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 18px; cursor: pointer; transition: all .15s;
    border-top: 3px solid var(--primary);
}
.stat-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); transform: translateY(-2px); }
.stat-warning { border-top-color: var(--warning); }
.stat-success { border-top-color: var(--success); }
.stat-info { border-top-color: var(--info); }
.stat-value { font-size: 1.8rem; font-weight: 800; }
.stat-label { color: var(--text-muted); font-size: .85rem; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table th {
    text-align: left; padding: 10px 12px;
    font-size: .75rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-muted); border-bottom: 2px solid var(--border);
    background: #f8fafc;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: .9rem; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f8fafc; }
.clickable { cursor: pointer; }
.text-right { text-align: right !important; }
.cell-muted { color: var(--text-muted); font-size: .85rem; }

/* ---------- Badges ---------- */
.badge {
    display: inline-block; padding: 3px 10px; border-radius: 999px;
    font-size: .75rem; font-weight: 600; white-space: nowrap;
}
.badge-secondary { background: #e2e8f0; color: #475569; }
.badge-warning { background: #fef3c7; color: #a16207; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-info { background: #cffafe; color: #155e75; }
.badge-purple { background: #f3e8ff; color: #7e22ce; }
.badge-dark { background: #334155; color: #e2e8f0; }
.badge-danger { background: #fee2e2; color: #991b1b; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 14px; display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: .8rem; font-weight: 600; color: var(--text-muted); }
.form-control, .form-control-sm {
    padding: 8px 12px; border: 1px solid var(--border);
    border-radius: var(--radius); font-size: .9rem; font-family: inherit;
    background: #fff; color: var(--text); width: 100%;
}
.form-control:focus, .form-control-sm:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-control-sm { padding: 6px 10px; font-size: .85rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; padding: 20px; }
.form-grid .form-group { margin-bottom: 0; }

input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: .9rem; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }

/* ---------- Login ---------- */
.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
    padding: 20px;
}
.login-card {
    background: #fff; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
    padding: 36px 32px; width: 100%; max-width: 400px;
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand .brand-dot { width: 42px; height: 42px; margin-bottom: 12px; }
.login-brand h1 { font-size: 1.5rem; font-weight: 800; color: var(--text); }
.login-brand p { color: var(--text-muted); font-size: .85rem; }

.password-wrapper { position: relative; }
.password-wrapper .form-control { padding-right: 42px; }
.password-toggle {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    background: none; border: none; cursor: pointer; color: var(--text-muted);
    padding: 4px; display: flex; align-items: center; justify-content: center;
}
.password-toggle:hover { color: var(--primary); }

/* ---------- Loading ---------- */
.loading { display: flex; justify-content: center; padding: 60px; }
.spinner {
    width: 36px; height: 36px; border-radius: 50%;
    border: 3px solid var(--border); border-top-color: var(--primary);
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Filter bar ---------- */
.filters-bar { display: flex; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.filters-bar select, .filters-bar input { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: .9rem; }

/* ---------- Totals ---------- */
.totals-box { padding: 16px 20px; }
.totals-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: .9rem; }
.totals-grand { border-top: 2px solid var(--border); margin-top: 6px; padding-top: 10px; font-size: 1.1rem; font-weight: 800; color: var(--primary); }

/* ---------- Detail ---------- */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }
.detail-fields { padding: 16px 20px; display: flex; flex-direction: column; gap: 10px; }
.detail-fields .label { display: inline-block; min-width: 130px; color: var(--text-muted); font-size: .8rem; font-weight: 600; }

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(15,23,42,.5);
    display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-card {
    background: #fff; border-radius: 12px; padding: 24px; width: 100%; max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-card h3 { margin-bottom: 16px; }
.modal-wide { max-width: 720px; max-height: 90vh; overflow-y: auto; }
.action-bar { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; padding: 0 20px 20px; }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 16px; }

/* ---------- CTA ---------- */
.cta-bar { display: flex; justify-content: flex-end; margin-top: 8px; }

/* ---------- Company profile ---------- */
.company-brand { display: flex; align-items: center; gap: 16px; padding: 16px 20px; margin-bottom: 20px; }
.company-brand .logo-preview { width: 72px; height: 72px; }
.company-brand-info { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.company-brand-name { font-size: 1.15rem; font-weight: 700; }
.logo-row { display: flex; align-items: center; gap: 20px; padding: 20px; flex-wrap: wrap; }
.logo-preview {
    width: 112px; height: 112px; border: 1px dashed var(--border); border-radius: 12px;
    display: flex; align-items: center; justify-content: center; overflow: hidden;
    background: #f8fafc;
}
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-placeholder { color: var(--text-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.logo-upload { display: flex; flex-direction: column; gap: 6px; }
.form-hint { font-size: .78rem; color: var(--text-muted); }
.form-section-title {
    grid-column: 1 / -1; font-size: .75rem; font-weight: 700; letter-spacing: .06em;
    text-transform: uppercase; color: var(--text-muted); border-bottom: 1px solid var(--border);
    padding-bottom: 6px; margin-bottom: 4px; margin-top: 8px;
}
.inline-form { display: inline-block; margin-left: 12px; }
.alert-info { background: #e0f2fe; color: #0c4a6e; border: 1px solid #bae6fd; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.tab {
    padding: 10px 16px; border: none; background: transparent; cursor: pointer;
    font-size: .9rem; font-weight: 600; color: var(--text-muted);
    border-bottom: 2px solid transparent; margin-bottom: -1px; font-family: inherit;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-actions { display: flex; gap: 8px; align-items: center; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- Misc ---------- */
.access-denied { padding: 60px; text-align: center; }
.access-denied h2 { margin-bottom: 8px; }
.empty-state { padding: 48px; text-align: center; color: var(--text-muted); }

@media (max-width: 768px) {
    .sidebar { width: 72px; }
    .sidebar-brand span:not(.brand-dot), .nav-link span:last-child, .nav-section,
    .user-card .user-info, .sidebar-footer .btn { display: none; }
    .nav-link { justify-content: center; padding: 12px; }
    .main-content { padding: 16px; }
}