@import url('https://fonts.googleapis.com/css2?family=Fira+Sans:wght@300;400;500;600;700&display=swap');

:root {
  /* Paleta corporativa */
  --chatello-charcoal:    #121619;
  --chatello-gray:        #2A2C2D;
  --chatello-beige:       #DBD2CB;
  --chatello-beige-light: #ECE6E0;
  --chatello-beige-soft:  #F5F1ED;
  --chatello-white:       #FFFFFF;

  /* Tokens semánticos */
  --bg:            #F5F1ED;
  --surface:       #FFFFFF;
  --surface-2:     #FAF7F4;
  --border:        #E2DAD2;
  --border-strong: #C9BFB5;
  --text:          #121619;
  --text-2:        #4A4D50;
  --muted:         #7A7670;

  --ok:      #3E7B4F; --ok-bg:      #E1EFE4;
  --warn:    #B4781B; --warn-bg:    #FBEFD8;
  --danger:  #A62A1F; --danger-bg:  #F8E1DD;
  --info:    #4A4D50; --info-bg:    #ECE6E0;

  --shadow-sm: 0 1px 2px rgba(18, 22, 25, 0.05);
  --shadow:    0 4px 12px rgba(18, 22, 25, 0.08);
  --shadow-lg: 0 12px 32px rgba(18, 22, 25, 0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #17191B;
    --surface:       #1F2224;
    --surface-2:     #24272A;
    --border:        #34383B;
    --border-strong: #464B4F;
    --text:          #EDE8E3;
    --text-2:        #C7C1BA;
    --muted:         #938E88;

    --ok-bg:     #1D3324;
    --warn-bg:   #3A2C10;
    --danger-bg: #3A1815;
    --info-bg:   #2A2D30;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Fira Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}

h1, h2, h3, h4 { margin: 0 0 8px; color: var(--text); }
h2 { font-size: 20px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
h4 { font-size: 13px; font-weight: 600; }
p { margin: 0 0 8px; }

/* --- Layout sidebar + main --- */

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

.sidebar {
  width: 240px;
  background: var(--chatello-charcoal);
  color: var(--chatello-beige);
  padding: 28px 20px 24px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar .brand { margin-bottom: 32px; }
.sidebar .brand h1 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin: 4px 0 4px;
  color: var(--chatello-beige);
}
.sidebar .brand .subtitle {
  font-size: 11px;
  color: rgba(219, 210, 203, 0.55);
}

.sidebar nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  padding: 11px 14px;
  border-radius: 6px;
  color: rgba(219, 210, 203, 0.78);
  font-weight: 500;
  text-decoration: none;
}
.sidebar nav a:hover { background: rgba(219, 210, 203, 0.08); color: var(--chatello-beige); }
.sidebar nav a.active {
  background: var(--chatello-beige);
  color: var(--chatello-charcoal);
  font-weight: 600;
}

.sidebar .user {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid rgba(219, 210, 203, 0.12);
  font-size: 12px;
}
.sidebar .user strong { display: block; }
.sidebar .user span { color: rgba(219, 210, 203, 0.55); }
.sidebar button {
  margin-top: 14px;
  padding: 9px 12px;
  background: transparent;
  border: 1px solid rgba(219, 210, 203, 0.3);
  color: var(--chatello-beige);
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12.5px;
}
.sidebar button:hover { background: rgba(219, 210, 203, 0.1); }

.main {
  flex: 1;
  padding: 36px 40px;
  max-width: 1440px;
  min-width: 0;
}

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-header .count { font-size: 12px; color: var(--muted); }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 14px 18px; }
  .sidebar .brand { margin: 0; }
  .sidebar nav { flex-direction: row; margin-left: auto; }
  .sidebar .user, .sidebar button { display: none; }
  .main { padding: 24px 20px; }
}

/* --- Vista de dos columnas (lista + detalle) --- */

.editor-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 1100px) {
  .editor-grid { grid-template-columns: 1fr; }
}

/* --- Cards --- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 20px;
}

.card-header {
  padding: 16px 20px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.card-header h3 { font-size: 15px; font-weight: 600; color: var(--text); margin: 0; }

.card-body { padding: 20px; }

/* --- Tablas --- */

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--muted);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:hover { background: var(--chatello-beige-soft); }
@media (prefers-color-scheme: dark) { tbody tr:hover { background: var(--surface-2); } }

td.num, th.right { text-align: right; font-variant-numeric: tabular-nums; }

table .empty { text-align: center; padding: 40px 20px; color: var(--muted); }

tr.fila-articulo { cursor: pointer; }
tr.fila-articulo.selected { background: var(--chatello-beige-light); }
@media (prefers-color-scheme: dark) { tr.fila-articulo.selected { background: var(--surface-2); } }

tr.linea-faltante td { background: var(--danger-bg); }
tr.linea-unidad-difiere td { background: var(--warn-bg); }

/* --- Badges --- */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.badge-ok        { background: var(--ok-bg);     color: var(--ok); }
.badge-alta      { background: var(--danger-bg); color: var(--danger); }
.badge-media     { background: var(--warn-bg);   color: var(--warn); }
.badge-baja      { background: var(--info-bg);   color: var(--info); }
.badge-pendiente { background: var(--warn-bg);   color: var(--warn); }

/* --- Botones --- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--chatello-charcoal); color: var(--chatello-beige); border-color: var(--chatello-charcoal); }
.btn-primary:hover { background: #000; }

.btn-success { background: var(--ok); color: white; border-color: var(--ok); }
.btn-success:hover { background: #2f5f3c; }

.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #8a1f17; }

.btn-sm { padding: 5px 11px; font-size: 12px; }

/* --- Forms --- */

label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="search"],
input[type="number"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 13.5px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--chatello-charcoal);
  box-shadow: 0 0 0 3px rgba(18, 22, 25, 0.08);
}
input[readonly] { background: var(--surface-2); color: var(--text-2); cursor: not-allowed; }

.campo { margin-bottom: 14px; }
.fila-campos { display: flex; gap: 12px; }
.fila-campos > .campo { flex: 1; min-width: 0; }

.filters {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filters input, .filters select { width: auto; min-width: 140px; }
.filters input[type="search"] { flex: 1; min-width: 180px; }

/* --- Avisos --- */

.aviso {
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 12.5px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.aviso-info    { background: var(--info-bg);   color: var(--text-2); border-color: var(--border); }
.aviso-ambar   { background: var(--warn-bg);   color: var(--warn); }
.aviso-rojo    { background: var(--danger-bg); color: var(--danger); }
.aviso-pendiente {
  background: var(--warn-bg);
  color: var(--warn);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 12.5px;
}

/* --- Nombre derivado --- */

.nombre-preview {
  font-size: 19px;
  font-weight: 600;
  color: var(--text);
  padding: 10px 0 4px;
}
.nombre-preview .vacio { color: var(--muted); font-weight: 400; font-style: italic; }

/* --- Modales --- */

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(18, 22, 25, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--surface);
  border-radius: 10px;
  padding: 26px;
  max-width: 480px;
  width: calc(100% - 40px);
  box-shadow: var(--shadow-lg);
}
.modal h3 { font-size: 17px; font-weight: 600; margin: 0 0 14px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.modal ul.similares { margin: 10px 0; padding-left: 20px; }
.modal ul.similares li { margin-bottom: 4px; }

/* --- Login --- */

body.login-body {
  background: var(--chatello-charcoal);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--surface);
  padding: 48px 44px 40px;
  border-radius: 10px;
  width: 380px;
  max-width: 100%;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-card .brand h1 {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--text);
  text-transform: none;
  letter-spacing: normal;
}
.login-card .sub { font-size: 13px; color: var(--muted); margin-bottom: 28px; }
.login-card form { text-align: left; }
.login-card .btn { width: 100%; margin-top: 8px; padding: 12px; font-size: 14px; justify-content: center; }
.login-card .error { margin-top: 12px; color: var(--danger); font-size: 12px; text-align: center; min-height: 16px; }

/* --- Utilidades --- */

.muted { color: var(--muted); }
.pre-crudo {
  white-space: pre-wrap;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  max-height: 220px;
  overflow: auto;
}
.chip {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  margin: 2px 4px 2px 0;
}
.vacio-estado {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
