/* Variables y base */
:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --border: #30363d;
  --radius: 8px;
  --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}

.header nav {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.header nav a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
}

.header nav a:hover {
  color: var(--text);
  background: var(--surface2);
}

/* Dropdown */
.dropdown {
  position: relative;
  display: flex;
  align-items: center;
}

.dropbtn {
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  text-decoration: none;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: var(--surface);
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  top: 100%;
  left: 0;
  margin-top: 0.25rem;
}

.dropdown-content a {
  color: var(--text-muted) !important;
  padding: 12px 16px !important;
  text-decoration: none;
  display: block;
  border-radius: 0 !important;
}

.dropdown-content a:hover {
  background-color: var(--surface2) !important;
  color: var(--text) !important;
}

.dropdown:hover .dropdown-content {
  display: block;
}

.dropdown:hover .dropbtn {
  color: var(--text);
  background: var(--surface2);
}

/* Main */
.main {
  flex: 1;
  padding: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* Hero / Home */
.hero {
  text-align: center;
  padding: 2rem 0;
}

.hero h1 {
  font-size: 1.75rem;
  margin-bottom: 0.5rem;
}

.hero p {
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  text-align: left;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-decoration: none;
  color: inherit;
  transition: border-color .2s, transform .15s;
}

.card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.card-icon {
  font-size: 2rem;
  display: block;
  margin-bottom: 0.5rem;
}

.card h2 {
  font-size: 1.1rem;
  margin: 0 0 0.5rem;
}

.card p {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0;
}

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.page-header .subtitle {
  width: 100%;
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
  font-family: inherit;
}

.btn:hover {
  background: var(--surface);
  border-color: var(--text-muted);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, .15);
}

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

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.table th,
.table td {
  padding: 0.6rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table th {
  background: var(--surface2);
  font-weight: 600;
}

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

.table tbody tr:hover {
  background: rgba(255, 255, 255, .03);
}

.table .empty {
  color: var(--text-muted);
  text-align: center;
  padding: 1.5rem;
}

.table .empty a {
  color: var(--accent);
}

.table .text-right {
  text-align: right;
}

.table .actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.table .actions form.inline {
  display: inline;
}

/* Forms */
.form {
  max-width: 600px;
}

.form label {
  display: block;
  margin-bottom: 1rem;
}

.form label span {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.form input,
.form select,
.form textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

.form input:focus,
.form select:focus,
.form textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1.5rem;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.form-actions {
  margin-top: 1.5rem;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.form-inline {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.form-inline label {
  flex: 1;
  min-width: 120px;
}

.section {
  margin: 1.5rem 0;
}

.section h2 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
}

.row-head {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.row-head label {
  margin-bottom: 0;
}

.row-head label.inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.row-head label.inline span {
  margin-bottom: 0;
  margin-right: 0.25rem;
}

/* Cotización detalle */
.cotizacion-detail {
  max-width: 700px;
}

.cotizacion-detail p {
  margin: 0.5rem 0;
}

/* Dimensionador */
.dimensionador-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .dimensionador-layout {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.panel h2 {
  font-size: 1.1rem;
  margin: 0 0 1rem;
}

.hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0.5rem 0 1rem;
}

.preview-plancha {
  width: 100%;
  max-width: 400px;
  min-height: 150px;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 4px;
  position: relative;
  margin: 0 auto 1rem;
  overflow-y: auto;
  max-height: 400px;
}

.preview-plancha .plancha-wrap {
  background: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
  border-radius: 4px;
}

.preview-plancha .pieza-preview {
  position: absolute;
  border: 1px solid rgba(59, 130, 246, 0.8);
  background: rgba(59, 130, 246, 0.2);
  border-radius: 2px;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #93c5fd;
  overflow: hidden;
}

.resumen {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.print-area {
  padding: 1rem;
}

.error-msg {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
  padding: 0.75rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

/* Footer */
.footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* Login page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f1419 0%, #1a2332 50%, #0f1419 100%);
}

.login-container {
  width: 100%;
  max-width: 400px;
  padding: 1.5rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  text-align: center;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.login-logo {
  font-size: 3.5rem;
  display: block;
  margin-bottom: 0.5rem;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-8px);
  }
}

.login-title {
  font-size: 1.5rem;
  margin: 0 0 0.25rem;
  font-weight: 700;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0 0 1.5rem;
}

.login-form label {
  display: block;
  text-align: left;
  margin-bottom: 1rem;
}

.login-form label span {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.login-form input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s;
}

.login-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.login-btn {
  width: 100%;
  padding: 0.65rem 1rem;
  font-size: 1rem;
  margin-top: 0.5rem;
  font-weight: 600;
  transition: background 0.2s, transform 0.1s;
}

.login-btn:active {
  transform: scale(0.98);
}

.login-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 1.5rem;
}

/* User info in header */
.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.user-name {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.btn-logout {
  color: var(--text-muted);
  border-color: var(--border);
  font-size: 0.8rem;
  transition: color 0.2s, border-color 0.2s;
}

.btn-logout:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(239, 68, 68, .1);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-active {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.badge-inactive {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

/* Checkbox styling */
.checkbox-label span:first-child {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.checkbox-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.checkbox-wrap input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* ========================================= */
/* MOBILE RESPONSIVENESS (Max 768px)         */
/* ========================================= */
@media (max-width: 768px) {

  /* 1. Generales y espaciados */
  .main {
    padding: 1rem;
  }

  /* 2. Header & Navegación */
  .header {
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1rem;
    gap: 1.2rem;
  }

  .header nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    width: 100%;
    justify-content: flex-start;
    padding-bottom: 0.5rem;
    /* Space for scrollbar */
    -webkit-overflow-scrolling: touch;
    border-bottom: 1px solid var(--border);
  }

  .header nav a {
    white-space: nowrap;
    font-size: 0.95rem;
  }

  .user-info {
    width: 100%;
    justify-content: center;
  }

  /* 3. Formularios (Grillas a 1 columna) */
  .form-grid {
    grid-template-columns: 1fr;
    gap: 0 1rem;
  }

  .form-inline {
    flex-direction: column;
    gap: 1rem;
  }

  .form-inline label {
    width: 100%;
  }

  /* 4. Tablas (Scroll interno y evitar colapso) */
  .table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
  }

  .table {
    border: none;
    /* Let the wrapper handle the border */
    min-width: 600px;
    /* Force minimum width to trigger scroll on small screens */
  }

  .table th,
  .table td {
    white-space: nowrap;
    padding: 0.75rem;
  }

  .table .actions {
    flex-wrap: nowrap;
  }

  /* 5. Dimensionador / Inputs apilados */
  .row-head {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  .row-head label {
    width: 100%;
  }

  .row-head .btn {
    width: 100%;
    margin-top: 0.5rem;
  }

  /* Botones 100% en acciones generales */
  .form-actions {
    flex-direction: column;
  }

  .form-actions .btn {
    width: 100%;
    text-align: center;
  }

  /* Page header */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  /* Responsive Modals */
  #customConfirmModal>div {
    width: 90% !important;
    padding: 20px !important;
  }

  #customConfirmModal .btn {
    width: 100%;
  }

  #customConfirmModal div[style*="display:flex"] {
    flex-direction: column;
  }
}

/* Print */
@media print {

  .header,
  .footer,
  .no-print,
  .btn,
  .form-actions,
  .page-header .btn {
    display: none !important;
  }

  .main {
    padding: 0;
    max-width: none;
  }

  body {
    background: #fff;
    color: #000;
  }

  .print-page .print-content {
    max-width: 100%;
  }

  .table {
    border: 1px solid #333;
  }

  .table th,
  .table td {
    border-color: #ccc;
  }
}