:root {
  --sidebar-width: 280px;
  --brand: #2563eb;
  --accent: #10b981;
  --ink: #0f172a;
  --muted: #64748b;
  --surface: #ffffff;
  --line: #e2e8f0;
  --bg: #f4f7fb;
  --sidebar-bg: #0f172a;
  --sidebar-bg-soft: #172554;
  --sidebar-text: #dbeafe;
  --sidebar-muted: #93a4bd;
  --card-shadow: 0 14px 34px rgba(15, 23, 42, .08);
  --soft-blue: #eff6ff;
  --soft-teal: #ecfdf5;
  --soft-amber: #fffbeb;
  --soft-rose: #fff1f2;
}

[data-bs-theme="dark"] {
  --ink: #e5e7eb;
  --muted: #94a3b8;
  --surface: #111827;
  --line: #243044;
  --bg: #0b1020;
  --sidebar-bg: #050816;
  --sidebar-bg-soft: #111827;
  --sidebar-text: #e5e7eb;
  --sidebar-muted: #9ca3af;
  --card-shadow: 0 14px 34px rgba(0, 0, 0, .24);
  --soft-blue: #10213f;
  --soft-teal: #0b2f2a;
  --soft-amber: #322410;
  --soft-rose: #35151d;
}

body { background: var(--bg); color: var(--ink); font-size: 14px; }
.app-shell { min-height: 100vh; display: flex; }
.sidebar { width: var(--sidebar-width); background: radial-gradient(circle at 20% 0%, rgba(16, 185, 129, .22), transparent 34%), linear-gradient(180deg, var(--sidebar-bg), var(--sidebar-bg-soft)); border-right: 1px solid rgba(255,255,255,.08); padding: 18px; position: fixed; inset: 0 auto 0 0; z-index: 1040; overflow-y: auto; box-shadow: 16px 0 40px rgba(15,23,42,.12); }
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark { width: 42px; height: 42px; border-radius: 8px; display: grid; place-items: center; color: #fff; font-weight: 800; background: linear-gradient(135deg, #38bdf8, #10b981); box-shadow: 0 10px 24px rgba(16,185,129,.26); }
.brand-logo { width: 46px; height: 46px; object-fit: contain; border-radius: 8px; border: 1px solid rgba(255,255,255,.22); background: #fff; padding: 4px; box-shadow: 0 10px 24px rgba(0,0,0,.18); }
.brand strong { display: block; line-height: 1.2; }
.sidebar .brand strong { color: #fff; }
.brand small, .user-chip small { display: block; color: var(--muted); font-size: 11px; }
.sidebar .brand small { color: var(--sidebar-muted); }
.sidebar-nav { margin-top: 22px; gap: 4px; }
.nav-label { color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: .08em; margin: 16px 10px 6px; }
.sidebar .nav-label { color: #93c5fd; opacity: .82; }
.sidebar .nav-link { color: var(--sidebar-text); border-radius: 8px; display: flex; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid transparent; }
.sidebar .nav-button { width: 100%; background: transparent; text-align: left; appearance: none; }
.sidebar .nav-link i { color: #a7f3d0; }
.sidebar .nav-link.active, .sidebar .nav-link:hover { color: #fff; background: linear-gradient(135deg, rgba(37,99,235,.92), rgba(13,148,136,.92)); border-color: rgba(255,255,255,.14); box-shadow: 0 10px 24px rgba(2,6,23,.22); }
.sidebar .nav-link.active i, .sidebar .nav-link:hover i { color: #fff; }
.sidebar .nav-link.disabled { opacity: .5; }
.sidebar .nav-sub { margin-left: 18px; padding: 8px 10px; font-size: 13px; }
.nav-badge { margin-left: auto; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; display: inline-grid; place-items: center; background: #dc2626; color: #fff; font-size: 11px; font-weight: 700; }
.main { margin-left: var(--sidebar-width); width: calc(100% - var(--sidebar-width)); min-height: 100vh; }
.topbar { min-height: 76px; background: rgba(255,255,255,.92); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); padding: 14px 22px; display: flex; justify-content: space-between; align-items: center; gap: 16px; position: sticky; top: 0; z-index: 1000; }
[data-bs-theme="dark"] .topbar { background: rgba(17,24,39,.9); }
body.pwa-standalone .topbar { padding-top: calc(14px + env(safe-area-inset-top)); }
.topbar h1 { font-size: 22px; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.btn-icon { width: 40px; height: 40px; display: inline-grid; place-items: center; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.user-chip { border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-align: left; border-radius: 8px; display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: center; }
.user-chip-avatar { width: 34px; height: 34px; object-fit: cover; border-radius: 50%; border: 1px solid var(--line); grid-row: span 2; }
.content { padding: 22px; }
.panel, .stat-card { background: linear-gradient(180deg, rgba(255,255,255,.98), var(--surface)); border: 1px solid rgba(148,163,184,.28); border-radius: 8px; box-shadow: var(--card-shadow); }
[data-bs-theme="dark"] .panel, [data-bs-theme="dark"] .stat-card { background: linear-gradient(180deg, rgba(30,41,59,.92), var(--surface)); }
.panel { padding: 18px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.panel-header h2 { font-size: 17px; margin: 0; position: relative; padding-left: 10px; }
.panel-header h2::before { content: ""; position: absolute; left: 0; top: 3px; bottom: 3px; width: 4px; border-radius: 999px; background: linear-gradient(180deg, var(--brand), var(--accent)); }
.stat-card { padding: 18px; display: flex; align-items: center; gap: 14px; }
.stat-card i { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 8px; color: #fff; background: linear-gradient(135deg, #2563eb, #38bdf8); font-size: 22px; box-shadow: 0 10px 20px rgba(37,99,235,.18); }
.stat-card { transition: transform .16s ease, box-shadow .16s ease; }
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 18px 42px rgba(15,23,42,.12); }
.row > [class*="col-"]:nth-child(2n) .stat-card i { background: linear-gradient(135deg, #0f766e, #14b8a6); }
.row > [class*="col-"]:nth-child(3n) .stat-card i { background: linear-gradient(135deg, #7c3aed, #ec4899); }
.row > [class*="col-"]:nth-child(4n) .stat-card i { background: linear-gradient(135deg, #d97706, #f97316); }
.stat-card span { color: var(--muted); display: block; }
.stat-card strong { font-size: 26px; }
.welcome-card { background: linear-gradient(135deg, #1d4ed8, #0f766e 55%, #16a34a); color: #fff; border-radius: 8px; padding: 18px; display: flex; align-items: center; justify-content: space-between; gap: 14px; box-shadow: 0 18px 44px rgba(15,23,42,.18); }
.welcome-card span { display: block; opacity: .92; }
.welcome-card strong { display: block; font-size: 22px; margin-top: 4px; }
.welcome-card i { font-size: 30px; opacity: .88; }
.activity-list { display: grid; gap: 10px; }
.activity-item { border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.activity-item span, .activity-item small { display: block; color: var(--muted); }
.app-footer { margin-top: 24px; padding: 12px 0 2px; color: var(--muted); font-size: 12px; text-align: center; }
.login-footer { margin-top: 18px; padding-top: 14px; border-top: 1px solid #e5e7eb; }
.login-page { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(180deg, #0f172a 0 48%, #eef2f7 48% 100%); }
.login-card { width: min(420px, calc(100vw - 32px)); background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 26px; box-shadow: 0 24px 80px rgba(15,23,42,.22); }
.login-page .brand { padding-bottom: 14px; border-bottom: 1px solid #e5e7eb; }
.dt-buttons { display: none !important; }
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
table.dataTable td, table.dataTable th { vertical-align: middle; }
.table-photo { width: 42px; height: 42px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.wa-link { color: #15803d; font-weight: 600; text-decoration: none; white-space: nowrap; }
.wa-link:hover { color: #166534; text-decoration: underline; }
.notif-dot { position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; border-radius: 999px; display: inline-grid; place-items: center; padding: 0 5px; background: #dc2626; color: #fff; font-size: 11px; font-weight: 700; border: 2px solid var(--surface); }
.chat-contact-list { display: grid; gap: 8px; }
.chat-contact { width: 100%; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px; padding: 10px; display: flex; justify-content: space-between; gap: 10px; text-align: left; }
.chat-contact small { display: block; color: var(--muted); }
.chat-contact em { min-width: 22px; height: 22px; border-radius: 999px; background: #dc2626; color: #fff; font-style: normal; display: inline-grid; place-items: center; font-size: 11px; }
.chat-contact.active, .chat-contact:hover { border-color: var(--brand); background: rgba(37, 99, 235, .08); }
.chat-panel { min-height: 560px; display: flex; flex-direction: column; }
.chat-messages { flex: 1; min-height: 380px; max-height: 560px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 6px; }
.chat-bubble { max-width: min(76%, 620px); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--surface); }
.chat-bubble.mine { align-self: flex-end; background: #2563eb; color: #fff; border-color: #2563eb; }
.chat-bubble.theirs { align-self: flex-start; }
.chat-bubble small { display: block; margin-top: 6px; font-size: 11px; color: inherit; opacity: .75; }
.chat-reply { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px; }
.detail-row { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; min-height: 44px; background: var(--surface); }
.detail-row strong { display: block; color: var(--muted); font-size: 12px; margin-bottom: 3px; }
.detail-row span { word-break: break-word; }
.profile-detail { display: grid; gap: 14px; }
.profile-head { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: #f8fafc; }
.profile-head img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.profile-head h3 { margin: 0 0 4px; font-size: 20px; }
.profile-head p { margin: 0; color: var(--muted); }
.plain-detail { display: grid; gap: 6px 18px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.plain-detail-row { display: grid; grid-template-columns: minmax(150px, 190px) 12px 1fr; gap: 6px; align-items: start; }
.plain-detail-row strong { color: var(--muted); font-weight: 600; }
.plain-detail-row b { font-weight: 700; text-align: center; }
.plain-detail-row span { word-break: break-word; }
.ajax-result-list { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); max-height: 240px; overflow-y: auto; }
.ajax-result-list:empty { display: none; }
.ajax-result-item { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--ink); padding: 9px 10px; text-align: left; }
.ajax-result-item:last-child { border-bottom: 0; }
.ajax-result-item:hover { background: rgba(37, 99, 235, .08); }
.selected-chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.selected-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 5px 8px; background: #f8fafc; font-size: 12px; }
.selected-chip button { border: 0; background: transparent; color: #dc2626; font-weight: 700; line-height: 1; }
.sidebar-backdrop, .mobile-bottom-nav, .mobile-menu-backdrop, .mobile-menu-sheet, .mobile-quick-actions, .mobile-only-notice { display: none; }
@media (max-width: 767px) { .detail-grid { grid-template-columns: 1fr; } }
@media (max-width: 767px) { .plain-detail { grid-template-columns: 1fr; } .plain-detail-row { grid-template-columns: minmax(120px, 42%) 12px 1fr; } }
.mobile-technical { }
.table thead th, table.dataTable thead th {
  background: #eef2f7 !important;
  color: #334155;
  font-weight: 700;
}
.dt-buttons .btn,
.table-actions .btn,
.dataTables_wrapper .btn,
.dt-button.btn {
  --bs-btn-padding-y: .2rem;
  --bs-btn-padding-x: .45rem;
  --bs-btn-font-size: .78rem;
  border-radius: 6px;
}
.btn-sm {
  --bs-btn-padding-y: .2rem;
  --bs-btn-padding-x: .45rem;
  --bs-btn-font-size: .78rem;
}

@media (max-width: 991px) {
  body { -webkit-tap-highlight-color: transparent; }
  body.sidebar-open, body.mobile-menu-open { overflow: hidden; }
  .sidebar {
    width: min(86vw, 320px);
    transform: translateX(-105%);
    transition: transform .24s cubic-bezier(.2,.8,.2,1);
    border-radius: 0 18px 18px 0;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
  .sidebar.show { transform: translateX(0); }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .46);
    z-index: 1035;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
    backdrop-filter: blur(2px);
  }
  body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .main { margin-left: 0; width: 100%; }
  .topbar {
    align-items: flex-start;
    border-bottom: 0;
    box-shadow: 0 10px 28px rgba(15,23,42,.08);
  }
  .topbar-actions { margin-left: auto; }
  .content { padding-bottom: calc(94px + env(safe-area-inset-bottom)); }
  .mobile-quick-actions {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
  }
  .mobile-quick-actions a {
    min-width: 0;
    min-height: 68px;
    border: 1px solid rgba(148,163,184,.28);
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(255,255,255,.98), rgba(248,250,252,.96));
    color: var(--ink);
    box-shadow: 0 10px 24px rgba(15,23,42,.08);
    text-decoration: none;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 5px;
    padding: 8px 4px;
    text-align: center;
    font-size: 10px;
    line-height: 1.08;
    font-weight: 800;
  }
  .mobile-quick-actions a i {
    width: 31px;
    height: 31px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: linear-gradient(135deg, #2563eb, #0f766e);
    color: #fff;
    font-size: 16px;
  }
  .mobile-quick-actions a.active {
    color: #fff;
    border-color: transparent;
    background: linear-gradient(135deg, #2563eb, #0f766e);
  }
  .mobile-quick-actions a.active i {
    background: rgba(255,255,255,.2);
  }
  [data-bs-theme="dark"] .mobile-quick-actions a {
    background: linear-gradient(180deg, rgba(30,41,59,.96), rgba(15,23,42,.96));
  }
  .app-footer { margin-bottom: 10px; }
  .mobile-bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 1025;
    min-height: 64px;
    padding: 7px;
    border: 1px solid rgba(148,163,184,.34);
    border-radius: 18px;
    background: rgba(255,255,255,.94);
    box-shadow: 0 18px 44px rgba(15,23,42,.18);
    backdrop-filter: blur(16px);
  }
  [data-bs-theme="dark"] .mobile-bottom-nav { background: rgba(17,24,39,.94); }
  .mobile-bottom-nav a,
  .mobile-bottom-nav button {
    position: relative;
    border: 0;
    border-radius: 14px;
    background: transparent;
    color: var(--muted);
    display: grid;
    place-items: center;
    align-content: center;
    gap: 2px;
    min-width: 0;
    padding: 5px 2px;
    text-decoration: none;
    font-size: 10px;
    line-height: 1.05;
    font-weight: 700;
  }
  .mobile-bottom-nav i { font-size: 20px; line-height: 1; }
  .mobile-bottom-nav a.active,
  .mobile-bottom-nav button:active {
    color: #fff;
    background: linear-gradient(135deg, #2563eb, #0f766e);
    box-shadow: 0 8px 18px rgba(37,99,235,.22);
  }
  .mobile-bottom-nav em {
    position: absolute;
    top: 3px;
    right: 10px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border-radius: 999px;
    display: inline-grid;
    place-items: center;
    background: #dc2626;
    color: #fff;
    font-style: normal;
    font-size: 10px;
    border: 2px solid #fff;
  }
  .mobile-menu-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.5);
    z-index: 1040;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
    backdrop-filter: blur(2px);
  }
  body.mobile-menu-open .mobile-menu-backdrop { opacity: 1; pointer-events: auto; }
  .mobile-menu-sheet {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1045;
    max-height: min(78vh, 680px);
    padding: 10px 14px calc(18px + env(safe-area-inset-bottom));
    border-radius: 22px 22px 0 0;
    background: rgba(255,255,255,.98);
    border: 1px solid rgba(148,163,184,.32);
    box-shadow: 0 -20px 52px rgba(15,23,42,.2);
    transform: translateY(105%);
    transition: transform .24s cubic-bezier(.2,.8,.2,1);
  }
  [data-bs-theme="dark"] .mobile-menu-sheet { background: rgba(17,24,39,.98); }
  body.mobile-menu-open .mobile-menu-sheet { transform: translateY(0); }
  .mobile-menu-handle {
    width: 44px;
    height: 5px;
    border-radius: 999px;
    background: #cbd5e1;
    margin: 0 auto 12px;
  }
  .mobile-menu-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
  }
  .mobile-menu-head strong { display: block; font-size: 17px; }
  .mobile-menu-head span { display: block; color: var(--muted); font-size: 12px; }
  .mobile-menu-grid {
    max-height: calc(min(78vh, 680px) - 92px);
    overflow-y: auto;
    padding-bottom: 6px;
  }
  .mobile-menu-section {
    display: grid;
    gap: 9px;
    padding: 10px 0 14px;
    border-bottom: 1px solid rgba(148,163,184,.22);
  }
  .mobile-menu-section:last-child { border-bottom: 0; }
  .mobile-menu-section h3 {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: .04em;
    text-transform: uppercase;
  }
  .mobile-menu-section-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
  }
  .mobile-menu-section-grid a {
    min-width: 0;
    min-height: 78px;
    border: 1px solid rgba(148,163,184,.28);
    border-radius: 16px;
    background: linear-gradient(180deg, rgba(248,250,252,.98), rgba(241,245,249,.96));
    color: var(--ink);
    display: grid;
    place-items: center;
    align-content: center;
    gap: 7px;
    padding: 8px 5px;
    text-align: center;
    text-decoration: none;
    font-size: 10px;
    line-height: 1.08;
    font-weight: 800;
  }
  .mobile-menu-section-grid a i {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: linear-gradient(135deg, #2563eb, #14b8a6);
    color: #fff;
    font-size: 17px;
  }
  .mobile-menu-section-grid a.active {
    color: #fff;
    background: linear-gradient(135deg, #2563eb, #0f766e);
    border-color: transparent;
  }
  .mobile-menu-section-grid a.active i { background: rgba(255,255,255,.2); }
  [data-bs-theme="dark"] .mobile-menu-section-grid a {
    background: linear-gradient(180deg, rgba(30,41,59,.96), rgba(15,23,42,.96));
  }
}

@media (max-width: 575px) {
  .content { padding: 12px 12px calc(96px + env(safe-area-inset-bottom)); }
  .topbar {
    min-height: 64px;
    flex-wrap: nowrap;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
    gap: 10px;
  }
  .topbar h1 { font-size: 18px; }
  .breadcrumb { display: none; }
  .topbar-actions { gap: 6px; }
  .btn-icon { width: 38px; height: 38px; border-radius: 12px; }
  .topbar .user-chip {
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: 14px;
    display: grid;
    place-items: center;
  }
  .topbar .user-chip span,
  .topbar .user-chip small { display: none; }
  .topbar .user-chip-avatar { width: 32px; height: 32px; grid-row: auto; }
  .topbar .user-chip::after { display: none; }
  .panel { padding: 14px; }
  .panel-header { align-items: flex-start; flex-direction: column; }
  .table-actions { width: 100%; justify-content: flex-start; }
  .table-actions .btn { flex: 1 1 auto; }
  .stat-card { padding: 14px; }
  .stat-card i { width: 42px; height: 42px; }
  .stat-card strong { font-size: 22px; }
  .welcome-card { padding: 16px; align-items: flex-start; }
  .welcome-card strong { font-size: 19px; }
  .modal-dialog { margin: 10px; }
  .dataTables_wrapper .row { row-gap: 8px; }
}

@media (max-width: 767px) {
  .mobile-technical { display: none !important; }
  .mobile-only-notice {
    display: block;
    border: 1px solid rgba(37, 99, 235, .22);
    border-radius: 8px;
    background: #eff6ff;
    color: #1e3a8a;
    padding: 12px 14px;
    margin-bottom: 12px;
    font-size: 13px;
  }
  [data-bs-theme="dark"] .mobile-only-notice {
    background: #10213f;
    color: #bfdbfe;
    border-color: rgba(147, 197, 253, .22);
  }
}
