:root {
  --bg: #121927;
  --bg-soft: #1b2435;
  --bg-card: rgba(33, 45, 67, 0.9);
  --line: rgba(255, 255, 255, 0.08);
  --text: #f4f7fb;
  --muted: #8fa0bc;
  --accent: #ff6a13;
  --accent-soft: rgba(255, 106, 19, 0.16);
  --danger: #ff5b5b;
  --success: #1ec98f;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top right, rgba(255, 106, 19, 0.22), transparent 24%),
    linear-gradient(180deg, #141c2c 0%, #0f1522 100%);
  color: var(--text);
}

a {
  color: inherit;
  text-decoration: none;
}

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

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

.auth-panel,
.panel,
.stat-card,
.document-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.auth-panel {
  width: min(520px, 100%);
  padding: 36px;
}

.auth-brand,
.brand,
.topbar-user,
.panel-header,
.document-actions,
.panel-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(135deg, #ff8d3a, var(--accent));
  color: #fff;
  font-weight: 800;
  box-shadow: 0 16px 32px rgba(255, 106, 19, 0.28);
}

.eyebrow {
  margin: 0 0 8px;
  color: #ffb37d;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
}

.auth-copy,
.brand span,
.list-row span,
td span,
.topbar-user span,
.document-meta span,
.empty-state {
  color: var(--muted);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  padding: 28px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(26, 36, 54, 0.92), rgba(16, 24, 38, 0.96));
}

.sidebar-nav {
  display: grid;
  gap: 10px;
  margin: 34px 0;
}

.sidebar-nav a {
  padding: 16px 18px;
  border-radius: 16px;
  color: var(--muted);
  font-weight: 600;
  transition: 0.2s ease;
}

.sidebar-nav a.active,
.sidebar-nav a:hover {
  color: #fff;
  background: linear-gradient(90deg, var(--accent-soft), rgba(255, 106, 19, 0.06));
  border: 1px solid rgba(255, 106, 19, 0.18);
}

.sidebar-card {
  padding: 18px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
}

.content {
  padding: 28px;
}

.content > .panel + .panel {
  margin-top: 24px;
}

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

.topbar h1,
.panel h2,
.document-card h3 {
  margin: 0;
}

.stats-grid,
.panel-grid,
.document-grid {
  display: grid;
  gap: 20px;
}

.stats-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 20px;
}

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

.stat-card,
.panel,
.document-card {
  padding: 22px;
}

.stat-card strong {
  display: block;
  margin-top: 10px;
  font-size: 2rem;
}

.list-stack,
.form-grid,
.document-meta {
  display: grid;
  gap: 14px;
}

.list-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.list-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

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

.form-grid label,
.compact-form label {
  display: grid;
  gap: 8px;
}

.full-width {
  grid-column: 1 / -1;
}

.field-compact {
  max-width: 420px;
}

.field-stack-start {
  grid-column: 1 / 2;
}

.field-spacer {
  min-height: 1px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(9, 15, 27, 0.72);
  color: var(--text);
  border-radius: 14px;
  padding: 14px 16px;
  outline: none;
}

input[type="checkbox"] {
  width: auto;
}

input[type="file"] {
  padding: 10px 12px;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(12, 20, 35, 0.92), rgba(9, 15, 27, 0.9));
  cursor: pointer;
}

input[type="file"]::file-selector-button {
  margin-right: 14px;
  border: 1px solid rgba(255, 106, 19, 0.24);
  border-radius: 12px;
  padding: 10px 16px;
  background: linear-gradient(135deg, rgba(255, 138, 52, 0.22), rgba(255, 106, 19, 0.14));
  color: #ffd7bc;
  font-weight: 700;
  cursor: pointer;
  transition: 0.2s ease;
}

input[type="file"]::file-selector-button:hover {
  border-color: rgba(255, 106, 19, 0.4);
  background: linear-gradient(135deg, rgba(255, 138, 52, 0.28), rgba(255, 106, 19, 0.2));
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 52px;
  border-radius: 18px;
  background-image:
    linear-gradient(135deg, transparent 50%, rgba(255, 255, 255, 0.82) 50%),
    linear-gradient(45deg, rgba(255, 255, 255, 0.82) 50%, transparent 50%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  background-position:
    calc(100% - 24px) calc(50% - 3px),
    calc(100% - 18px) calc(50% - 3px),
    0 0;
  background-size:
    7px 7px,
    7px 7px,
    100% 100%;
  background-repeat: no-repeat;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 10px 24px rgba(0, 0, 0, 0.12);
  cursor: pointer;
}

select:hover {
  border-color: rgba(255, 255, 255, 0.16);
}

select option {
  background: #202a3d;
  color: var(--text);
}

.custom-select {
  position: relative;
  width: 100%;
}

.custom-select select {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}

.custom-select-trigger {
  width: 100%;
  min-height: 54px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background:
    linear-gradient(180deg, rgba(12, 20, 35, 0.92), rgba(9, 15, 27, 0.9));
  color: var(--text);
  border-radius: 18px;
  padding: 14px 54px 14px 18px;
  outline: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 10px 24px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  text-align: left;
  position: relative;
}

.custom-select-trigger::after,
.custom-select-trigger::before {
  content: "";
  position: absolute;
  right: 22px;
  top: 50%;
  width: 8px;
  height: 2px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  transition: 0.2s ease;
}

.custom-select-trigger::before {
  transform: translateY(-2px) rotate(45deg);
  right: 27px;
}

.custom-select-trigger::after {
  transform: translateY(-2px) rotate(-45deg);
}

.custom-select.open .custom-select-trigger,
.custom-select-trigger:focus {
  border-color: rgba(255, 106, 19, 0.6);
  box-shadow:
    0 0 0 4px rgba(255, 106, 19, 0.16),
    0 16px 40px rgba(0, 0, 0, 0.2);
}

.custom-select.open .custom-select-trigger {
  border-radius: 18px 18px 12px 12px;
}

.custom-select.open .custom-select-trigger::before {
  transform: translateY(-2px) rotate(-45deg);
}

.custom-select.open .custom-select-trigger::after {
  transform: translateY(-2px) rotate(45deg);
}

.custom-select-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 30;
  padding: 8px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(18, 25, 39, 0.98);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.34);
  display: grid;
  gap: 6px;
}

.custom-select[hidden] .custom-select-panel,
.custom-select-panel[hidden] {
  display: none;
}

.custom-select-option {
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 13px 14px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.custom-select-option:hover,
.custom-select-option:focus {
  background: rgba(255, 255, 255, 0.06);
  outline: none;
}

.custom-select-option.is-selected {
  background: linear-gradient(90deg, rgba(255, 106, 19, 0.2), rgba(255, 106, 19, 0.08));
  border: 1px solid rgba(255, 106, 19, 0.2);
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(255, 106, 19, 0.6);
  box-shadow: 0 0 0 4px rgba(255, 106, 19, 0.16);
}

.primary-button,
.ghost-button,
.success-button,
.danger-button {
  border: 0;
  border-radius: 14px;
  padding: 13px 18px;
  cursor: pointer;
  transition: 0.2s ease;
}

.primary-button {
  background: linear-gradient(135deg, #ff8a34, var(--accent));
  color: #fff;
  font-weight: 700;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  border: 1px solid var(--line);
}

.success-button {
  background: rgba(30, 201, 143, 0.16);
  color: #b5f4dc;
  border: 1px solid rgba(30, 201, 143, 0.26);
}

.danger-button {
  background: rgba(255, 91, 91, 0.12);
  color: #ffb3b3;
  border: 1px solid rgba(255, 91, 91, 0.2);
}

.toolbar,
.document-actions,
.checkbox,
td form {
  display: flex;
  gap: 12px;
  align-items: center;
}

.toolbar {
  margin-top: 20px;
  margin-bottom: 18px;
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) minmax(220px, 1fr) minmax(160px, 0.55fr) auto;
  align-items: stretch;
  gap: 12px;
}

.checkbox {
  position: relative;
}

.checkbox-toggle {
  min-height: 52px;
  padding: 10px 14px;
  width: fit-content;
  max-width: 240px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(12, 20, 35, 0.9), rgba(9, 15, 27, 0.86));
  gap: 12px;
  cursor: pointer;
  align-items: center;
  justify-content: flex-start;
  transition: 0.2s ease;
}

.form-grid > .checkbox-toggle.full-width,
.compact-form > .checkbox-toggle.full-width {
  grid-column: 1 / -1;
  justify-self: start;
}

.checkbox-toggle:hover {
  border-color: rgba(255, 255, 255, 0.16);
}

.checkbox-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  border: 0;
}

.checkbox-toggle-control {
  flex: 0 0 54px;
  width: 54px;
  height: 30px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
  position: relative;
  transition: 0.2s ease;
}

.checkbox-toggle-control::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #f4f7fb;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
  transition: 0.2s ease;
}

.checkbox-copy {
  display: flex;
  align-items: center;
  flex: 1;
}

.checkbox-copy strong {
  font-size: 0.92rem;
  font-weight: 700;
}

.checkbox-toggle input:checked + .checkbox-toggle-control {
  background: linear-gradient(135deg, rgba(255, 138, 52, 0.72), rgba(255, 106, 19, 0.88));
  border-color: rgba(255, 138, 52, 0.54);
}

.checkbox-toggle input:checked + .checkbox-toggle-control::after {
  transform: translateX(24px);
}

.checkbox-toggle input:focus-visible + .checkbox-toggle-control {
  box-shadow:
    0 0 0 4px rgba(255, 106, 19, 0.16),
    inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.form-grid > .checkbox-toggle + .primary-button,
.compact-form > .checkbox-toggle + .ghost-button {
  justify-self: start;
  min-width: 280px;
}

.toolbar input,
.toolbar select {
  min-width: 0;
}

.toolbar .custom-select {
  min-width: 0;
}

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

.modal-shell {
  width: min(920px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
}

.modal-shell::backdrop {
  background: rgba(8, 12, 20, 0.74);
  backdrop-filter: blur(8px);
}

.modal-card {
  padding: 22px;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: rgba(24, 34, 52, 0.96);
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.42);
  color: var(--text);
}

.modal-card h2,
.modal-card label span,
.modal-card strong {
  color: var(--text);
}

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

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

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

.inline-edit summary {
  cursor: pointer;
  color: #ffb37d;
  margin-bottom: 10px;
}

.compact-form {
  margin-bottom: 12px;
}

.badge {
  display: inline-flex;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
}

.badge-success {
  background: rgba(30, 201, 143, 0.16);
  color: #9df2d1;
}

.badge-muted {
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
}

.flash {
  margin-bottom: 20px;
  padding: 14px 16px;
  border-radius: 16px;
  transition: 0.25s ease;
}

.flash-success {
  background: rgba(30, 201, 143, 0.15);
  border: 1px solid rgba(30, 201, 143, 0.24);
}

.flash-error {
  background: rgba(255, 91, 91, 0.12);
  border: 1px solid rgba(255, 91, 91, 0.2);
}

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

.document-card p {
  color: var(--muted);
}

.library-table td strong,
.library-table td span {
  display: block;
}

.library-table td:last-child {
  width: 1%;
  white-space: nowrap;
}

.library-actions {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  gap: 10px;
  align-items: center;
  justify-content: flex-start;
}

.library-actions form {
  margin: 0;
  display: block;
}

.library-actions .ghost-button,
.library-actions .success-button,
.library-actions .danger-button {
  min-width: 132px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.library-actions .danger-button {
  min-width: 98px;
}

.standalone-library {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(9, 15, 27, 0.18);
}

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

.helper-copy {
  margin: 0;
  color: var(--muted);
}

.inline-button {
  display: inline-flex;
  width: fit-content;
}

.pagination-bar,
.pagination-actions,
.pagination-copy {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pagination-bar {
  justify-content: space-between;
  margin-top: 18px;
  flex-wrap: wrap;
  row-gap: 14px;
}

.pagination-copy span {
  color: var(--muted);
}

.pagination-copy {
  flex-wrap: wrap;
}

.ghost-button.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

.table-helper {
  display: inline-block;
  color: var(--muted);
  max-width: 240px;
  line-height: 1.45;
}

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

  th,
  td {
    padding: 14px 8px;
  }

  .library-actions .ghost-button,
  .library-actions .success-button,
  .library-actions .danger-button {
    min-width: 118px;
    padding: 12px 14px;
  }

  .library-actions .danger-button {
    min-width: 92px;
  }
}

@media (max-width: 1200px) {
  .topbar {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .topbar-user {
    width: 100%;
    justify-content: space-between;
  }

  .toolbar {
    grid-template-columns: minmax(0, 1.6fr) minmax(220px, 1fr) minmax(150px, 0.55fr) auto;
  }

  .library-table td:last-child {
    min-width: 260px;
  }
}

@media (max-width: 1080px) {
  .app-shell,
  .panel-grid,
  .stats-grid,
  .document-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .toolbar,
  .topbar,
  .topbar-user,
  .document-actions,
  .library-actions {
    align-items: stretch;
  }

  .library-table td:last-child {
    white-space: normal;
  }

  .toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .field-compact {
    max-width: 100%;
  }

  .field-stack-start {
    grid-column: auto;
  }

  .field-spacer {
    display: none;
  }

  table {
    min-width: 960px;
  }

  .sidebar {
    display: none;
  }
}

@media (max-width: 720px) {
  .content {
    padding: 16px;
  }

  .panel,
  .auth-panel,
  .stat-card,
  .document-card {
    padding: 18px;
    border-radius: 18px;
  }

  .topbar-user {
    gap: 12px;
  }

  .topbar-user > div {
    width: 100%;
  }

  .toolbar button,
  .topbar-user .ghost-button,
  .inline-button {
    width: 100%;
    justify-content: center;
  }

  .pagination-actions,
  .pagination-copy {
    width: 100%;
  }

  .pagination-bar {
    margin-top: 22px;
  }

  .pagination-actions .ghost-button {
    width: 100%;
    justify-content: center;
  }

  table {
    min-width: 820px;
  }
}
