:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --text: #111827;
  --muted: #667085;
  --line: #d8dee6;
  --accent: #c8102e;
  --accent-strong: #a40d25;
  --accent-soft: #fff0f3;
  --danger: #b42318;
  --shadow: 0 18px 48px rgba(17, 24, 39, 0.12);
  --radius: 8px;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #101318;
  color: #ffffff;
  padding: 20px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 22px;
}

.login-mark,
.app-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

.brand-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: var(--radius);
}

.brand-title {
  font-weight: 800;
  letter-spacing: 0;
}

.brand-subtitle,
.profile-meta,
.workspace-url {
  color: var(--muted);
  font-size: 13px;
}

.sidebar .brand-subtitle {
  color: #aeb8c4;
}

.category-list {
  display: grid;
  gap: 4px;
}

.category-button {
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 10px;
  background: transparent;
  color: #d5dce5;
  text-align: left;
  cursor: pointer;
}

.category-button:hover,
.category-button.active {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.main {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 72px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(17, 24, 39, 0.03);
}

.search-wrap {
  flex: 1;
  max-width: 620px;
}

.search {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 14px;
  color: var(--text);
  background: var(--surface-2);
  outline: none;
}

.search:focus {
  border-color: var(--accent);
  background: #ffffff;
}

.profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.profile-text {
  text-align: right;
}

.profile-name {
  font-weight: 700;
  white-space: nowrap;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.content-panel {
  padding: 28px;
}

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

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 18px;
}

.counter {
  color: var(--muted);
  font-size: 14px;
}

.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.pinned-section {
  margin-bottom: 26px;
}

.pinned-head {
  display: flex;
  align-items: center;
  min-height: 28px;
  margin-bottom: 12px;
}

.pinned-grid .app-card {
  border-color: rgba(200, 16, 46, 0.28);
  background: linear-gradient(180deg, #ffffff 0%, #fff8fa 100%);
}

.app-card {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 188px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  background: var(--surface);
  box-shadow: 0 8px 26px rgba(17, 24, 39, 0.06);
  overflow: hidden;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.app-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), #ef3340);
}

.app-card:hover {
  transform: translateY(-2px);
  border-color: rgba(200, 16, 46, 0.35);
  box-shadow: 0 18px 44px rgba(17, 24, 39, 0.13);
}

.app-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-card-head > div:nth-child(2) {
  min-width: 0;
}

.app-title {
  font-weight: 800;
  font-size: 16px;
}

.app-category {
  color: var(--muted);
  font-size: 13px;
}

.app-description {
  margin: 14px 0;
  color: #475467;
  line-height: 1.4;
}

.app-icon {
  width: 48px;
  height: 48px;
  border: 1px solid rgba(200, 16, 46, 0.16);
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55);
}

.app-icon.has-image {
  background: #ffffff;
  color: transparent;
}

.app-icon img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.health-badge {
  margin-left: auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.health-badge.online {
  border-color: rgba(16, 185, 129, 0.26);
  background: #ecfdf3;
  color: #047857;
}

.health-badge.checking {
  border-color: rgba(59, 130, 246, 0.26);
  background: #eff6ff;
  color: #1d4ed8;
}

.health-badge.degraded {
  border-color: rgba(245, 158, 11, 0.3);
  background: #fffbeb;
  color: #b45309;
}

.health-badge.offline {
  border-color: rgba(200, 16, 46, 0.26);
  background: var(--accent-soft);
  color: var(--accent);
}

.health-badge.disabled {
  border-color: #d0d5dd;
  background: #f2f4f7;
  color: #667085;
}

.pin-button {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0;
  background: #ffffff;
  color: var(--muted);
  cursor: pointer;
}

.pin-button:hover,
.pin-button.active {
  border-color: rgba(200, 16, 46, 0.35);
  background: var(--accent-soft);
  color: var(--accent);
}

.pin-button svg {
  width: 16px;
  height: 16px;
}

.app-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.primary-button,
.secondary-button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--line);
}

.secondary-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.danger-button {
  color: var(--danger);
}

.danger-button:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.login-panel {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 72px);
  padding: 28px;
}

.login-box {
  width: min(380px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-box h1 {
  margin: 16px 0 22px;
}

.login-box .primary-button {
  width: 100%;
}

.error-text {
  min-height: 20px;
  margin-top: 12px;
  color: var(--danger);
  font-size: 14px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 160px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface);
}

.workspace-panel {
  margin-top: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.workspace-head {
  margin: 0;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.workspace-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.workspace-frame {
  display: block;
  width: 100%;
  height: min(720px, calc(100vh - 220px));
  min-height: 460px;
  border: 0;
  background: #ffffff;
}

.admin-panel {
  margin-top: 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 8px 26px rgba(17, 24, 39, 0.06);
  overflow: hidden;
}

.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.admin-subtitle,
.admin-list-head {
  color: var(--muted);
  font-size: 13px;
}

.admin-actions,
.admin-form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.admin-list-head {
  margin-bottom: 8px;
  font-weight: 800;
  text-transform: uppercase;
}

.admin-apps-list {
  display: grid;
  gap: 8px;
}

.admin-app-row {
  display: grid;
  gap: 3px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #ffffff;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.admin-app-row:hover,
.admin-app-row.active {
  border-color: rgba(200, 16, 46, 0.35);
  background: var(--accent-soft);
}

.admin-app-row span {
  font-weight: 800;
}

.admin-app-row small {
  color: var(--muted);
}

.admin-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.admin-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.admin-form input,
.admin-form textarea,
.admin-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 10px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

.admin-form textarea {
  resize: vertical;
}

.admin-form input:focus,
.admin-form textarea:focus,
.admin-form select:focus {
  border-color: var(--accent);
}

.admin-wide {
  grid-column: 1 / -1;
}

.admin-check {
  align-self: end;
  display: flex !important;
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 38px;
}

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

[hidden] {
  display: none !important;
}

@media (max-width: 840px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    padding: 12px;
  }

  .brand {
    padding-bottom: 12px;
  }

  .category-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .category-button {
    width: auto;
    min-width: max-content;
  }

  .topbar {
    height: auto;
    flex-direction: column;
    align-items: stretch;
    padding: 14px;
  }

  .profile {
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .profile-text {
    text-align: left;
  }

  .content-panel {
    padding: 16px;
  }

  .section-head,
  .workspace-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace-actions {
    width: 100%;
  }

  .admin-head,
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .admin-head {
    align-items: flex-start;
    flex-direction: column;
  }

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