:root {
  --bg: #f5f7fb;
  --panel: #fff;
  --text: #172033;
  --muted: #687387;
  --line: #dfe5ee;
  --primary: #2563eb;
  --primary-dark: #1748b8;
  --success: #0f9f6e;
  --danger: #dc2626;
  --warning: #b45309;
  --shadow: 0 10px 28px rgba(15, 23, 42, .08);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
a { color: inherit; text-decoration: none; }
input, textarea, select, button { font: inherit; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 248px;
  padding: 18px;
  background: #101827;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand small, .user-chip span { display: block; color: #a8b3c7; font-size: 12px; margin-top: 2px; }
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #fff;
  color: #101827;
  font-weight: 800;
}
.nav { display: grid; gap: 6px; }
.nav a {
  padding: 10px 12px;
  border-radius: 8px;
  color: #d9e2f2;
}
.nav a:hover { background: rgba(255,255,255,.09); color: #fff; }
.sidebar-footer { margin-top: auto; display: grid; gap: 10px; }
.user-chip { padding: 12px; background: rgba(255,255,255,.08); border-radius: 8px; }
.muted-link { color: #a8b3c7; font-size: 14px; }
.main { margin-left: 248px; padding: 28px; min-height: 100vh; }
.login-main { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.page-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 22px;
}
h1, h2, p { margin-top: 0; }
h1 { font-size: 28px; margin-bottom: 6px; }
h2 { font-size: 18px; margin-bottom: 14px; }
.page-head p, .hint, .muted { color: var(--muted); }
.panel, .module-card, .metric, .login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.panel { padding: 18px; }
.narrow { max-width: 560px; }
.login-card { width: min(420px, 100%); padding: 28px; }
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand .brand-mark { margin: 0 auto 14px; background: #101827; color: #fff; }
.stack, .form-grid { display: grid; gap: 14px; }
label { display: grid; gap: 7px; color: #334155; font-weight: 600; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}
textarea { resize: vertical; line-height: 1.6; }
input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 10px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
}
.btn:hover { border-color: #b9c4d4; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .65; cursor: not-allowed; }
.alert { padding: 11px 13px; border-radius: 8px; margin-bottom: 16px; }
.alert.success { background: #e8fff5; color: #047857; border: 1px solid #b7f7dc; }
.alert.danger { background: #fff1f2; color: #be123c; border: 1px solid #fecdd3; }
.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.metric { padding: 18px; }
.metric span { color: var(--muted); display: block; margin-bottom: 8px; }
.metric strong { font-size: 28px; }
.section { margin-top: 24px; }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 12px; }
.section-title h2 { margin: 0; }
.section-title a { color: var(--primary); }
.module-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.module-card { padding: 18px; display: grid; gap: 8px; }
.module-card:hover { border-color: var(--primary); }
.module-card span { color: var(--muted); line-height: 1.5; }
.tool-layout { display: grid; grid-template-columns: minmax(360px, 520px) minmax(0, 1fr); gap: 18px; align-items: start; }
.tool-panel, .output-panel { min-height: 440px; }
.check-row, .action-row, .inline-form, .row-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.check-row label { display: inline-flex; grid-auto-flow: column; align-items: center; gap: 7px; font-weight: 500; }
.check-row input { width: 16px; height: 16px; }
.action-row { margin-top: 14px; }
.action-row .btn { flex: 1; }
.output-list { display: grid; gap: 14px; }
.empty-state { color: var(--muted); padding: 42px 0; text-align: center; }
.output-item { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.output-head { display: flex; justify-content: space-between; gap: 12px; padding: 12px; border-bottom: 1px solid var(--line); }
.output-actions { display: flex; gap: 8px; position: relative; }
pre {
  margin: 0;
  padding: 14px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: #111827;
  color: #e5e7eb;
  border-radius: 6px;
  font-family: Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
}
.output-item pre { border-radius: 0; }
.qr-popover {
  display: none;
  position: absolute;
  right: 0;
  top: 42px;
  z-index: 10;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
}
.qr-wrap:hover .qr-popover { display: block; }
.qr-popover svg { display: block; width: 260px; max-width: 70vw; height: auto; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 700; font-size: 13px; }
.badge { display: inline-flex; border-radius: 999px; padding: 3px 9px; font-size: 12px; }
.badge.success { background: #dcfce7; color: #166534; }
.badge.failed { background: #fee2e2; color: #991b1b; }
.empty { color: var(--muted); text-align: center; }
.record-detail { margin-top: 12px; display: grid; gap: 8px; }
.inline-form { align-items: end; }
.inline-form input, .inline-form select { max-width: 220px; }
.row-form { display: contents; }
details summary { cursor: pointer; color: var(--primary); }
@media (max-width: 900px) {
  .sidebar { position: static; width: auto; border-radius: 0; }
  .main { margin-left: 0; padding: 18px; }
  .page-head, .tool-layout { display: grid; grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: 1fr; }
}

.log-metrics { margin-bottom: 16px; }
.filter-panel { margin-bottom: 18px; }
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  align-items: end;
}
.filter-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}
.logs-table td { vertical-align: top; }
.cell-sub {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}
.badge.role-admin { background: #e0ecff; color: #1d4ed8; }
.badge.role-user { background: #ecfdf5; color: #047857; }
.badge.role-none { background: #f1f5f9; color: #64748b; }
.detail-grid {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 8px 12px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.detail-grid span { color: var(--muted); }
.detail-grid strong { word-break: break-word; }
.log-detail pre { max-height: 360px; }
.logs-table code {
  display: inline-flex;
  padding: 3px 7px;
  border-radius: 6px;
  background: #f1f5f9;
  color: #334155;
}
@media (max-width: 900px) {
  .filter-actions { grid-column: 1 / -1; }
}

.video-parser-shell {
  display: flex;
  justify-content: center;
}
.video-parser-card {
  width: 100%;
  max-width: 760px;
  padding: 26px;
  border-radius: 12px;
  background: radial-gradient(circle at 50% 0%, #18181c 0%, #08080a 100%);
  color: #f5f5f7;
  box-shadow: var(--shadow);
}
.video-parser-input-row {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  background: rgba(255,255,255,.03);
  padding: 8px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,.08);
  box-shadow: inset 0 1px 2px rgba(0,0,0,.35);
}
.video-parser-input-row input {
  flex: 1;
  border: 0;
  background: transparent;
  color: #fff;
  box-shadow: none;
}
.video-parser-input-row input::placeholder { color: #686873; }
.video-parser-primary {
  padding: 12px 28px;
  border-radius: 12px;
  border: 0;
  background: linear-gradient(135deg, #ff2a5f 0%, #c71585 100%);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 4px 15px rgba(255,42,95,.22);
}
.video-parser-primary:disabled { background: #252528; color: #666; box-shadow: none; cursor: not-allowed; }
.video-parser-error {
  display: none;
  padding: 13px 16px;
  border-left: 4px solid #ff453a;
  border-radius: 8px;
  background: rgba(255,69,58,.08);
  color: #ff453a;
  margin-bottom: 18px;
}
.video-parser-error.show { display: block; }
.video-parser-loading { display: none; text-align: center; color: #8a8a93; padding: 28px; }
.video-parser-loading.show { display: block; }
.video-parser-spinner {
  width: 28px;
  height: 28px;
  border: 2px solid rgba(255,255,255,.08);
  border-top-color: #ff2a5f;
  border-right-color: #ff2a5f;
  border-radius: 50%;
  animation: spin .65s linear infinite;
  margin: 0 auto 12px;
}
.video-parser-loading-text { font-size: 14px; letter-spacing: 1px; }
.video-parser-result { display: none; opacity: 0; transform: translateY(10px); transition: all .45s ease; }
.video-parser-result.show { display: block; opacity: 1; transform: translateY(0); }
.video-parser-main-card {
  background: rgba(255,255,255,.035);
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 24px;
  padding: 22px;
  box-shadow: 0 18px 38px rgba(0,0,0,.28);
}
.video-parser-info-bar {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.video-parser-cover {
  width: 64px;
  height: 85px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: #151518;
  border: 1px solid rgba(255,255,255,.06);
  box-shadow: 0 4px 12px rgba(0,0,0,.45);
}
.video-parser-info-text { min-width: 0; }
.video-parser-title {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.video-parser-meta { font-size: 13px; color: #8a8a93; margin-top: 8px; font-family: Menlo, Consolas, monospace; }
.video-parser-video-box {
  background: #000;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.06);
  margin-bottom: 22px;
  min-height: 180px;
  box-shadow: 0 10px 30px rgba(0,0,0,.48);
}
.video-parser-video-box video {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: block;
  object-fit: contain;
  background: #000;
}
.video-parser-video-box.fail-active video { display: none; }
.video-parser-fail-overlay {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 13px;
  min-height: clamp(280px, 56vw, 380px);
  padding: 28px 20px;
  text-align: center;
  background: rgba(10,10,12,.92);
}
.video-parser-fail-overlay.show { display: flex; }
.video-parser-fail-icon {
  width: 48px;
  height: 48px;
  line-height: 48px;
  border-radius: 50%;
  background: rgba(255,42,95,.1);
  border: 1px solid rgba(255,42,95,.24);
  color: #ff2a5f;
  font-size: 20px;
  font-weight: 700;
}
.video-parser-fail-msg { color: #f5f5f7; font-weight: 600; line-height: 1.5; }
.video-parser-qr-container { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 100%; }
#videoParserQrCanvas { background: #fff; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.6); image-rendering: pixelated; max-width: 100%; height: auto; }
.video-parser-qr-hint, .video-parser-fail-hint { font-size: 12px; color: #8a8a93; }
.video-parser-fail-hint { max-width: 280px; color: #66666d; }
.video-parser-copy-btn {
  padding: 10px 22px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(255,255,255,.06);
  color: #e5e5ea;
  cursor: pointer;
}
.video-parser-copy-btn.copied { border-color: rgba(52,199,89,.4); background: rgba(52,199,89,.15); color: #34c759; }
.video-parser-download-row { display: flex; gap: 14px; justify-content: center; }
.video-parser-download-btn {
  flex: 1;
  padding: 14px 22px;
  border-radius: 14px;
  border: 0;
  background: linear-gradient(135deg, #ff2a5f 0%, #c71585 100%);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.video-parser-download-btn.secondary {
  background: rgba(255,255,255,.06);
  color: #f5f5f7;
  border: 1px solid rgba(255,255,255,.09);
}
@media (max-width: 620px) {
  .video-parser-card { padding: 16px; }
  .video-parser-input-row, .video-parser-download-row { display: grid; }
  .video-parser-info-bar { gap: 14px; }
  .video-parser-cover { width: 56px; height: 74px; }
}

/* AISP uploader module */
.aisp-module {
    display: grid;
    gap: 18px;
}

.aisp-hero {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 18px 0 8px;
}

.aisp-hero h1 {
    margin: 0 0 8px;
    font-size: 26px;
    line-height: 1.25;
    color: #172033;
}

.aisp-hero p {
    margin: 0;
    max-width: 760px;
    color: #647084;
    line-height: 1.75;
}

.aisp-badge {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    background: #e8f5ee;
    color: #1d7a45;
    font-size: 13px;
    font-weight: 700;
}

.aisp-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.9fr);
    gap: 18px;
    align-items: start;
}

.aisp-panel {
    background: #fff;
    border: 1px solid #e5eaf2;
    border-radius: 8px;
    padding: 18px;
    box-shadow: 0 8px 24px rgba(17, 31, 54, 0.06);
}

.aisp-panel h2 {
    margin: 0 0 8px;
    font-size: 18px;
    line-height: 1.35;
    color: #172033;
}

.aisp-panel > p {
    margin: 0 0 14px;
    color: #6b7688;
    line-height: 1.7;
}

.aisp-upload-area {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 220px;
    border: 1.5px dashed #b9c6d8;
    border-radius: 8px;
    background: #f8fafc;
    cursor: pointer;
    transition: border-color .18s ease, background .18s ease, box-shadow .18s ease;
}

.aisp-upload-area:hover,
.aisp-upload-area.is-dragover {
    border-color: #2b75e8;
    background: #f1f7ff;
    box-shadow: inset 0 0 0 1px rgba(43, 117, 232, 0.12);
}

.aisp-upload-area input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.aisp-upload-inner {
    display: grid;
    justify-items: center;
    gap: 9px;
    padding: 26px;
    text-align: center;
    pointer-events: none;
}

.aisp-upload-icon {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: #eaf2ff;
    color: #2b75e8;
    font-size: 28px;
    font-weight: 800;
}

.aisp-upload-title {
    color: #162033;
    font-size: 18px;
    font-weight: 800;
}

.aisp-upload-subtitle {
    color: #728096;
    line-height: 1.65;
    font-size: 14px;
}

.aisp-progress {
    margin-top: 14px;
    display: none;
    gap: 9px;
}

.aisp-progress.is-visible {
    display: grid;
}

.aisp-progress-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: #526075;
    font-size: 13px;
}

.aisp-progress-bar {
    height: 9px;
    overflow: hidden;
    border-radius: 999px;
    background: #edf1f7;
}

.aisp-progress-fill {
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #2b75e8, #16a36c);
    transition: width .18s ease;
}

.aisp-result {
    margin-top: 14px;
    display: none;
    grid-template-columns: minmax(0, 1fr) 136px;
    gap: 16px;
    align-items: start;
    padding: 14px;
    border: 1px solid #dbe6f3;
    border-radius: 8px;
    background: #fbfdff;
}

.aisp-result.is-visible {
    display: grid;
}

.aisp-result-label {
    margin-bottom: 7px;
    color: #637083;
    font-size: 13px;
}

.aisp-result-link {
    display: block;
    word-break: break-all;
    color: #1d5fd0;
    line-height: 1.6;
    text-decoration: none;
}

.aisp-result-link:hover {
    text-decoration: underline;
}

.aisp-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}

.aisp-button,
.aisp-secondary-button {
    border: 0;
    border-radius: 7px;
    min-height: 38px;
    padding: 0 14px;
    font-weight: 800;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}

.aisp-button {
    background: #1f6fe5;
    color: #fff;
    box-shadow: 0 7px 16px rgba(31, 111, 229, .22);
}

.aisp-secondary-button {
    background: #eef3f9;
    color: #243044;
}

.aisp-button:hover,
.aisp-secondary-button:hover {
    transform: translateY(-1px);
}

.aisp-qr-box {
    display: grid;
    gap: 8px;
    justify-items: center;
    color: #6d7a8e;
    font-size: 12px;
    text-align: center;
}

.aisp-qr-box img,
.aisp-qr-canvas canvas {
    width: 120px;
    height: 120px;
    border: 1px solid #edf1f6;
    border-radius: 6px;
    background: #fff;
}

.aisp-history {
    margin-top: 18px;
}

.aisp-history h3 {
    margin: 0 0 10px;
    font-size: 15px;
    color: #273248;
}

.aisp-history-list {
    display: grid;
    gap: 9px;
}

.aisp-history-empty {
    color: #7a8698;
    font-size: 13px;
    padding: 12px;
    border-radius: 8px;
    background: #f7f9fc;
}

.aisp-history-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 12px;
    border: 1px solid #e6ebf2;
    border-radius: 8px;
    background: #fff;
}

.aisp-history-name {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #1f2b3d;
    font-weight: 800;
}

.aisp-history-meta {
    margin-top: 4px;
    color: #748095;
    font-size: 12px;
}

.aisp-textarea {
    width: 100%;
    min-height: 150px;
    resize: vertical;
    border: 1px solid #dbe3ef;
    border-radius: 8px;
    padding: 12px;
    color: #1f2a3b;
    line-height: 1.65;
    outline: none;
}

.aisp-textarea:focus,
.aisp-select:focus {
    border-color: #2b75e8;
    box-shadow: 0 0 0 3px rgba(43, 117, 232, .12);
}

.aisp-form-row {
    display: grid;
    gap: 7px;
    margin-top: 12px;
}

.aisp-form-row label {
    color: #536176;
    font-size: 13px;
    font-weight: 800;
}

.aisp-select {
    width: 100%;
    min-height: 38px;
    border: 1px solid #dbe3ef;
    border-radius: 7px;
    padding: 0 10px;
    background: #fff;
    color: #1f2a3b;
}

.aisp-qr-preview {
    display: grid;
    place-items: center;
    min-height: 242px;
    margin-top: 14px;
    border: 1px solid #e5ebf3;
    border-radius: 8px;
    background: #f8fafc;
}

.aisp-qr-placeholder {
    color: #7d8796;
    text-align: center;
    line-height: 1.7;
}

.aisp-qr-canvas {
    display: grid;
    place-items: center;
}

.aisp-qr-canvas canvas {
    width: 190px;
    height: 190px;
}

.aisp-toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 1000;
    max-width: min(420px, calc(100vw - 32px));
    transform: translateX(-50%) translateY(16px);
    opacity: 0;
    pointer-events: none;
    padding: 11px 16px;
    border-radius: 8px;
    background: rgba(20, 31, 46, .94);
    color: #fff;
    font-size: 14px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, .22);
    transition: opacity .18s ease, transform .18s ease;
}

.aisp-toast.is-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

@media (max-width: 980px) {
    .aisp-hero {
        flex-direction: column;
    }

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

@media (max-width: 640px) {
    .aisp-panel {
        padding: 14px;
    }

    .aisp-result {
        grid-template-columns: 1fr;
    }

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

    .aisp-actions {
        display: grid;
    }

    .aisp-button,
    .aisp-secondary-button {
        width: 100%;
    }
}

.form-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.module-permission-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  min-width: 340px;
}
.module-permission-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: #334155;
  font-size: 13px;
  white-space: nowrap;
}
.module-permission-item.is-sensitive {
  border-color: #fed7aa;
  background: #fff7ed;
  color: #9a3412;
}
.module-permission-item input {
  width: auto;
  min-width: 14px;
}
.module-permission-item input:disabled + span {
  color: #64748b;
}
.snapshot-pretty {
  white-space: pre-wrap;
  word-break: break-word;
}
