:root {
  color-scheme: light;
  --page: #f4f7fa;
  --sidebar: #0f2437;
  --sidebar-soft: #17334c;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #dbe4ec;
  --line-strong: #c8d5df;
  --text: #162635;
  --muted: #667789;
  --primary: #0878b8;
  --primary-dark: #075f92;
  --primary-soft: #e8f5fc;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --success: #0f766e;
  --radius: 8px;
  --shadow: 0 10px 28px rgba(22, 38, 53, .08);
}

* {
  box-sizing: border-box;
}

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

body.modal-open {
  overflow: hidden;
}

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

button,
.button-link {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

button:hover,
.button-link:hover {
  background: var(--primary-dark);
}

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

button.secondary:hover {
  background: var(--surface-soft);
}

button.danger {
  background: var(--danger-soft);
  border-color: #ffd4cf;
  color: var(--danger);
}

button.hidden,
.hidden {
  display: none !important;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 9px 10px;
  outline: none;
  font-size: 13px;
}

textarea {
  resize: vertical;
}

select[multiple] {
  min-height: 88px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(8, 120, 184, .12);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
}

.shell {
  width: 100%;
  min-height: 100vh;
}

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

.login-card {
  width: min(960px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand {
  min-height: 430px;
  display: grid;
  align-content: center;
  gap: 22px;
  padding: 42px;
  background: linear-gradient(135deg, #0f3654, #0878b8);
  color: #fff;
}

.brand-logo {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: 7px;
}

.brand-logo.large {
  width: 126px;
  height: 126px;
}

.eyebrow,
.page-kicker {
  display: block;
  margin-bottom: 6px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.login-brand .eyebrow {
  color: #c7ecff;
}

.login-brand h1 {
  max-width: 520px;
  font-size: 38px;
  line-height: 1.08;
}

.login-brand p {
  color: rgba(255, 255, 255, .82);
  line-height: 1.45;
}

.auth-panel {
  display: grid;
  gap: 16px;
  align-content: center;
  padding: 32px;
}

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

.sidebar {
  min-height: 100vh;
  display: grid;
  align-content: start;
  gap: 18px;
  padding: 18px;
  background: var(--sidebar);
  color: #fff;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, .12);
}

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

.sidebar-brand span {
  margin-top: 3px;
  color: #9fb4c6;
  font-size: 12px;
}

.sidebar-nav {
  display: grid;
  gap: 6px;
}

.sidebar-actions {
  display: grid;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, .12);
}

.sidebar-actions button {
  width: 100%;
}

.sidebar-actions .secondary {
  background: rgba(255, 255, 255, .08);
  border-color: rgba(255, 255, 255, .16);
  color: #e7f0f7;
}

.sidebar-actions .secondary:hover {
  background: rgba(255, 255, 255, .14);
}

.tab {
  width: 100%;
  justify-content: flex-start;
  background: transparent;
  border-color: transparent;
  color: #cbd8e3;
}

.tab:hover,
.tab.active {
  background: var(--sidebar-soft);
  color: #fff;
}

.main-area {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 16px;
  padding: 20px;
}

.topbar {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(22, 38, 53, .04);
}

.topbar p,
.hint,
.message,
.section-title span,
.meta,
#previewMeta,
.muted,
.mini-item span {
  color: var(--muted);
}

.top-actions,
.modal-actions,
.file-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.summary-band {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.summary-band div,
.panel,
.modal-form {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.summary-band div {
  display: grid;
  gap: 6px;
  padding: 15px;
}

.summary-band span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary-band strong {
  font-size: 20px;
  overflow-wrap: anywhere;
}

.tab-panel {
  min-width: 0;
}

.files-area,
.users-list,
.mini-list {
  display: grid;
  gap: 12px;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
  padding: 16px;
  align-items: end;
}

.toolbar-title {
  grid-column: 1 / -1;
}

.section-title {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.table-card,
.list-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.datatable-wrap {
  width: 100%;
  overflow: auto;
}

.datatable {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 13px;
}

.datatable thead {
  background: #f7fafc;
}

.datatable th {
  height: 42px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  color: #526575;
  font-size: 12px;
  font-weight: 800;
  text-align: left;
  text-transform: uppercase;
}

.sort-button {
  min-height: auto;
  padding: 0;
  justify-content: flex-start;
  background: transparent;
  border: 0;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  text-transform: inherit;
}

.sort-button:hover,
.sort-button.active {
  background: transparent;
  color: var(--primary-dark);
}

.datatable td {
  padding: 12px;
  border-bottom: 1px solid #edf2f6;
  vertical-align: middle;
}

.datatable tbody tr:hover {
  background: #fbfdff;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.pagination-bar label {
  display: flex;
  grid-auto-flow: column;
  align-items: center;
  gap: 8px;
}

.pagination-bar select {
  width: auto;
  min-width: 76px;
  padding: 7px 8px;
}

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

.select-col {
  width: 42px;
}

.actions-col {
  width: 260px;
}

.check-file {
  width: 16px;
  height: 16px;
}

.table-file {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 260px;
}

.file-icon {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 800;
}

.file-main {
  min-width: 0;
}

.file-name {
  max-width: 360px;
  overflow: hidden;
  color: var(--text);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge,
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 700;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.description {
  margin-top: 8px;
  color: #405160;
  line-height: 1.35;
}

.message {
  min-height: 18px;
  font-size: 12px;
  font-weight: 700;
}

.message.error {
  color: var(--danger);
}

.message.ok {
  color: var(--success);
}

.empty {
  padding: 34px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
}

.admin-grid {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.upload-panel,
.list-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.user-row {
  display: grid;
  grid-template-columns: 1fr 1fr 150px auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.user-row.readonly {
  grid-template-columns: 1fr auto auto;
}

.inline-check {
  display: flex;
  grid-auto-flow: column;
  align-items: center;
  gap: 6px;
}

.inline-check input {
  width: 16px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(10, 24, 36, .54);
}

.modal-box {
  width: min(1120px, 100%);
  height: min(780px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(10, 24, 36, .26);
}

.modal-form {
  width: min(560px, 100%);
  display: grid;
  gap: 14px;
  padding: 20px;
  box-shadow: 0 24px 70px rgba(10, 24, 36, .22);
}

.wide-form {
  width: min(760px, 100%);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.catalog-form {
  width: min(720px, 100%);
}

.catalog-list-section {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

.wide-form .section-title,
.wide-form .full-span,
.wide-form .form-footer {
  grid-column: 1 / -1;
}

.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.compact-table {
  min-width: 0;
}

.compact-table th,
.compact-table td {
  height: auto;
  padding: 10px 12px;
}

.compact-empty {
  padding: 20px;
}

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

.modal-head h2 {
  max-width: 680px;
  overflow-wrap: anywhere;
}

.preview-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
}

.preview-body {
  min-height: 0;
  background: var(--surface-soft);
}

.preview-body iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.preview-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.preview-empty {
  height: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

.preview-empty strong {
  color: var(--text);
}

.preview-side {
  display: grid;
  align-content: start;
  gap: 14px;
  overflow: auto;
  padding: 14px;
  border-left: 1px solid var(--line);
  background: var(--surface);
}

.preview-side form {
  display: grid;
  gap: 10px;
}

.mini-list h3 {
  margin: 0;
  font-size: 14px;
}

.mini-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.blocked {
  opacity: .62;
  pointer-events: none;
}

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

  .sidebar {
    min-height: auto;
  }

  .sidebar-nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .summary-band,
  .toolbar,
  .admin-grid,
  .preview-layout,
  .login-card {
    grid-template-columns: 1fr;
  }

  .topbar,
  .modal-head {
    align-items: stretch;
    flex-direction: column;
  }

  .user-row,
  .user-row.readonly {
    grid-template-columns: 1fr;
  }

  .pagination-bar,
  .pagination-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .preview-side {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}
