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

:root {
  --bg-start: #ede9fe;
  --bg-mid: #f5f3ff;
  --bg-end: #fce7f3;
  --sidebar: rgba(255, 255, 255, 0.72);
  --sidebar-border: rgba(124, 58, 237, 0.1);
  --card: #ffffff;
  --foreground: #1e1b4b;
  --muted: #64748b;
  --muted-soft: #94a3b8;
  --border: rgba(15, 23, 42, 0.08);
  --primary: #7c3aed;
  --primary-soft: rgba(124, 58, 237, 0.1);
  --radius: 12px;
  --radius-lg: 16px;
  --sidebar-w: 16rem;
  --sans: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 4px 16px rgba(76, 29, 149, 0.08);
}

html {
  font-size: 16px;
}

body {
  font-family: var(--sans);
  color: var(--foreground);
  background: linear-gradient(145deg, var(--bg-start) 0%, var(--bg-mid) 42%, var(--bg-end) 100%);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
  border: none;
  background: none;
  cursor: pointer;
  color: inherit;
}

img {
  display: block;
  max-width: 100%;
}

/* Layout */
.app {
  min-height: 100vh;
}

.layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  backdrop-filter: blur(16px);
  border-right: 1px solid var(--sidebar-border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  margin: 8px;
  border-radius: var(--radius);
}

.sidebar-brand img {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.sidebar-brand span {
  font-weight: 600;
  font-size: 0.9375rem;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}

.sidebar-label {
  padding: 8px 12px 6px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
}

.nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item > a,
.nav-item > button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--foreground);
  transition: background 0.15s;
}

.nav-item > a:hover,
.nav-item > button:hover {
  background: rgba(124, 58, 237, 0.08);
}

.nav-item.is-open > button {
  background: rgba(124, 58, 237, 0.08);
  font-weight: 500;
}

.nav-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.75;
}

.nav-chevron {
  margin-left: auto;
  transition: transform 0.2s;
}

.nav-item.is-open .nav-chevron {
  transform: rotate(90deg);
}

.nav-sub {
  list-style: none;
  margin: 2px 0 4px 12px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}

.nav-sub a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.8125rem;
  color: var(--foreground);
}

.nav-sub a:hover {
  background: rgba(124, 58, 237, 0.06);
}

.nav-sub a.is-active {
  background: rgba(124, 58, 237, 0.12);
  font-weight: 500;
}

.sidebar-user {
  padding: 8px;
  margin: 8px;
  border-top: 1px solid var(--border);
}

.sidebar-user-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border-radius: var(--radius);
  text-align: left;
}

.sidebar-user-btn:hover {
  background: rgba(124, 58, 237, 0.06);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
}

.user-meta {
  min-width: 0;
  flex: 1;
}

.user-name {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  display: block;
  font-size: 0.6875rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main */
.main-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.45);
  backdrop-filter: blur(12px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--foreground);
  transition: background 0.15s;
}

.icon-btn:hover {
  background: rgba(124, 58, 237, 0.08);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.header-divider {
  width: 1px;
  height: 16px;
  background: var(--border);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  color: var(--muted);
}

.breadcrumb a:hover {
  color: var(--foreground);
}

.breadcrumb-current {
  color: var(--foreground);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.notif-wrap {
  position: relative;
}

.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Dashboard */
.dashboard {
  flex: 1;
  padding: 24px;
}

.page-head {
  margin-bottom: 24px;
}

.page-head h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.page-head p {
  font-size: 0.875rem;
  color: var(--muted);
  max-width: 42rem;
}

.page-head strong {
  color: var(--foreground);
  font-weight: 500;
}

/* KPI grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.kpi-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-height: 96px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border-left: 4px solid transparent;
  transition: box-shadow 0.2s;
}

.kpi-card:hover {
  box-shadow: var(--shadow);
}

.kpi-card--emerald { border-left-color: #10b981; }
.kpi-card--sky { border-left-color: #0ea5e9; }
.kpi-card--amber { border-left-color: #f59e0b; }
.kpi-card--violet { border-left-color: #8b5cf6; }
.kpi-card--fuchsia { border-left-color: #d946ef; }
.kpi-card--rose { border-left-color: #f43f5e; }
.kpi-card--cyan { border-left-color: #06b6d4; }

.kpi-body {
  min-width: 0;
}

.kpi-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  line-height: 1.3;
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 4px;
}

.kpi-desc {
  font-size: 0.6875rem;
  color: var(--muted-soft);
  line-height: 1.35;
}

.kpi-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kpi-icon svg {
  width: 20px;
  height: 20px;
}

.kpi-icon--emerald { background: rgba(16, 185, 129, 0.1); color: #059669; }
.kpi-icon--sky { background: rgba(14, 165, 233, 0.1); color: #0284c7; }
.kpi-icon--amber { background: rgba(245, 158, 11, 0.1); color: #d97706; }
.kpi-icon--violet { background: rgba(139, 92, 246, 0.1); color: #7c3aed; }
.kpi-icon--fuchsia { background: rgba(217, 70, 239, 0.1); color: #c026d3; }
.kpi-icon--rose { background: rgba(244, 63, 94, 0.1); color: #e11d48; }
.kpi-icon--cyan { background: rgba(6, 182, 212, 0.1); color: #0891b2; }

/* Panels */
.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.panel-head {
  padding: 20px 24px 0;
}

.panel-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.panel-sub {
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.45;
}

.panel-body {
  padding: 16px 24px 24px;
}

/* Chart — materiales por área */
.bar-chart {
  padding: 8px 0;
}

.bar-chart-axis {
  display: flex;
  justify-content: space-between;
  padding: 0 0 8px 120px;
  font-size: 0.6875rem;
  color: var(--muted);
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.bar-label {
  width: 108px;
  flex-shrink: 0;
  font-size: 0.6875rem;
  color: var(--muted);
  text-align: right;
}

.bar-track {
  flex: 1;
  height: 32px;
  position: relative;
  border-top: 1px dashed rgba(148, 163, 184, 0.35);
}

.bar-fill {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 32px;
  border-radius: 0 6px 6px 0;
  background: linear-gradient(90deg, #8b5cf6, #c084fc);
  min-width: 24%;
}

.empty-state {
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 12px;
}

.link-primary {
  display: block;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--primary);
}

.link-primary:hover {
  text-decoration: underline;
}

/* Work orders chart */
.col-chart {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 48px;
  height: 140px;
  padding: 16px 24px 0;
  border-bottom: 1px dashed rgba(148, 163, 184, 0.35);
}

.col-bar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.col-bar {
  width: 56px;
  border-radius: 8px 8px 0 0;
  background: var(--primary);
}

.col-bar--short { height: 28px; }
.col-bar--empty { height: 4px; background: #e2e8f0; }

.col-label {
  font-size: 0.6875rem;
  color: var(--muted);
  text-align: center;
  max-width: 100px;
  line-height: 1.3;
}

/* Table */
.data-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: #fafafa;
}

.data-table th.num,
.data-table td.num {
  text-align: right;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.data-table td.mono {
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
}

.data-table tbody tr:hover {
  background: rgba(124, 58, 237, 0.03);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* Portfolio back — subtle */
.back-portfolio {
  position: fixed;
  bottom: 20px;
  left: calc(var(--sidebar-w) + 20px);
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  transition: color 0.15s, box-shadow 0.15s;
}

.back-portfolio:hover {
  color: var(--primary);
  box-shadow: var(--shadow);
}

.back-portfolio svg {
  width: 16px;
  height: 16px;
}

@media (max-width: 1200px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 900px) {
  .sidebar {
    display: none;
  }

  .back-portfolio {
    left: 20px;
  }

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

@media (max-width: 560px) {
  .dashboard {
    padding: 16px;
  }

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