:root {
  color-scheme: light;
  --bg-a: #ccd9ee;
  --bg-b: #e1e9f7;
  --card: #eef3fb;
  --line: #a9b9d1;
  --line-strong: #8da4c6;
  --text: #0e2039;
  --muted: #334a67;
  --brand: #173fae;
  --brand-hover: #103485;
  --secondary: #273548;
  --danger: #9f1c1c;
  --success-bg: #cce9d7;
  --error-bg: #f3caca;
  --control-h: 42px;
  --radius-md: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 8% -10%, #bdcfec 0%, transparent 45%),
    radial-gradient(circle at 100% 0%, #c9daef 0%, transparent 30%),
    linear-gradient(180deg, var(--bg-a) 0%, var(--bg-b) 100%);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(10px);
  border-bottom: 1px solid #acbed9;
  background: rgba(224, 234, 248, 0.9);
}

.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  letter-spacing: 0.3px;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(160deg, #1d4ed8, #0284c7);
  box-shadow: 0 0 0 5px rgba(29, 78, 216, 0.18);
}

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

.action-link {
  text-decoration: none;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  min-height: var(--control-h);
  border: 1px solid #8ea6c8;
  border-radius: var(--radius-md);
  background: #dae6f8;
  color: #183966;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.logout-form {
  margin: 0;
  display: flex;
}

.action-btn,
button,
.link-button,
input,
select {
  min-height: var(--control-h);
  height: var(--control-h);
  font-size: 14px;
  line-height: 1;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #7e9ac3;
  border-radius: var(--radius-md);
  background: linear-gradient(160deg, #dbe7f9, #c8d8f0);
  color: #17335f;
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
}

.action-btn:hover {
  background: linear-gradient(160deg, #c9d8ef, #b7cae8);
}

.menu-manage {
  position: relative;
}

.menu-manage summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  margin: 0;
}

.menu-manage summary::-webkit-details-marker {
  display: none;
}

.menu-manage[open] .action-btn-manage {
  border-color: #6f8db8;
  box-shadow: inset 0 0 0 1px #7996c0;
}

.plus-icon {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  line-height: 1;
  background: #f2f7ff;
  color: var(--brand);
  border: 1px solid #8fa5c7;
}

.manage-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: min(920px, 92vw);
  max-height: 72vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #eaf1fb;
  box-shadow: 0 28px 48px -24px rgba(10, 24, 45, 0.58);
}

.manage-panel h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.manage-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.manage-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid #c0cee2;
  border-radius: var(--radius-md);
  padding: 8px;
  background: #f2f6fc;
}

.manage-folder-name {
  margin: 0;
  font-weight: 700;
}

.manage-folder-meta {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.manage-move-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.manage-move-form,
.manage-delete-form {
  margin: 0;
}

.container {
  max-width: 1280px;
  margin: 18px auto 32px;
  padding: 0 16px;
}

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

.login-card {
  width: min(460px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 32px -30px rgba(12, 26, 46, 1);
  padding: 16px;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 24px;
}

.muted-login {
  margin: 0 0 12px;
  color: var(--muted);
}

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

.login-form label {
  display: block;
  color: #284460;
  font-size: 14px;
}

.login-form button {
  margin-top: 4px;
}

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

.stat-card {
  margin: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 10px 26px -22px rgba(9, 22, 40, 0.95);
}

.stat-label {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-value {
  margin: 6px 0 0;
  font-size: 25px;
  font-weight: 800;
}

.alerts {
  margin-bottom: 12px;
}

.alert {
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 8px;
  border: 1px solid transparent;
}

.alert.success {
  background: var(--success-bg);
  border-color: #8fc2a3;
}

.alert.error {
  background: var(--error-bg);
  border-color: #d59b9b;
}

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 84px;
}

.sidebar-head {
  margin-bottom: 10px;
}

.folder-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.folder-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: #e8eef8;
  padding: 9px 12px;
  color: var(--text);
  text-decoration: none;
}

.folder-link:hover {
  border-color: #a3b7d3;
  background: #dde7f5;
}

.folder-link.active {
  border-color: #7596c2;
  background: linear-gradient(160deg, #d8e5f7, #c7d7ee);
}

.folder-link-name {
  font-weight: 600;
}

.count-badge {
  font-size: 12px;
  font-weight: 700;
  color: #244878;
  background: #dbe6f5;
  border: 1px solid #a9bfdc;
  border-radius: 999px;
  padding: 2px 8px;
}

.content-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 32px -30px rgba(12, 26, 46, 1);
}

.card-spaced {
  padding: 16px;
}

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

h2 {
  margin: 0;
  font-size: 20px;
}

.table-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  width: min(960px, 100%);
}

.search-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 8px;
}

input,
select {
  width: 100%;
  margin: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 0 12px;
  background: #f4f8ff;
  color: var(--text);
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%2338557b' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-position: right 12px center;
  background-size: 10px 6px;
  background-repeat: no-repeat;
  padding-right: 34px;
  background-clip: padding-box;
}

option,
optgroup {
  color: var(--text);
  background: #f4f8ff;
}

input:focus,
select:focus {
  outline: 2px solid #aec3e2;
  border-color: #7391ba;
}

button {
  border: 0;
  border-radius: var(--radius-md);
  background: var(--brand);
  color: #fff;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

button:hover {
  background: var(--brand-hover);
}

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

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

.export-form {
  display: flex;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 0 14px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  background: #f4f8ff;
}

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

.users-create-card {
  margin-bottom: 14px;
}

.users-create-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: end;
}

.users-create-form label {
  display: block;
  color: #284460;
  font-size: 14px;
}

.users-create-action {
  display: flex;
  align-items: end;
}

.users-table-wrap {
  margin-top: 10px;
}

.users-table {
  width: 100%;
  min-width: 900px;
  border-collapse: separate;
  border-spacing: 0;
}

.users-table thead th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #27486f;
  padding: 10px 8px;
  border-bottom: 1px solid #afc3df;
}

.users-table tbody td {
  padding: 10px 8px;
  vertical-align: top;
  border-bottom: 1px solid #c5d4ea;
}

.users-actions {
  min-width: 340px;
}

.users-actions form {
  margin: 0 0 8px;
}

.users-actions form:last-child {
  margin-bottom: 0;
}

.users-inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.me-pill {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  min-height: 24px;
  border: 1px solid #95afd2;
  border-radius: 999px;
  background: #dbe7f8;
  color: #1a406f;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
}

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

.item-card {
  border: 1px solid #bccbe0;
  border-radius: 14px;
  padding: 12px;
  background: linear-gradient(180deg, #f0f5fd 0%, #e8f0fb 100%);
  display: flex;
  flex-direction: column;
  min-height: 272px;
}

.item-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.item-title {
  margin: 0;
  font-size: 18px;
}

.item-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.folder-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid #a8bfdc;
  border-radius: 999px;
  padding: 0 10px;
  min-height: 30px;
  font-size: 12px;
  font-weight: 700;
  color: #244878;
  background: #dde8f8;
  max-width: 55%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.metric {
  border: 1px solid #c5d4ea;
  border-radius: var(--radius-md);
  padding: 8px;
  background: #e5eefb;
  min-height: 72px;
}

.metric-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.metric-value {
  font-size: 14px;
}

.item-extra {
  margin-bottom: 10px;
}

.item-extra p {
  margin: 0 0 4px;
  font-size: 13px;
  color: #2e4a6c;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: auto;
}

.item-actions form {
  margin: 0;
}

.icon-btn {
  width: var(--control-h);
  min-width: var(--control-h);
  padding: 0;
  border: 1px solid #9db3d4;
  border-radius: var(--radius-md);
  background: #dbe7f8;
  color: #173865;
  font-size: 18px;
  line-height: 1;
}

.icon-btn:hover {
  background: #c9d9ef;
}

.small-btn {
  min-width: var(--control-h);
  padding: 0 12px;
}

.empty {
  text-align: center;
  color: var(--muted);
  margin: 8px 0 0;
}

.empty-inline {
  color: var(--muted);
  margin: 0;
}

.modal {
  width: min(820px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  background: #eaf1fb;
  box-shadow: 0 30px 60px -24px rgba(8, 18, 35, 0.65);
}

.modal::backdrop {
  background: rgba(8, 18, 35, 0.58);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid #b3c5dd;
  background: linear-gradient(180deg, #d9e5f7 0%, #e8f0fb 100%);
}

.modal-head h3 {
  margin: 0;
}

.ghost-close {
  border: 1px solid #9fb5d1;
  border-radius: var(--radius-md);
  background: #f4f8ff;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
  width: var(--control-h);
  min-width: var(--control-h);
  min-height: var(--control-h);
  padding: 0;
}

.modal-sub {
  margin: 0;
  padding: 10px 16px 0;
  color: var(--muted);
}

.modal-sub code {
  background: #dbe7f8;
  border: 1px solid #afc5e3;
  border-radius: 6px;
  padding: 1px 5px;
}

.modal-form {
  padding: 14px 16px 16px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.modal-form label {
  display: block;
  font-size: 14px;
  color: #284460;
}

.folder-create-inline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.inline-action-btn {
  border: 1px solid #99b2d4;
  border-radius: var(--radius-md);
  background: #dce8f9;
  color: #1a3e6f;
  padding: 0 12px;
}

.inline-action-btn:hover {
  background: #cadbf1;
}

.field-hint {
  margin: -2px 0 2px;
  color: var(--muted);
  font-size: 12px;
}

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

.modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

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

  .sidebar {
    position: static;
  }

  .folder-list {
    max-height: 260px;
    overflow: auto;
  }

  .table-head {
    flex-direction: column;
  }

  .table-tools {
    width: 100%;
    justify-content: flex-start;
  }

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

@media (max-width: 980px) {
  .manage-row {
    grid-template-columns: 1fr;
  }

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

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

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

  .users-actions {
    min-width: 240px;
  }
}

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

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

  .item-metrics {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .topbar-inner {
    flex-direction: column;
    align-items: stretch;
  }

  .top-actions {
    width: 100%;
  }

  .action-btn,
  .menu-manage {
    width: 100%;
  }

  .action-btn {
    justify-content: center;
  }

  .menu-manage summary {
    width: 100%;
    justify-content: center;
  }

  .manage-panel {
    width: 100%;
    right: 0;
    left: 0;
  }

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

  .search-form {
    grid-template-columns: 1fr;
    width: 100%;
  }

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

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

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg-a: #0f1623;
    --bg-b: #0a101b;
    --card: #141f30;
    --line: #2a3c59;
    --line-strong: #3a5278;
    --text: #e4ebf7;
    --muted: #a9bad4;
    --brand: #3f71db;
    --brand-hover: #345fba;
    --secondary: #3b516f;
    --danger: #ba4646;
    --success-bg: #18362b;
    --error-bg: #3d2026;
  }

  body {
    background:
      radial-gradient(circle at 8% -10%, #1a2b46 0%, transparent 45%),
      radial-gradient(circle at 100% 0%, #1b2f4b 0%, transparent 30%),
      linear-gradient(180deg, var(--bg-a) 0%, var(--bg-b) 100%);
  }

  .topbar {
    border-bottom-color: #2a3c59;
    background: rgba(12, 18, 29, 0.9);
  }

  .brand-dot {
    background: linear-gradient(160deg, #4f86ff, #1ba0f0);
    box-shadow: 0 0 0 5px rgba(79, 134, 255, 0.2);
  }

  .user-chip {
    border-color: #415a80;
    background: #1b2940;
    color: #dce8fb;
  }

  .action-btn {
    border-color: #415a80;
    background: linear-gradient(160deg, #223451, #1a293f);
    color: #e6eefc;
  }

  .action-btn:hover {
    background: linear-gradient(160deg, #273c5c, #20324e);
  }

  .menu-manage[open] .action-btn-manage {
    border-color: #5f7eaf;
    box-shadow: inset 0 0 0 1px #6d8fca;
  }

  .plus-icon {
    background: #17253b;
    color: #85acff;
    border-color: #415a80;
  }

  .manage-panel {
    border-color: #304566;
    background: #121d2e;
    box-shadow: 0 28px 48px -24px rgba(0, 0, 0, 0.8);
  }

  .manage-row {
    border-color: #304566;
    background: #17263a;
  }

  .folder-link {
    background: #17263a;
  }

  .folder-link:hover {
    border-color: #425d84;
    background: #1c2f48;
  }

  .folder-link.active {
    border-color: #5f7eaf;
    background: linear-gradient(160deg, #213853, #192d45);
  }

  .count-badge {
    color: #d2e2ff;
    background: #253854;
    border-color: #465f88;
  }

  .login-form label,
  .users-create-form label,
  .modal-form label {
    color: #b8ccec;
  }

  input,
  select {
    background-color: #0f1828;
    border-color: #3c547a;
  }

  select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%239cb9e6' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
    background-position: right 12px center;
    background-size: 10px 6px;
    background-repeat: no-repeat;
  }

  option,
  optgroup {
    color: #e4ebf7;
    background: #142237;
  }

  input:focus,
  select:focus {
    outline: 2px solid #5b7caf;
    border-color: #6f95d0;
  }

  .link-button {
    border-color: #3c547a;
    background: #17263b;
    color: #dce9ff;
  }

  .users-table thead th {
    color: #b8ccec;
    border-bottom-color: #3f587e;
  }

  .users-table tbody td {
    border-bottom-color: #304566;
  }

  .me-pill {
    border-color: #496a96;
    background: #223652;
    color: #d2e2ff;
  }

  .item-card {
    border-color: #314869;
    background: linear-gradient(180deg, #172539 0%, #122033 100%);
  }

  .folder-pill {
    border-color: #496a96;
    color: #d2e2ff;
    background: #223652;
  }

  .metric {
    border-color: #365279;
    background: #1a2b42;
  }

  .item-extra p {
    color: #adbfdd;
  }

  .icon-btn {
    border-color: #496a96;
    background: #223652;
    color: #d2e2ff;
  }

  .icon-btn:hover {
    background: #294264;
  }

  .modal {
    border-color: #304566;
    background: #121d2e;
    box-shadow: 0 30px 60px -24px rgba(0, 0, 0, 0.85);
  }

  .modal::backdrop {
    background: rgba(2, 8, 16, 0.76);
  }

  .modal-head {
    border-bottom-color: #304566;
    background: linear-gradient(180deg, #1d2f49 0%, #18263c 100%);
  }

  .ghost-close {
    border-color: #496a96;
    background: #17263b;
    color: #dce8fb;
  }

  .modal-sub code {
    background: #203452;
    border-color: #496a96;
  }

  .inline-action-btn {
    border-color: #496a96;
    background: #223652;
    color: #dce8fb;
  }

  .inline-action-btn:hover {
    background: #294264;
  }

  .alert.success {
    border-color: #2f7757;
    color: #daf2e5;
  }

  .alert.error {
    border-color: #8e4450;
    color: #ffdde1;
  }
}
