:root {
  --blue-900: #102f5f;
  --blue-700: #15559a;
  --green-600: #1f8a4c;
  --yellow-500: #f2c94c;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --page: #f4f7fb;
  --text: #172033;
  --muted: #637083;
  --border: #dbe4ef;
  --control: #ffffff;
  --control-muted: #eef5ff;
  --shadow: 0 14px 35px rgba(16, 47, 95, 0.10);
}

:root[data-theme="dark"] {
  --blue-900: #d7e6ff;
  --blue-700: #6ea8ff;
  --green-600: #7ad99f;
  --yellow-500: #f4d35e;
  --surface: #121a2a;
  --surface-soft: #172236;
  --page: #0b1220;
  --text: #eef4ff;
  --muted: #a9b7cc;
  --border: #27354c;
  --control: #0f1726;
  --control-muted: #1b2a42;
  --shadow: 0 14px 35px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--page);
}

a {
  color: inherit;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 48px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--blue-900);
  color: var(--yellow-500);
  font-weight: 800;
  font-size: 24px;
}

.brand-logo,
.login-logo {
  display: block;
  object-fit: contain;
  background: var(--control);
}

.brand-logo {
  width: 54px;
  height: 54px;
}

.login-logo {
  width: 76px;
  height: 76px;
}

.brand strong,
.brand span {
  display: block;
}

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

.brand span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--blue-900);
  cursor: pointer;
  text-decoration: none;
  font-weight: 700;
}

.icon-button.wide {
  width: auto;
  padding: 0 14px;
}

.icon-button.active {
  background: var(--blue-900);
  border-color: var(--blue-900);
  color: #ffffff;
}

.view-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--blue-900);
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.view-button.active {
  background: var(--blue-900);
  border-color: var(--blue-900);
  color: #ffffff;
}

.admin-link {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--green-600);
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.admin-link.muted {
  background: var(--control-muted);
  color: var(--blue-900);
}

.theme-toggle {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--control);
  color: var(--blue-900);
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.login-theme-toggle {
  justify-self: start;
}

.top-actions form {
  margin: 0;
}

.shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.page-heading {
  padding: 18px 0 26px;
}

.page-heading p {
  margin: 0 0 8px;
  color: var(--green-600);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.page-heading h1 {
  margin: 0;
  color: var(--blue-900);
  font-size: clamp(28px, 5vw, 42px);
  line-height: 1.08;
}

.page-heading span {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 16px;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.view-toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 420px) auto;
  gap: 8px;
  align-items: end;
  justify-content: space-between;
  margin: -8px 0 16px;
}

.view-buttons {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.search-box {
  color: var(--muted);
  font-size: 13px;
}

.search-box input {
  min-height: 42px;
  padding-left: 14px;
  background: var(--control);
  background-image: linear-gradient(transparent, transparent);
}

.app-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  min-height: 250px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.app-card.is-hidden {
  display: none !important;
}

.app-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--control-muted);
  font-size: 25px;
  overflow: hidden;
  color: var(--blue-900);
  font-weight: 700;
  text-align: center;
  line-height: 1;
}

.app-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-icon {
  background: var(--control);
  border: 1px solid var(--border);
  padding: 4px;
}

.app-card h2 {
  margin: 0 0 8px;
  color: var(--blue-900);
  font-size: 19px;
  line-height: 1.25;
}

.app-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.app-card a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 8px;
  background: var(--blue-700);
  color: #ffffff;
  font-weight: 700;
  text-decoration: none;
}

.app-grid.is-list {
  grid-template-columns: 1fr;
}

.app-grid.is-list .app-card {
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto;
  align-items: center;
  min-height: auto;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--page);
}

.login-card,
.form-panel,
.table-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.icon-preview-row,
.brand-panel,
.brand-admin-preview {
  display: flex;
  align-items: center;
}

.icon-preview-row {
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.icon-preview-row span,
.brand-panel p {
  display: block;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.admin-icon-preview {
  flex: 0 0 auto;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px;
}

.login-card h1,
.form-panel h2,
.table-panel h2 {
  margin: 0;
  color: var(--blue-900);
}

.login-card p {
  margin: -6px 0 6px;
  color: var(--muted);
}

label {
  display: grid;
  gap: 7px;
  color: var(--blue-900);
  font-size: 14px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--text);
  background: var(--control);
}

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

.primary-button,
.small-button {
  border: 0;
  border-radius: 8px;
  background: var(--blue-700);
  color: #ffffff;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
}

.primary-button {
  min-height: 44px;
  padding: 0 16px;
}

.small-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.small-button.danger {
  background: #b42318;
}

.small-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.alert {
  padding: 11px 12px;
  border-radius: 8px;
  font-size: 14px;
}

.alert.error {
  background: #fff1f0;
  color: #9f1b1b;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 18px;
  align-items: start;
}

.admin-console {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 20px;
  align-items: start;
}

.admin-sidebar {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.admin-sidebar a {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--blue-900);
  font-weight: 800;
  text-decoration: none;
}

.admin-sidebar a:hover,
.admin-sidebar a:focus-visible {
  background: var(--control-muted);
}

.admin-content {
  min-width: 0;
}

.user-admin-layout {
  margin-top: 22px;
}

.form-panel,
.table-panel {
  padding: 20px;
}

.brand-panel {
  align-items: flex-start;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 22px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
}

.brand-admin-preview {
  justify-content: center;
  width: 96px;
  height: 96px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.brand-admin-preview img {
  width: 84px;
  height: 84px;
  object-fit: contain;
}

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

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-line input {
  width: auto;
}

.text-link {
  color: var(--blue-700);
  font-weight: 700;
  text-decoration: none;
}

.responsive-table {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

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

.actions-cell form {
  margin: 0;
}

.table-icon {
  width: 38px;
  height: 38px;
  font-size: 18px;
}

.empty-state {
  margin: 18px 0 0;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface);
  text-align: center;
}

.app-card a:focus-visible,
.admin-link:focus-visible,
.icon-button:focus-visible,
.view-button:focus-visible,
.theme-toggle:focus-visible {
  outline: 3px solid var(--yellow-500);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .admin-link {
    flex: 1;
    justify-content: center;
  }

  .shell {
    width: min(100% - 24px, 1120px);
    padding-top: 20px;
  }

  .app-grid.is-list .app-card,
  .admin-layout,
  .admin-console,
  .view-toolbar {
    grid-template-columns: 1fr;
  }

  .admin-sidebar {
    position: static;
  }

  .view-buttons {
    justify-content: flex-start;
  }
}
