:root {
  --bg: #eef2f7;
  --panel: #fff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --danger: #dc2626;
  --success: #059669;
  --shadow: 0 20px 55px rgba(15, 23, 42, .1);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Segoe UI, system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 15% 0, #dbeafe 0, transparent 30%), var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  width: min(460px, 100%);
  background: #fffffff2;
  border: 1px solid #fff;
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 34px;
}

.login-card h1 {
  font-size: 28px;
  line-height: 1.15;
  margin: 18px 0 10px;
}

.login-card p,
.hint {
  color: var(--muted);
  line-height: 1.55;
}

.hint {
  margin-top: 18px;
  background: #eff6ff;
  border-radius: 16px;
  padding: 14px;
  color: #1e3a8a;
}

.logo {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 18px;
  background: linear-gradient(135deg, #2563eb, #0f172a);
  color: #fff;
  font-weight: 800;
}

.logo.small {
  width: 42px;
  height: 42px;
  border-radius: 14px;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 280px;
  padding: 22px;
  background: #0f172a;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 18px;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand > div:last-child {
  min-width: 0;
}

.brand strong,
.brand span {
  overflow-wrap: anywhere;
}

.brand span {
  display: block;
  color: #94a3b8;
  font-size: 13px;
  margin-top: 2px;
}

.menu-toggle {
  display: none;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  border: 0;
  border-radius: 14px;
  background: #ffffff14;
  color: #fff;
  cursor: pointer;
}

.menu-toggle span {
  width: 20px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  transition: transform .18s, opacity .18s;
}

.sidebar.open .menu-toggle span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.sidebar.open .menu-toggle span:nth-child(2) {
  opacity: 0;
}

.sidebar.open .menu-toggle span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

nav {
  display: grid;
  gap: 8px;
}

nav button,
.btn {
  border: 0;
  border-radius: 14px;
  min-height: 44px;
  padding: 12px 14px;
  font: inherit;
  cursor: pointer;
  transition: .18s;
}

nav button {
  background: transparent;
  color: #cbd5e1;
  text-align: left;
}

nav button:hover,
nav button.active {
  background: #ffffff1a;
  color: #fff;
}

.content {
  min-width: 0;
  margin-left: 280px;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  gap: 16px;
}

.topbar > div:first-child {
  min-width: 0;
}

.topbar p {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .12em;
}

.topbar h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.user-badge {
  max-width: 100%;
  background: var(--panel);
  padding: 12px 16px;
  border-radius: 16px;
  box-shadow: 0 8px 25px rgba(15, 23, 42, .08);
  color: var(--muted);
  overflow-wrap: anywhere;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.panel,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 34px rgba(15, 23, 42, .07);
}

.panel {
  min-width: 0;
  padding: 20px;
  margin-bottom: 18px;
}

.panel h2 {
  margin: 0 0 16px;
  font-size: 20px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.grid {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.side {
  grid-template-columns: 360px minmax(0, 1fr);
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.card {
  min-width: 0;
  padding: 18px;
}

.card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.card strong {
  display: block;
  font-size: 26px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.card small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.form {
  display: grid;
  gap: 14px;
}

.compact {
  grid-template-columns: 1fr;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-bottom: 14px;
}

.inline-form input[type="hidden"] {
  display: none;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  min-width: 0;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: var(--text);
}

.check input {
  width: 18px;
  min-width: 18px;
  height: 18px;
  min-height: 18px;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 11px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 4px #dbeafe;
}

.head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.head h2 {
  margin-bottom: 0;
}

.head input {
  max-width: 280px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #e2e8f0;
  color: var(--text);
  text-decoration: none;
  white-space: normal;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.btn.danger {
  background: #fee2e2;
  color: var(--danger);
}

.btn.ghost {
  background: #ffffff14;
  color: #e2e8f0;
  margin-top: auto;
  width: 100%;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

th {
  color: var(--muted);
  font-weight: 600;
  background: #f8fafc;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  background: #e0f2fe;
  color: #075985;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.badge.success {
  background: #dcfce7;
  color: #166534;
}

.badge.warn {
  background: #fef3c7;
  color: #92400e;
}

.badge.danger {
  background: #fee2e2;
  color: #991b1b;
}

.message {
  color: var(--danger);
  margin-top: 10px;
}

.toast {
  position: fixed;
  right: 24px;
  top: 24px;
  z-index: 50;
  background: #0f172a;
  color: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  max-width: min(360px, calc(100vw - 32px));
}

.hidden {
  display: none;
}

canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 190px;
}

@media (max-width: 1100px) {
  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .two,
  .side {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .content {
    padding: 22px;
  }

  .panel {
    padding: 18px;
  }

  .topbar h1 {
    font-size: 28px;
  }
}

@media (max-width: 760px) {
  .sidebar {
    position: sticky;
    inset: auto;
    top: 0;
    width: 100%;
    min-height: 68px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 0 0 22px 22px;
  }

  .menu-toggle {
    display: inline-flex;
  }

  nav {
    grid-column: 1 / -1;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: max-height .22s ease, opacity .18s ease;
  }

  .sidebar.open nav {
    max-height: 520px;
    opacity: 1;
    pointer-events: auto;
    padding-top: 4px;
  }

  nav button {
    min-height: 44px;
    padding: 11px 12px;
  }

  .btn.ghost {
    display: none;
    grid-column: 1 / -1;
    margin-top: 0;
  }

  .sidebar.open .btn.ghost {
    display: inline-flex;
  }

  .content {
    margin-left: 0;
    padding: 18px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .topbar p {
    font-size: 11px;
    letter-spacing: .08em;
  }

  .topbar h1 {
    font-size: 25px;
  }

  .user-badge {
    padding: 11px 13px;
  }

  .cards {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .grid {
    gap: 14px;
  }

  .panel {
    border-radius: 18px;
    padding: 16px;
    margin-bottom: 14px;
  }

  .panel h2 {
    font-size: 18px;
  }

  .head {
    display: grid;
    align-items: stretch;
    gap: 10px;
  }

  .head input {
    max-width: none;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
    width: 100%;
  }

  .actions .btn,
  .form > .btn {
    width: 100%;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    overflow-x: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 8px 22px rgba(15, 23, 42, .06);
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: minmax(96px, 38%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    min-height: 44px;
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
    overflow-wrap: anywhere;
  }

  tr.empty-row td {
    display: block;
  }

  tr.empty-row td::before {
    content: none;
  }

  td .actions {
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  }

  canvas {
    height: 230px;
  }
}

@media (max-width: 480px) {
  .login-body {
    padding: 16px;
    align-items: center;
  }

  .login-card {
    padding: 24px 18px;
    border-radius: 22px;
  }

  .login-card h1 {
    font-size: 23px;
  }

  .hint {
    padding: 12px;
  }

  .sidebar {
    padding: 10px 12px;
    border-radius: 0 0 18px 18px;
  }

  .brand {
    gap: 10px;
  }

  .brand strong {
    font-size: 15px;
  }

  .brand span {
    font-size: 12px;
  }

  .content {
    padding: 14px 12px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .panel {
    padding: 14px;
    border-radius: 16px;
  }

  .card {
    padding: 15px;
  }

  .card strong {
    font-size: 23px;
  }

  input,
  select,
  textarea,
  nav button,
  .btn {
    min-height: 46px;
  }

  td {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  td::before {
    font-size: 12px;
  }

  .toast {
    left: 12px;
    right: 12px;
    top: 12px;
    max-width: none;
  }
}
