:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --surface-3: #eef2f6;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --muted: #667085;
  --muted-2: #98a2b3;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --success: #0f9f6e;
  --danger: #d92d20;
  --shadow: 0 18px 42px rgba(16, 24, 40, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.login-view {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px;
  background: #f7f8fb;
}

.login-panel {
  position: relative;
  overflow: hidden;
  width: min(430px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(16, 24, 40, 0.10);
  padding: 34px;
}

.login-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: #111827;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  background: #111827;
  color: #ffffff;
  border-radius: 8px;
  font-weight: 800;
  margin-bottom: 22px;
}

.brand-mark.small {
  width: 34px;
  height: 34px;
  margin: 0;
  font-size: 13px;
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: 0;
}

.login-panel p {
  margin: 0 0 26px;
  color: var(--muted);
  line-height: 1.6;
}

.login-form,
.stack-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--text);
  background: var(--surface);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(21, 108, 254, 0.12);
}

.primary-btn,
.secondary-btn,
.ghost-btn {
  min-height: 36px;
  border-radius: var(--radius);
  padding: 0 13px;
  border: 1px solid transparent;
  font-weight: 700;
  white-space: nowrap;
}

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

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

.secondary-btn {
  color: #1d4ed8;
  background: #eff6ff;
  border-color: #bfdbfe;
}

.ghost-btn {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}

.ghost-btn.danger {
  color: var(--danger);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  color: var(--muted);
}

.message {
  min-height: 20px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

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

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

.local-preview {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}

.local-preview button {
  margin: 12px 8px 0 0;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.app-shell {
  height: 100%;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  background: var(--bg);
}

.sidebar {
  background: #fbfcfe;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-brand {
  height: 70px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

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

.sidebar-brand span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.nav-list {
  padding: 12px;
  display: grid;
  gap: 4px;
  overflow: auto;
}

.nav-item {
  width: 100%;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #344054;
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  text-align: left;
  font-size: 13px;
  font-weight: 650;
}

.nav-item:hover {
  background: #f2f4f7;
}

.nav-item.active {
  color: var(--text);
  background: #ffffff;
  border-color: var(--border);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}

.nav-icon {
  color: var(--muted-2);
  display: grid;
  place-items: center;
}

.nav-icon svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-item.active .nav-icon {
  color: var(--primary);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}

.main-area {
  min-width: 0;
  display: grid;
  grid-template-rows: 70px minmax(0, 1fr);
}

.topbar {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 13px 22px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.topbar h2 {
  margin: 2px 0 0;
  font-size: 21px;
  line-height: 1.2;
  letter-spacing: 0;
}

.kicker {
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
  letter-spacing: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-chip {
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px 0 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: #344054;
  font-size: 13px;
  white-space: nowrap;
}

.user-avatar {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #111827;
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
}

.user-role {
  color: var(--muted);
}

.content {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.dashboard {
  padding: 22px;
  display: grid;
  gap: 18px;
}

.section-title {
  margin: 0 0 10px;
  font-size: 15px;
}

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

.card,
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.card {
  padding: 18px;
}

.card h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.card p,
.muted {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
  font-size: 13px;
}

.tool-layout {
  height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
}

.tool-notice {
  background: #fffaf0;
  color: #8a4b00;
  border-bottom: 1px solid #f7d994;
  padding: 10px 18px;
  font-size: 13px;
  line-height: 1.5;
}

.tool-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #ffffff;
}

.panel-page {
  padding: 22px;
  display: grid;
  gap: 16px;
}

.library-page {
  padding: 22px;
  display: grid;
  gap: 14px;
}

.library-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  padding: 2px 2px 8px;
}

.library-head h3 {
  margin: 2px 0 6px;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

.library-head p {
  margin: 0;
  max-width: 680px;
  color: var(--muted);
  line-height: 1.6;
  font-size: 13px;
}

.library-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  padding-top: 2px;
}

.library-filterbar {
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) repeat(3, minmax(120px, 1fr)) auto;
  gap: 12px;
  align-items: end;
}

.library-filterbar label span {
  color: #475467;
  font-size: 11px;
  font-weight: 760;
}

.library-filterbar label,
.library-form-grid label {
  min-width: 0;
}

.library-status {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.library-status strong {
  color: var(--text);
  margin-right: 4px;
}

.library-status span {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 14px;
}

.library-card {
  position: relative;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.library-card:hover {
  border-color: #d0d5dd;
  box-shadow: 0 14px 30px rgba(16, 24, 40, 0.08);
  transform: translateY(-1px);
}

.library-thumb {
  aspect-ratio: 16 / 11;
  background: #f8fafc;
  display: grid;
  place-items: center;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
}

.library-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.favorite-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.favorite-btn.active {
  color: #b7791f;
  background: #fff8db;
  border-color: #f6d06f;
}

.library-card-body {
  padding: 13px;
  display: grid;
  gap: 9px;
}

.library-card h4 {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
}

.library-meta,
.library-tags,
.library-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.library-meta {
  color: var(--muted);
  font-size: 12px;
}

.library-meta span:not(:last-child)::after {
  content: "/";
  margin-left: 8px;
  color: var(--muted-2);
}

.library-fileline {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-card-actions {
  padding-top: 2px;
  gap: 6px;
}

.library-card-actions .secondary-btn,
.library-card-actions .ghost-btn {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 680;
}

.empty-card {
  grid-column: 1 / -1;
  min-height: 220px;
  display: grid;
  place-items: center;
  padding: 20px;
  color: var(--muted);
  border: 1px dashed var(--border-strong);
  background: var(--surface);
  border-radius: var(--radius);
}

.library-modal {
  width: min(760px, 100%);
}

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

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

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.toolbar label {
  min-width: 180px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

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

.table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.admin-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  gap: 14px;
}

.admin-section h3 {
  margin: 2px 0 0;
  font-size: 18px;
  line-height: 1.25;
}

.badge.ok {
  color: #067647;
  background: #ecfdf3;
  border-color: #abefc6;
}

.badge.warn {
  color: #8a4b00;
  background: #fff7e6;
  border-color: #f7d994;
}

.badge.bad {
  color: #b42318;
  background: #fff1f0;
  border-color: #fecdca;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.32);
  z-index: 50;
}

.modal {
  width: min(480px, 100%);
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 18px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal h3 {
  margin: 0;
  font-size: 18px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

[hidden] {
  display: none !important;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-brand,
  .sidebar-footer {
    display: none;
  }

  .nav-list {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
  }

  .main-area {
    grid-template-rows: auto minmax(0, 1fr);
  }

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

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

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

  .library-actions {
    justify-content: flex-start;
  }

  .library-filterbar,
  .library-form-grid,
  .library-form-grid.two {
    grid-template-columns: 1fr;
  }
}
