/* ============================
   Inventario Siigo - Premium Dashboard
   ============================ */

:root {
  /* Typography */
  --font-heading: 'Outfit', system-ui, -apple-system, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;

  /* Colors */
  --primary: #6366f1;
  /* Indigo 500 */
  --primary-hover: #4f46e5;
  /* Indigo 600 */
  --primary-light: #e0e7ff;
  /* Indigo 100 */
  --secondary: #ec4899;
  /* Pink 500 */

  --bg-body: #f1f5f9;
  /* Slate 100 */
  --bg-surface: #ffffff;
  --bg-sidebar: #0f172a;
  /* Slate 900 */

  --text-main: #1e293b;
  /* Slate 800 */
  --text-muted: #64748b;
  /* Slate 500 */
  --text-light: #94a3b8;
  /* Slate 400 */
  --text-on-dark: #f8fafc;

  --border: #e2e8f0;
  /* Slate 200 */

  --success: #10b981;
  /* Emerald 500 */
  --success-bg: #d1fae5;
  --warning: #f59e0b;
  /* Amber 500 */
  --warning-bg: #fef3c7;
  --danger: #ef4444;
  /* Red 500 */
  --danger-bg: #fee2e2;

  /* Spacing & Layout */
  --sidebar-width: 260px;
  --header-height: 64px;

  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

/* Reset & Base */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-body);
  color: var(--text-main);
  margin: 0;
  height: 100vh;
  overflow: hidden;
  /* App layout handles scroll */
}

/* Layout Grid */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--bg-sidebar);
  color: var(--text-on-dark);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  transition: transform 0.3s ease;
  z-index: 50;
}

.sidebar-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.25rem;
  color: white;
}

.logo-icon {
  font-size: 1.5rem;
}

.sidebar-nav {
  flex: 1;
  padding: 1.5rem 1rem;
  overflow-y: auto;
}

.sidebar-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  color: var(--text-light);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: white;
}

.nav-link.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.nav-link i {
  font-size: 1.25rem;
}

.nav-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 1rem 0;
}

.nav-link.danger:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
}

.avatar {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
}

.details {
  display: flex;
  flex-direction: column;
}

.details .name {
  font-size: 0.9rem;
  font-weight: 600;
  color: white;
}

.details .role {
  font-size: 0.75rem;
  color: var(--text-light);
}

/* Main Content Area */
.main-content {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-body);
}

/* Topbar */
.topbar {
  height: var(--header-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  z-index: 40;
}

.toggle-sidebar {
  display: none;
  /* Mobile only */
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.crumb-current {
  font-weight: 600;
  color: var(--text-main);
}

.topbar-actions {
  display: flex;
  gap: 1rem;
}

.action-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  position: relative;
  padding: 0.5rem;
  border-radius: 50%;
  transition: background 0.2s;
}

.action-btn:hover {
  background: var(--bg-body);
  color: var(--text-main);
}

.badge-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  background: var(--danger);
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
}

/* Content Wrapper */
.content-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
}

/* Cards & Components */
.card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
}

.card h2 {
  font-size: 1.25rem;
  margin-bottom: 1.25rem;
  color: var(--text-main);
}

/* Search Section */
.search-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

#quick-search {
  flex: 1;
  padding: 0.875rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  transition: all 0.2s;
}

#quick-search:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

input.cfg-input:focus {
  background: white;
  box-shadow: 0 0 0 1px var(--primary);
  border-radius: 2px;
}

/* Hide spin buttons */
input.cfg-input::-webkit-outer-spin-button,
input.cfg-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input.cfg-input[type=number] {
  -moz-appearance: textfield;
}

#clear-search {
  padding: 0.875rem 1.5rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

#clear-search:hover {
  background: var(--bg-body);
  color: var(--text-main);
  border-color: var(--text-light);
}

/* Tables */
.table-responsive {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead th {
  text-align: left;
  padding: 1rem;
  background: var(--bg-body);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-main);
}

tbody tr:hover td {
  background: var(--bg-body);
}

/* Utilities */
.text-right {
  text-align: right;
}

/* Status Chips */
.days-left {
  display: inline-flex;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

tr.under-min .days-left {
  background: var(--danger-bg);
  color: var(--danger);
}

tr:not(.under-min) .days-left {
  background: var(--success-bg);
  color: var(--success);
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .toggle-sidebar {
    display: block;
  }

  .topbar {
    padding: 0 1rem;
  }

  .content-wrapper {
    padding: 1rem;
  }

  /* Mobile Table to Compact List Transformation */

  /* Hide table headers */
  thead {
    display: none;
  }

  /* Compact Item Container */
  tr {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    grid-template-areas:
      "qty name days"
      "code inputs inputs";
    gap: 0.5rem 0.75rem;
    padding: 0.75rem 0.5rem;
    margin-bottom: 0;
    background: white;
    border-bottom: 1px solid var(--border);
    align-items: center;
  }

  tr:last-child {
    border-bottom: none;
  }

  /* Group Headers */
  tr.group-row {
    display: block;
    background: var(--bg-body);
    border-bottom: 1px solid var(--border);
    margin: 0;
    padding: 0.5rem 0.75rem;
    position: sticky;
    top: 0;
    z-index: 5;
  }

  tr.group-row td {
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0;
    border: none;
    display: block;
  }

  /* Cell Resets */
  td {
    padding: 0 !important;
    border: none !important;
    text-align: left !important;
    display: block;
  }

  td::before {
    content: none !important;
  }

  /* Hide Redundant Columns */
  td[data-label="Grupo"] {
    display: none;
  }

  /* --- Grid Areas & Styling --- */

  /* Quantity: Big & Bold */
  td[data-label="Cantidad"] {
    grid-area: qty;
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--primary);
    min-width: 3ch;
    text-align: right !important;
  }

  /* Name: Main Text */
  td[data-label="Nombre"] {
    grid-area: name;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Days: Badge */
  td[data-label="Días restantes"] {
    grid-area: days;
    justify-self: end;
  }

  td[data-label="Días restantes"] .days-left {
    font-size: 0.75rem;
    padding: 0.1rem 0.5rem;
    height: auto;
  }

  /* Code: Subtle */
  td[data-label="Código"] {
    grid-area: code;
    font-family: 'Menlo', monospace;
    font-size: 0.75rem;
    color: var(--text-light);
  }

  /* Inputs Row */
  td[data-label="Mínimo"],
  td[data-label="Pack"],
  td[data-label="Consumo/día"] {
    grid-area: inputs;
    display: none;
    /* Hide inputs on mobile by default to save space, or adjust as needed */
  }

  /* Adjust Fichas Grid for mobile */
  .fichas-grid {
    grid-template-columns: 1fr;
  }
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card,
.fichas-cell {
  animation: fadeIn 0.4s ease-out forwards;
}