:root {
  --ink: #172033;
  --muted: #667085;
  --line: #d8dee8;
  --soft-line: #eef2f6;
  --bg: #f3f5f8;
  --panel: #ffffff;
  --nav: #0f2235;
  --nav-2: #17324d;
  --blue: #0b5f9e;
  --blue-2: #074a7d;
  --cyan: #0aa1b7;
  --red: #c83242;
  --green: #13845a;
  --amber: #a86500;
}
* { box-sizing: border-box; }
html { min-height: 100%; }
body { margin: 0; min-height: 100%; font-family: "Segoe UI", Arial, sans-serif; color: var(--ink); background: var(--bg); font-size: 14px; }
a { color: inherit; text-decoration: none; }
h3 { margin: 0 0 14px; font-size: 17px; }
p { line-height: 1.55; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 28px; background: #eef4f8; }
.login-card { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 30px; box-shadow: 0 22px 60px rgba(23, 32, 51, .14); }
.brand { display: flex; align-items: center; gap: 13px; margin-bottom: 20px; }
.brand img { width: 58px; height: 58px; object-fit: cover; border-radius: 50%; border: 1px solid rgba(255,255,255,.18); }
.brand h1 { margin: 0; font-size: 21px; line-height: 1.1; }
.brand span { display: block; color: var(--muted); font-size: 13px; margin-top: 4px; }
label { display: block; font-size: 12px; font-weight: 700; margin: 12px 0 6px; color: #344054; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 10px 11px; font: inherit; background: #fff; color: var(--ink); transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(11, 95, 158, .12); }
textarea { min-height: 92px; resize: vertical; }
button, .btn { border: 0; border-radius: 6px; padding: 10px 13px; background: var(--blue); color: #fff; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px; }
button:hover, .btn:hover { background: var(--blue-2); }
.btn.secondary, button.secondary { background: #e8edf3; color: var(--ink); }
.btn.secondary:hover, button.secondary:hover { background: #dfe6ef; }
.btn.danger, button.danger { background: var(--red); }
.hint { color: var(--muted); font-size: 13px; line-height: 1.45; }
.app { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar { background: linear-gradient(180deg, var(--nav), var(--nav-2)); color: #eaf3fb; padding: 18px 14px; position: sticky; top: 0; height: 100vh; overflow: auto; border-right: 1px solid rgba(255,255,255,.08); }
.sidebar .brand { padding: 4px 6px 16px; margin-bottom: 8px; border-bottom: 1px solid rgba(255,255,255,.11); }
.sidebar .brand img { width: 48px; height: 48px; }
.sidebar .brand h1 { font-size: 16px; letter-spacing: .02em; }
.sidebar .brand span { color: #b7cce0; }
.nav { display: grid; gap: 5px; margin-top: 10px; }
.nav a { padding: 10px 11px; border-radius: 6px; color: #dceaf6; display: grid; grid-template-columns: 30px 1fr; align-items: center; gap: 9px; }
.nav a i { width: 28px; height: 28px; border-radius: 6px; display: grid; place-items: center; background: rgba(255,255,255,.08); color: #cde1f4; font-style: normal; font-size: 10px; font-weight: 800; }
.nav a.active, .nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav a.active i, .nav a:hover i { background: var(--cyan); color: #fff; }
.main { min-width: 0; }
.topbar { display: flex; justify-content: space-between; gap: 16px; align-items: center; padding: 15px 24px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; backdrop-filter: blur(8px); }
.topbar h2 { margin: 0; font-size: 21px; }
.content { padding: 22px 24px 34px; display: grid; gap: 18px; }
.banner { width: 100%; height: 78px; object-fit: contain; background: #fff; border-bottom: 1px solid var(--line); padding: 8px 18px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.panel, .card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 17px; box-shadow: 0 1px 2px rgba(16, 24, 40, .04); }
.metric { min-height: 116px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.metric:after { content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 4px; background: var(--cyan); }
.metric strong { font-size: 33px; letter-spacing: 0; }
.metric span { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; justify-content: space-between; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.table-wrap { overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 1px 2px rgba(16, 24, 40, .04); }
table { width: 100%; border-collapse: collapse; min-width: 820px; }
th, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--soft-line); vertical-align: top; }
tbody tr:hover { background: #f8fafc; }
th { font-size: 11px; color: var(--muted); text-transform: uppercase; background: #f8fafc; font-weight: 800; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 800; background: #e8edf3; color: var(--ink); white-space: nowrap; }
.badge.danger { background: #fde8eb; color: var(--red); }
.badge.warn { background: #fff2d8; color: var(--amber); }
.badge.ok { background: #e2f5ed; color: var(--green); }
.badge.muted { background: #edf1f6; color: var(--muted); }
.flash { padding: 12px 14px; border-radius: 7px; font-weight: 700; border: 1px solid transparent; }
.flash.ok { background: #e2f5ed; color: var(--green); border-color: #b8e3cf; }
.flash.error { background: #fde8eb; color: var(--red); border-color: #f5b9c0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.span-2, .span-all { grid-column: 1 / -1; }
.timeline { display: grid; gap: 10px; }
.timeline-item { border-left: 3px solid var(--cyan); padding-left: 12px; }
.timeline-item small { color: var(--muted); display: block; margin-bottom: 3px; }
.permissions-panel { overflow: hidden; }
.permissions-grid { display: grid; grid-template-columns: minmax(240px, 1fr) repeat(3, minmax(120px, 160px)); border: 1px solid var(--line); border-radius: 8px; overflow: auto; margin: 14px 0; }
.permissions-head, .permissions-group, .permission-label, .switch { min-height: 48px; border-bottom: 1px solid var(--soft-line); display: flex; align-items: center; padding: 10px 12px; background: #fff; }
.permissions-head { background: #f8fafc; font-size: 12px; color: var(--muted); text-transform: uppercase; font-weight: 800; }
.permissions-group { background: #eef6fa; color: #174862; font-weight: 800; min-height: 38px; }
.permission-label { flex-direction: column; align-items: flex-start; justify-content: center; font-weight: 700; }
.permission-label small { color: var(--muted); font-weight: 500; margin-top: 2px; }
.switch { justify-content: center; margin: 0; }
.switch input { display: none; }
.switch span { width: 42px; height: 24px; border-radius: 999px; background: #cdd5df; position: relative; transition: background .15s; }
.switch span:after { content: ""; width: 18px; height: 18px; border-radius: 50%; background: #fff; position: absolute; left: 3px; top: 3px; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span:after { transform: translateX(18px); }
.modal { display: none; position: fixed; inset: 0; z-index: 50; padding: 22px; background: rgba(15, 34, 53, .58); overflow: auto; }
.modal.is-open { display: grid; place-items: start center; }
.modal-dialog { width: min(760px, 100%); background: #fff; border-radius: 8px; border: 1px solid var(--line); box-shadow: 0 28px 80px rgba(15, 34, 53, .28); margin: 32px 0; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 17px; border-bottom: 1px solid var(--line); background: #f8fafc; }
.modal-head h3 { margin: 0; }
.modal-body { padding: 17px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 17px; border-top: 1px solid var(--line); background: #f8fafc; }
.icon-btn { width: 34px; min-height: 34px; padding: 0; border-radius: 6px; background: #e8edf3; color: var(--ink); font-size: 20px; line-height: 1; }
.modal .panel { border: 0; box-shadow: none; padding: 0; }
.modal .panel h3 { display: none; }
.modal .panel > button:last-child { display: none; }
.menu-toggle, .mobile-menu-backdrop { display: none; }
.print-header { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .topbar { position: static; align-items: flex-start; flex-direction: column; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .form-grid { grid-template-columns: 1fr; }
  .permissions-grid { grid-template-columns: minmax(220px, 1fr) repeat(3, 110px); }
  .modal { padding: 12px; }
  .modal-dialog { margin: 12px 0; }
}
@media (max-width: 720px) {
  html { min-height: 100%; background: var(--bg); }
  body { min-height: 100%; font-size: 14px; -webkit-tap-highlight-color: transparent; }
  .login { align-items: stretch; place-items: stretch; padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom)); }
  .login-card { width: 100%; align-self: center; padding: 24px 20px; border-radius: 12px; box-shadow: 0 16px 45px rgba(23, 32, 51, .12); }
  .login-card .brand { justify-content: center; text-align: left; }
  .login-card input, .login-card button { min-height: 46px; }

  .app { display: block; min-height: 100vh; }
  .banner { display: none; }
  .main { min-height: 100vh; }
  .topbar { position: sticky; top: 0; z-index: 20; padding: calc(12px + env(safe-area-inset-top)) 16px 12px; gap: 10px; background: rgba(255, 255, 255, .97); box-shadow: 0 1px 0 var(--line); display: grid; grid-template-columns: 44px 1fr; align-items: center; }
  .topbar h2 { font-size: 18px; line-height: 1.2; }
  .topbar .hint { font-size: 12px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; grid-column: 1 / -1; }
  .topbar .actions .btn { width: 100%; min-height: 42px; }
  .topbar .actions .btn:only-child { grid-column: 1 / -1; }
  .menu-toggle { display: inline-flex; width: 40px; min-height: 40px; padding: 0; border-radius: 10px; font-size: 20px; background: var(--nav); color: #fff; }
  .content { padding: 14px 12px 20px; gap: 12px; }

  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 60; width: min(82vw, 310px); height: 100dvh; padding: calc(18px + env(safe-area-inset-top)) 14px calc(18px + env(safe-area-inset-bottom)); border-right: 1px solid rgba(255,255,255,.10); background: linear-gradient(180deg, var(--nav), var(--nav-2)); box-shadow: 18px 0 45px rgba(15, 34, 53, .28); overflow-y: auto; transform: translateX(-104%); transition: transform .22s ease; }
  body.menu-open .sidebar { transform: translateX(0); }
  .sidebar .brand { display: flex; padding: 0 4px 16px; margin-bottom: 10px; }
  .sidebar .brand img { width: 46px; height: 46px; }
  .sidebar .brand h1 { font-size: 16px; }
  .nav { display: grid; gap: 6px; margin-top: 8px; overflow: visible; }
  .nav a { min-width: 0; padding: 11px 10px; grid-template-columns: 32px 1fr; justify-items: stretch; gap: 10px; border-radius: 8px; font-size: 14px; line-height: 1.2; text-align: left; }
  .nav a i { width: 30px; height: 28px; border-radius: 7px; font-size: 10px; }
  .mobile-menu-backdrop { display: none; position: fixed; inset: 0; z-index: 55; background: rgba(15, 34, 53, .44); }
  body.menu-open .mobile-menu-backdrop { display: block; }
  body.menu-open { overflow: hidden; }

  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { min-height: 94px; padding: 14px; }
  .metric strong { font-size: 27px; }
  .metric span { font-size: 10px; line-height: 1.25; }
  .panel, .card { border-radius: 10px; padding: 14px; }
  .toolbar { display: block; }
  .actions { display: grid; grid-template-columns: 1fr; gap: 8px; }
  .actions .btn, .actions button { width: 100%; min-height: 44px; }

  .table-wrap { border-radius: 10px; margin: 0 -2px; }
  table { min-width: 720px; }
  th, td { padding: 10px; }
  .badge { padding: 5px 9px; }

  input, select, textarea { min-height: 44px; font-size: 16px; }
  textarea { min-height: 106px; }
  .form-grid { gap: 10px; }

  .modal { padding: 0; background: rgba(15, 34, 53, .42); }
  .modal.is-open { display: block; }
  .modal-dialog { width: 100%; min-height: 100dvh; margin: 0; border: 0; border-radius: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; box-shadow: none; }
  .modal-head { position: sticky; top: 0; z-index: 2; padding: calc(13px + env(safe-area-inset-top)) 14px 13px; }
  .modal-head h3 { font-size: 17px; }
  .modal-body { overflow: auto; padding: 14px; }
  .modal-foot { position: sticky; bottom: 0; padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: 1fr 1fr; }
  .modal-foot button { min-height: 44px; }
  .icon-btn { width: 38px; min-height: 38px; }

  .permissions-grid { grid-template-columns: minmax(220px, 1fr) repeat(3, 96px); margin-left: -2px; margin-right: -2px; }
  .permission-label small { font-size: 11px; }
}
@media print {
  .sidebar, .topbar, .no-print, .banner { display: none !important; }
  .app { display: block; }
  .content { padding: 0; }
  .panel, .table-wrap { border: 0; box-shadow: none; }
  .print-header { display: block; margin-bottom: 18px; }
  body { background: #fff; }
}
