﻿/* ============================================================
   KYSTENO — audit.css
   Audit Log Viewer Styles — Build 31
   ============================================================ */

/* ── Panel shell ──────────────────────────────────────────── */

#auditLogPanel {
  display: none;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  position: relative;
  flex: 1;
  max-height: 100vh;
}

/* ── Header ───────────────────────────────────────────────── */

.audit-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 28px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.audit-header-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(99, 102, 241, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6366f1;
  flex-shrink: 0;
}

.audit-header-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.audit-header-count {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--card-bg);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 20px;
}

.audit-header-close {
  width: 30px;
  height: 30px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.audit-header-close:hover {
  background: var(--hover-bg);
  color: var(--text);
}

/* ── Filter bar ───────────────────────────────────────────── */

.audit-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.audit-filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.audit-filter-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.audit-filter-select,
.audit-filter-input,
.audit-filter-date {
  font-size: 12px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--text);
  height: 30px;
  outline: none;
  transition: border-color 0.15s;
}
.audit-filter-select:focus,
.audit-filter-input:focus,
.audit-filter-date:focus {
  border-color: #6366f1;
}

.audit-filter-input {
  width: 160px;
}

.audit-filter-date {
  width: 128px;
}

.audit-filter-btn {
  height: 30px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.audit-filter-btn--apply {
  background: #6366f1;
  border-color: #6366f1;
  color: #fff;
}
.audit-filter-btn--apply:hover {
  background: #4f46e5;
}

.audit-filter-btn--clear {
  background: var(--card-bg);
  color: var(--text-muted);
}
.audit-filter-btn--clear:hover {
  background: var(--hover-bg);
  color: var(--text);
}

/* ── Content area (table + detail drawer side-by-side) ───── */

.audit-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Table area ───────────────────────────────────────────── */

.audit-table-wrap {
  flex: 1;
  overflow-y: auto;
  min-width: 0;
  position: relative;
  height: 100%;
}


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

.audit-table thead th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--card-bg, #f3f4f6);
  position: sticky;
  top: 0;
  z-index: 3;
  white-space: nowrap;
  box-shadow: inset 0 -1px 0 var(--border);
}

.audit-col-time   { width: 110px;  padding-left: 28px !important; }
.audit-col-actor  { width: 200px;  }
.audit-col-action { width: 150px;  }
.audit-col-target { width: 200px;  }
.audit-col-detail { }

.audit-row {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.audit-row:hover {
  background: var(--hover-bg);
}
.audit-row:last-child {
  border-bottom: none;
}

.audit-row td {
  padding: 10px 16px;
  vertical-align: middle;
}

.audit-row td:first-child {
  padding-left: 28px;
}

/* Skeleton */
.audit-row-skeleton td {
  padding: 12px 16px;
}
.audit-row-skeleton td:first-child {
  padding-left: 28px;
}
.audit-skel {
  height: 14px;
  border-radius: 4px;
  background: var(--border);
  animation: auditSkelPulse 1.4s ease-in-out infinite;
}
@keyframes auditSkelPulse {
  0%, 100% { opacity: 0.5; }
  50%       { opacity: 1;   }
}

.audit-time {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Actor chip */
.audit-actor {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.audit-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.audit-actor-email {
  font-size: 12px;
  color: var(--text);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Target link */
.audit-target {
  font-size: 12px;
  color: var(--text);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
}
.audit-target-link {
  color: #6366f1;
  cursor: pointer;
  text-decoration: none;
}
.audit-target-link:hover {
  text-decoration: underline;
}
.audit-target-empty {
  color: var(--text-muted);
  font-size: 12px;
}
.audit-type-chip {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  margin-left: 6px;
  vertical-align: middle;
}

/* Detail summary */
.audit-detail {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
}

.audit-load-error {
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── Action badges ────────────────────────────────────────── */

.audit-badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.audit-badge--created    { background: rgba(34,197,94,0.12);   color: #16a34a; border: 1px solid rgba(34,197,94,0.25); }
.audit-badge--edited     { background: rgba(59,130,246,0.12);  color: #2563eb; border: 1px solid rgba(59,130,246,0.25); }
.audit-badge--deleted    { background: rgba(239,68,68,0.12);   color: #dc2626; border: 1px solid rgba(239,68,68,0.25); }
.audit-badge--moved      { background: rgba(249,115,22,0.12);  color: #ea580c; border: 1px solid rgba(249,115,22,0.25); }
.audit-badge--restored   { background: rgba(79, 70, 229,0.12);  color: var(--primary-hover); border: 1px solid rgba(79, 70, 229,0.25); }
.audit-badge--permission { background: rgba(234,179,8,0.12);   color: #b45309; border: 1px solid rgba(234,179,8,0.25); }
.audit-badge--member     { background: rgba(139,92,246,0.12);  color: #7c3aed; border: 1px solid rgba(139,92,246,0.25); }
.audit-badge--review     { background: rgba(79, 70, 229,0.12);  color: var(--primary-hover); border: 1px solid rgba(79, 70, 229,0.25); }
.audit-badge--approved   { background: rgba(34,197,94,0.12);   color: #16a34a; border: 1px solid rgba(34,197,94,0.25); }
.audit-badge--default    { background: var(--card-bg);         color: var(--text-muted); border: 1px solid var(--border); }

/* ── Empty state ──────────────────────────────────────────── */

#auditEmptyState {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 80px 24px;
  color: var(--text-muted);
  text-align: center;
}
.audit-empty-icon {
  opacity: 0.3;
  color: var(--text-muted);
}
.audit-empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.audit-empty-sub {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 300px;
  line-height: 1.5;
}

/* ── Load more ────────────────────────────────────────────── */

.audit-load-more-wrap {
  padding: 16px 28px 24px;
  text-align: center;
}

#auditLoadMore {
  display: none;
  padding: 8px 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
#auditLoadMore:hover {
  background: var(--hover-bg);
}

/* ── Detail drawer ────────────────────────────────────────── */

#auditDetailDrawer {
  width: 0;
  overflow: hidden;
  transition: width 0.22s ease;
  border-left: 1px solid transparent;
  background: var(--card-bg);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
#auditDetailDrawer.open {
  width: 340px;
  border-left-color: var(--border);
  overflow-y: auto;
}

.audit-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.audit-drawer-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.audit-drawer-close {
  width: 26px;
  height: 26px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  transition: background 0.15s;
}
.audit-drawer-close:hover {
  background: var(--hover-bg);
  color: var(--text);
}

#auditDetailContent {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.audit-detail-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.audit-detail-time {
  font-size: 12px;
  color: var(--text-muted);
}

.audit-detail-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.audit-detail-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.audit-detail-section {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.audit-detail-json {
  font-size: 11px;
  font-family: ui-monospace, 'SF Mono', monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text);
  line-height: 1.5;
  margin: 0;
  max-height: 200px;
  overflow-y: auto;
}

.audit-detail-code {
  font-size: 10px;
  font-family: ui-monospace, 'SF Mono', monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 7px;
  color: var(--text-muted);
  word-break: break-all;
}

/* Diff table */
.audit-diff-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
.audit-diff-table th {
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}
.audit-diff-table td {
  padding: 5px 8px;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 11px;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.audit-diff-key    { color: var(--text); font-weight: 500; }
.audit-diff-before { color: #dc2626; background: rgba(239,68,68,0.06); }
.audit-diff-after  { color: #16a34a; background: rgba(34,197,94,0.06); }

/* ── Gutter: page activity section ───────────────────────── */

#gutterAuditSection {
  display: none;
}

.audit-gutter-loading,
.audit-gutter-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 0;
}

.audit-gutter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
}
.audit-gutter-row:last-child {
  border-bottom: none;
}

.audit-gutter-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  flex-shrink: 0;
}

.audit-gutter-meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.audit-gutter-actor {
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.audit-gutter-time {
  font-size: 11px;
  color: var(--text-muted);
}

.audit-gutter-see-all {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  font-size: 12px;
  color: #6366f1;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-weight: 500;
}
.audit-gutter-see-all:hover {
  text-decoration: underline;
}

/* ── SQL info banner (shown when table missing) ───────────── */

.audit-setup-banner {
  margin: 16px 28px;
  padding: 14px 18px;
  background: rgba(234,179,8,0.08);
  border: 1px solid rgba(234,179,8,0.3);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}
.audit-setup-banner strong {
  font-weight: 600;
}
.audit-setup-banner code {
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 11px;
  background: rgba(0,0,0,0.07);
  padding: 1px 5px;
  border-radius: 3px;
}

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 768px) {
  .audit-filters {
    padding: 10px 16px;
    gap: 6px;
  }
  .audit-filter-input  { width: 120px; }
  .audit-filter-date   { width: 110px; }
  .audit-header        { padding: 14px 16px 12px; }
  .audit-col-detail    { display: none; }
  .audit-col-actor     { width: 160px; }
  #auditDetailDrawer.open { width: 100%; position: absolute; right: 0; top: 0; bottom: 0; z-index: 10; }
}
