:root {
  --bg: #eef5fb;
  --bg2: #f8fbff;
  --panel: rgba(255,255,255,.92);
  --panel-solid: #ffffff;
  --line: #cfe0f2;
  --line-soft: #e7eef7;
  --text: #172033;
  --muted: #667085;
  --header: #0f172a;
  --header2: #14213d;
  --accent: #3b82f6;
  --accent2: #7c3aed;
  --accent-soft: #eaf2ff;
  --row-alt: #f7fbff;
  --row-hover: #eef7ff;
  --selected: rgba(99,102,241,0.15);
  --readonly: #f1f5f9;
  --shadow: 0 10px 28px rgba(15,23,42,.08);
  --radius: 14px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 12% 0%, rgba(59,130,246,.16), transparent 28%),
    radial-gradient(circle at 86% 4%, rgba(124,58,237,.11), transparent 30%),
    linear-gradient(180deg, var(--bg2), var(--bg));
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
}
.app-header {
  background: linear-gradient(135deg, var(--header), var(--header2));
  color: white;
  padding: 14px 18px;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(620px, 1.7fr);
  gap: 16px;
  align-items: center;
  box-shadow: 0 12px 28px rgba(15,23,42,.22);
}
.app-kicker {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #93c5fd;
  font-weight: 700;
  margin-bottom: 3px;
}
.app-kicker.dark { color: var(--accent); }
.app-header h1 { margin: 0 0 4px; font-size: 21px; line-height: 1.1; }
.app-header h1 span { color:#bfdbfe; font-weight: 650; }
.app-header p { margin: 0; color: #cbd5e1; font-size: 12px; }
main { padding: 14px; }

.loader-panel {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) minmax(170px, 1fr) auto auto minmax(110px, auto);
  align-items: center;
  gap: 8px;
}
.drop-file-box {
  min-height: 56px;
  border: 1px dashed rgba(191,219,254,.72);
  border-radius: 13px;
  padding: 8px 12px;
  background: rgba(255,255,255,.08);
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, background .15s ease, box-shadow .15s ease;
  overflow: hidden;
}
.drop-file-box:hover,
.drop-file-box.dragover {
  background: rgba(59,130,246,.16);
  border-color: #93c5fd;
  box-shadow: inset 0 0 0 1px rgba(147,197,253,.28);
  transform: translateY(-1px);
}
.drop-file-box input { display:none; }
.drop-label { display:block; color:#bfdbfe; font-size:11px; margin-bottom: 4px; }
.drop-name {
  display:block;
  color:#fff;
  font-weight: 700;
  white-space: nowrap;
  overflow:hidden;
  text-overflow: ellipsis;
}
.status { color: #dbeafe; font-size:12px; white-space: nowrap; }

.card {
  background: var(--panel);
  border: 1px solid rgba(207,224,242,.95);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.grid-card { padding-bottom: 14px; }
.hidden { display:none; }
h2 { margin: 0 0 9px; font-size: 15px; letter-spacing: .01em; }
.section-title-row,
.grid-title-row { display:flex; align-items:center; justify-content:space-between; gap: 10px; }
.grid-actions { display:flex; align-items:center; gap:8px; }
.ghost-button.danger { color:#9f1239; border-color:#fecdd3; background:#fff7f8; }
.count { color: var(--muted); font-variant-numeric: tabular-nums; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 9px 12px;
}
.search-grid { grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); }
.field label { display:block; font-size:11px; color: var(--muted); margin-bottom:4px; font-weight: 650; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 9px;
  background: #fff;
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 4px rgba(59,130,246,.12);
}
.field textarea { min-height: 76px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; line-height: 1.55; }
.field.readonly input, .field.readonly textarea, .field.readonly select,
.field input:disabled, .field textarea:disabled, .field select:disabled {
  background: var(--readonly);
  color: #475467;
  border-color: #d8e2ee;
}
.button-row { margin-top: 10px; display:flex; gap:8px; }
.button-row.compact { margin-top: 0; }
.button-row.right { justify-content: flex-end; }
button {
  border: 0;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 750;
  font-size: 13px;
  transition: transform .14s ease, box-shadow .14s ease, opacity .14s ease, background .14s ease;
  white-space: nowrap;
}
button:hover:not(:disabled) { transform: translateY(-1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
.primary-button {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  box-shadow: 0 8px 18px rgba(59,130,246,.25);
}
.ghost-button {
  background: rgba(255,255,255,.78);
  color: #24415f;
  border: 1px solid rgba(207,224,242,.9);
}
.app-header .ghost-button { background: rgba(255,255,255,.12); color:#e0f2fe; border: 1px solid rgba(191,219,254,.35); }
.small { padding: 6px 12px; font-size: 12px; }
.icon-button {
  width: 32px; height: 32px; padding:0;
  display:inline-grid; place-items:center;
  background: #f8fafc;
  color:#334155;
  border:1px solid var(--line);
  box-shadow:none;
}
.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 390px);
  min-height: 300px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
table { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 980px; }
th, td {
  border-bottom: 1px solid var(--line-soft);
  border-right: 1px solid var(--line-soft);
  padding: 6px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
th {
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, #f6f9ff, #eaf2fb);
  z-index: 1;
  text-align:left;
  color:#29415f;
  font-weight: 800;
  font-size: 12px;
}
tbody tr { cursor: default; }
tbody tr:hover td { background: var(--row-hover); }
tr:nth-child(even) td { background: var(--row-alt); }
tr.selected td { background: var(--selected) !important; }
td.number { text-align:right; font-variant-numeric: tabular-nums; }
td.boolean { text-align:center; }
#detailDialog { width: min(1040px, 92vw); max-height: 92vh; border: none; border-radius: 18px; padding: 0; box-shadow: 0 28px 80px rgba(15,23,42,.30); }
#detailDialog::backdrop { background: rgba(15,23,42,.42); backdrop-filter: blur(2px); }
.dialog-body { padding: 16px; background: linear-gradient(180deg, #fff, #f8fbff); }
.dialog-title-row { display:flex; align-items:start; justify-content:space-between; margin-bottom: 10px; }
.dialog-title-row h2 { margin-bottom:0; }
.detail-grid { grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); }
.child-card {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  background: rgba(255,255,255,.75);
}
.child-card h3 { margin: 2px 0 10px; font-size: 14px; }
.child-table-wrap { max-height: 220px; overflow:auto; border: 1px solid var(--line); border-radius: 10px; background:#fff; }
.badge { display:inline-block; padding:2px 7px; border-radius:999px; background:#eef2ff; color:#3730a3; }
@media (max-width: 980px) {
  .app-header { grid-template-columns: 1fr; }
  .loader-panel { grid-template-columns: 1fr 1fr; }
  .status { grid-column: 1 / -1; }
}

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: linear-gradient(180deg, #eef6ff, #ddecfb); }
.sort-mark { display:inline-block; margin-left:6px; color: var(--accent2); font-size: 10px; min-width: 10px; }
.context-menu {
  position: fixed;
  z-index: 10000;
  min-width: 180px;
  padding: 6px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 14px 36px rgba(15,23,42,.18);
}
.context-menu button {
  width: 100%;
  display: block;
  border-radius: 8px;
  padding: 8px 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
  box-shadow: none;
  font-weight: 650;
}
.context-menu button:hover:not(:disabled) { background: var(--accent-soft); transform: none; }
.context-menu button:disabled { color: #98a2b3; }
