/* Tahliliy app shell — uses tokens from tokens.css */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body.app-body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: var(--lh);
  overflow-x: hidden;
}

[hidden] { display: none !important; }

a { color: var(--primary); }
img, svg, video { max-width: 100%; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 260px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border);
  z-index: 100;
}
.sidebar-brand {
  padding: var(--space-6) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-logo {
  display: block;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: 0.08em;
  color: var(--text);
  text-decoration: none;
  text-transform: uppercase;
}
.sidebar-logo span {
  color: var(--primary);
}
.sidebar-subtitle {
  margin: var(--space-2) 0 0;
  font-size: var(--fs-xs);
  line-height: 1.35;
  color: var(--muted);
}
.sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-4) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.nav-link {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 var(--space-4);
  border-radius: 999px;
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.nav-link:hover { background: var(--surface); color: var(--text); }
.nav-link.active,
.nav-link.active:hover {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* ---------- Main ---------- */
.app-main {
  margin-left: 260px;
  min-height: 100vh;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--header-h);
  padding: var(--space-2) var(--space-6);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar:not(:has(.topbar-search)) { display: none; }
.topbar-search { flex: 1 1 auto; max-width: 480px; }
.input-search {
  width: 100%;
  min-height: 40px;
  padding: 0 var(--space-4);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  font: inherit;
  font-size: var(--fs-sm);
}
.input-search::placeholder { color: var(--muted); }
.input-search:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px var(--glow-blue); }

.app-content {
  flex: 1 1 auto;
  width: 100%;
  max-width: var(--container-wide);
  margin: 0 auto;
  padding: var(--space-8) var(--space-6);
  min-width: 0;
}

/* Hamburger (mobile only) */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: var(--tap);
  height: var(--tap);
  padding: 0 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
}
.hamburger span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 90;
}

/* ---------- Utilities ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}
.stat-card .stat-value {
  font-family: var(--font-heading);
  font-size: var(--fs-stat);
  font-weight: 800;
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
}
.label-caps {
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: 0 var(--space-5);
  background: var(--primary);
  color: #fff;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-elevated); }

.badge-positive, .badge-neutral, .badge-negative,
.badge-risk-high, .badge-risk-medium, .badge-risk-low,
.tier-ordinary, .tier-expert, .tier-priority {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
}
.badge-positive { background: var(--positive-soft); color: var(--positive); }
.badge-neutral  { background: var(--neutral-soft);  color: var(--muted); }
.badge-negative { background: var(--negative-soft); color: var(--negative); }
.badge-risk-high   { background: var(--risk-high-soft);   color: var(--risk-high); }
.badge-risk-medium { background: var(--risk-medium-soft); color: var(--risk-medium); }
.badge-risk-low    { background: var(--risk-low-soft);    color: var(--risk-low); }

.tier-ordinary { background: var(--primary-soft);       color: var(--primary-hover); }
.tier-expert   { background: var(--tier-priority-soft); color: var(--tier-priority); }
.tier-priority { background: var(--tier-urgent-soft);   color: var(--tier-urgent); }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.table-wrap table { width: 100%; border-collapse: collapse; }
.table-wrap th, .table-wrap td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.table-wrap th {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--muted);
}

.mobile-cards { display: none; flex-direction: column; gap: var(--space-3); }
.mobile-cards > * {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
}

.blur-filler { filter: blur(5px); user-select: none; pointer-events: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1279px) {
  .app-content { padding: var(--space-6) var(--space-5); }
}

@media (max-width: 1023px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform var(--transition-slow);
    box-shadow: var(--shadow-lg);
    width: min(280px, 86vw);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open { overflow: hidden; }
  .app-main { margin-left: 0; }
  .hamburger { display: inline-flex; }
  /* On mobile the topbar always shows (hamburger needed) */
  .topbar:not(:has(.topbar-search)) {
    display: flex;
    border-bottom: 0;
    background: transparent;
    position: static;
    padding-bottom: 0;
  }
  .topbar { padding: var(--space-2) var(--space-4); }
}

@media (max-width: 767px) {
  .app-content { padding: var(--space-5) var(--space-4); }
  .table-wrap.has-cards { display: none; }
  .mobile-cards { display: flex; }
  .card { padding: var(--space-5); }
}

@media (max-width: 479px) {
  .app-content { padding: var(--space-4) var(--space-3); }
  .topbar-search { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .nav-link, .btn { transition: none; }
}

/* ---------- Print ---------- */
@media print {
  :root {
    --bg: #fff; --surface: #fff; --surface-elevated: #fff;
    --text: #0F172A; --muted: #475569; --border: #CBD5E1;
  }
  body.app-body { background: #fff; color: #0F172A; overflow: visible; }
  .sidebar, .sidebar-overlay, .hamburger, .topbar,
  .sticky-actions, [data-sticky-actions] { display: none !important; }
  .app-main { margin-left: 0; }
  .app-content { max-width: none; padding: 0; }
  .card, .stat-card { box-shadow: none; break-inside: avoid; }
  .table-wrap { overflow: visible; }
  .table-wrap.has-cards { display: block; }
  .mobile-cards { display: none; }
}
