/* ========================================================
   Dashboard / App layout
   ======================================================== */

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: calc(100vh - var(--header-h));
}

.app-sidebar {
  background: #fff;
  border-right: 1px solid var(--border);
  padding: var(--space-3) var(--space-2);
  display: flex; flex-direction: column;
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
}
.app-sidebar h4 {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-light); font-weight: 600; margin: var(--space-2) 8px var(--space-1);
}
.app-sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.app-sidebar nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; color: var(--text); border-radius: var(--radius);
  font-size: 0.9375rem; font-weight: 500; min-height: 44px;
  transition: background 150ms;
}
.app-sidebar nav a:hover { background: var(--bg-alt); color: var(--text); }
.app-sidebar nav a.is-active { background: rgba(59,130,246,0.10); color: var(--accent); }
.app-sidebar nav a i { width: 20px; text-align: center; color: var(--text-muted); }
.app-sidebar nav a.is-active i { color: var(--accent); }

.app-main {
  padding: var(--space-3);
  background: var(--bg);
}
.app-main h1 { font-size: 1.875rem; margin-bottom: 6px; }
.app-main h1 + .lead { color: var(--text-muted); margin-bottom: var(--space-3); }

.stats-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-2); margin-bottom: var(--space-3); align-items: stretch;
}
.stat-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-2); box-shadow: var(--shadow-sm);
  display: flex; align-items: center; gap: var(--space-2);
}
.stat-card .stat-icon {
  width: 48px; height: 48px; border-radius: 12px;
  background: rgba(59,130,246,0.10); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 1.25rem;
  flex-shrink: 0;
}
.stat-card .stat-meta { flex: 1; min-width: 0; }
.stat-card .stat-num { font-size: 1.5rem; font-weight: 800; color: var(--text); line-height: 1.1; }
.stat-card .stat-label { font-size: 0.8125rem; color: var(--text-muted); margin-top: 2px; }

.usage-meter {
  margin-top: 8px; height: 8px; background: var(--bg-alt); border-radius: 999px; overflow: hidden;
}
.usage-meter > span {
  display: block; height: 100%; background: var(--accent-gradient); border-radius: 999px;
  transition: width 400ms ease;
}

.panel {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-3); box-shadow: var(--shadow-sm); min-height: 180px;
  display: flex; flex-direction: column;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-2); gap: var(--space-2); flex-wrap: wrap;
}
.panel-head h2 { font-size: 1.25rem; margin: 0; }
.panel-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--space-2); align-items: start;
}

.empty-state {
  flex: 1; min-height: 180px;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  gap: 8px; text-align: center; color: var(--text-muted);
}
.empty-state i { font-size: 2rem; color: var(--text-light); }
.empty-state p { font-size: 0.9rem; margin: 0; }

table.data-table {
  width: 100%; border-collapse: collapse; font-size: 0.9rem;
}
table.data-table th, table.data-table td {
  text-align: left; padding: 12px; border-bottom: 1px solid var(--border);
}
table.data-table th { font-size: 0.8125rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
table.data-table tbody tr:hover { background: var(--bg-alt); }
table.data-table .row-actions { display: inline-flex; gap: 6px; align-items: center; }
table.data-table .row-actions .btn { min-height: 32px; padding: 6px 12px; font-size: 0.8125rem; }

.upgrade-banner {
  background: linear-gradient(135deg, #1e293b, #0a1628);
  color: #fff; border-radius: var(--radius-lg);
  padding: var(--space-3); position: relative; overflow: hidden;
  margin-bottom: var(--space-3);
}
.upgrade-banner::before {
  content: ''; position: absolute; right: -10%; top: -50%; width: 50%; aspect-ratio: 1;
  background: radial-gradient(circle, rgba(139,92,246,0.30), transparent 60%);
}
.upgrade-banner h3 { color: #fff; margin: 0 0 8px; }
.upgrade-banner p { color: rgba(255,255,255,0.78); margin: 0 0 var(--space-2); }
.upgrade-banner .btn { background: var(--accent-gradient); color: #fff; border: none; }

.status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600;
}
.status-pending    { background: #fef3c7; color: #92400e; }
.status-processing { background: #dbeafe; color: #1e40af; }
.status-complete   { background: #dcfce7; color: #065f46; }
.status-failed     { background: #fee2e2; color: #991b1b; }

.plan-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.plan-pill.free { background: var(--bg-alt); color: var(--text-muted); }
.plan-pill.pro  { background: var(--accent-gradient); color: #fff; }

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border-strong); border-radius: var(--radius-lg);
  padding: var(--space-5); text-align: center;
  background: #fff; cursor: pointer; transition: all 200ms;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  min-height: 280px; justify-content: center;
}
.upload-zone:hover, .upload-zone.is-drag {
  border-color: var(--accent); background: rgba(59,130,246,0.04);
}
.upload-zone i { font-size: 3rem; color: var(--accent); }
.upload-zone h3 { margin: 0; }
.upload-zone p { color: var(--text-muted); margin: 0; }
.upload-zone .file-types { font-size: 0.875rem; }
.upload-zone input[type="file"] { display: none; }

.upload-progress {
  margin-top: var(--space-3); padding: var(--space-2);
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  display: none;
}
.upload-progress.is-visible { display: block; }
.upload-progress-bar {
  height: 8px; background: var(--bg-alt); border-radius: 999px; overflow: hidden;
  margin-top: 8px;
}
.upload-progress-bar > span {
  display: block; height: 100%; background: var(--accent); transition: width 200ms;
}

/* Document Analysis tabs */
.doc-header {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-2) var(--space-3); margin-bottom: var(--space-2);
  display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
}
.doc-header .doc-icon {
  width: 56px; height: 56px; border-radius: 12px; background: var(--accent-gradient);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
  flex-shrink: 0;
}
.doc-header .doc-meta { flex: 1; min-width: 0; }
.doc-header h1 { font-size: 1.25rem; margin: 0; word-break: break-word; }
.doc-header .meta-row { font-size: 0.8125rem; color: var(--text-muted); display: flex; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.doc-header .doc-actions { display: flex; gap: 8px; }

.tab-bar {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border-bottom: none; padding: 0 var(--space-2); display: flex;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  position: sticky; top: var(--header-h); z-index: 10;
}
.tab-bar button {
  background: transparent; border: none; padding: 16px 18px; font-size: 0.9375rem;
  font-weight: 500; color: var(--text-muted); cursor: pointer; white-space: nowrap;
  position: relative; transition: color 150ms;
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px;
}
.tab-bar button:hover { color: var(--text); }
.tab-bar button.is-active { color: var(--accent); font-weight: 600; }
.tab-bar button.is-active::after {
  content: ''; position: absolute; left: 12px; right: 12px; bottom: 0; height: 3px;
  background: var(--accent); border-radius: 999px 999px 0 0;
}

.tab-panes {
  background: #fff; border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg); padding: var(--space-3);
  min-height: 400px;
}
.tab-pane { display: none; animation: fadeIn 200ms ease; }
.tab-pane.is-active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: none;} }

.skeleton {
  background: linear-gradient(90deg, var(--bg-alt) 0%, #e6ecf3 50%, var(--bg-alt) 100%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite;
  border-radius: var(--radius); height: 16px; margin: 6px 0;
}
.skeleton.lg { height: 32px; }
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

.kp-list { list-style: none; padding: 0; margin: 0; }
.kp-list li { padding: 12px 0 12px 32px; position: relative; border-bottom: 1px solid var(--border); }
.kp-list li:last-child { border-bottom: none; }
.kp-list li::before {
  content: '\f00c'; font-family: 'Font Awesome 6 Free'; font-weight: 900;
  position: absolute; left: 0; top: 14px; color: var(--success);
  width: 22px; height: 22px; background: rgba(16,185,129,0.10); border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 0.7rem;
}

/* Risk table */
.risk-table th, .risk-table td { vertical-align: top; }
.sev-pill {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}
.sev-pill.critical { background: var(--danger); color: #fff; }
.sev-pill.high     { background: #f97316; color: #fff; }
.sev-pill.medium   { background: var(--warning); color: #fff; }
.sev-pill.low      { background: var(--success); color: #fff; }

/* PII donut */
.pii-summary {
  display: grid; grid-template-columns: 220px 1fr; gap: var(--space-3);
  align-items: center; margin-bottom: var(--space-3);
}
.pii-donut {
  width: 200px; height: 200px; border-radius: 50%;
  background: conic-gradient(var(--success) 0% var(--score), var(--bg-alt) var(--score) 100%);
  display: flex; align-items: center; justify-content: center; position: relative;
}
.pii-donut::before {
  content: ''; position: absolute; inset: 16px; background: #fff; border-radius: 50%;
}
.pii-donut span {
  position: relative; font-size: 2.5rem; font-weight: 800; color: var(--text);
}
.pii-frameworks { display: flex; gap: 8px; flex-wrap: wrap; }
.pii-frameworks .framework-badge {
  padding: 8px 12px; border-radius: 8px; font-size: 0.875rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}
.framework-compliant   { background: #dcfce7; color: #065f46; }
.framework-at-risk     { background: #fef3c7; color: #92400e; }
.framework-non-compliant { background: #fee2e2; color: #991b1b; }
@media (max-width: 767px) {
  .pii-summary { grid-template-columns: 1fr; }
  .pii-donut { margin: 0 auto; }
}

/* Timeline */
.timeline-list { position: relative; padding-left: 32px; }
.timeline-list::before {
  content: ''; position: absolute; left: 12px; top: 8px; bottom: 8px;
  width: 2px; background: var(--border);
}
.timeline-item {
  position: relative; padding: var(--space-2); margin-bottom: var(--space-2);
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  border-left: 4px solid var(--text-light);
}
.timeline-item::before {
  content: ''; position: absolute; left: -25px; top: 22px;
  width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--text-light);
}
.timeline-item.urgency-past    { border-left-color: var(--text-light); opacity: 0.7; }
.timeline-item.urgency-urgent  { border-left-color: var(--danger); }
.timeline-item.urgency-urgent::before  { border-color: var(--danger); }
.timeline-item.urgency-upcoming{ border-left-color: var(--accent); }
.timeline-item.urgency-upcoming::before{ border-color: var(--accent); }
.timeline-item.urgency-future  { border-left-color: var(--success); }
.timeline-item.urgency-future::before  { border-color: var(--success); }
.timeline-item h4 { margin: 0 0 4px; font-size: 1rem; }
.timeline-item .timeline-date { font-size: 0.8125rem; color: var(--text-muted); margin-bottom: 6px; }
.timeline-item p { margin: 0; font-size: 0.9rem; color: var(--text); }

/* Chat */
.chat-shell {
  display: flex; flex-direction: column;
  height: 60vh; min-height: 400px;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: var(--bg);
}
.chat-messages { flex: 1; overflow-y: auto; padding: var(--space-2); display: flex; flex-direction: column; gap: 12px; }
.chat-msg { max-width: 85%; padding: 12px 16px; border-radius: 16px; font-size: 0.9375rem; line-height: 1.5; }
.chat-msg.from-user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.from-ai { align-self: flex-start; background: #fff; color: var(--text); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-msg .source {
  margin-top: 8px; padding: 8px 12px; background: var(--bg-alt); border-left: 3px solid var(--accent);
  border-radius: 6px; font-style: italic; color: var(--text-muted); font-size: 0.875rem;
}
.chat-input-row { display: flex; gap: 8px; padding: var(--space-2); border-top: 1px solid var(--border); background: #fff; }
.chat-input-row input { flex: 1; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: var(--radius); }
.chat-input-row input:focus { border-color: var(--accent); outline: none; }

/* Compare */
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
@media (max-width: 767px) { .compare-grid { grid-template-columns: 1fr; } }

@media (max-width: 1023px) {
  .app-shell { grid-template-columns: 1fr; }
  /* Grid items default to min-width:auto which prevents shrinking below content
     intrinsic width. The sidebar's wide horizontal nav was pushing the whole grid
     wider than the viewport, hiding doc-header content off-screen and clipping
     tab content. min-width:0 + max-width:100vw keeps each grid row contained. */
  .app-shell > .app-sidebar,
  .app-shell > .app-main {
    min-width: 0;
    max-width: 100vw;
  }
  .app-sidebar { position: static; height: auto; flex-direction: row; overflow-x: auto; padding: var(--space-2); border-right: none; border-bottom: 1px solid var(--border); }
  .app-sidebar h4 { display: none; }
  .app-sidebar nav { flex-direction: row; gap: 4px; flex: 0 0 auto; }
  .app-sidebar nav a { white-space: nowrap; padding: 8px 12px; flex: 0 0 auto; }
}
