:root {
  --bg: #EDECE6;
  --surface: #FFFFFF;
  --ink: #1A1D1B;
  --ink-soft: #5C6259;
  --border: #D9D7CD;
  --accent: #2F5233;       /* crate green - brand/action */
  --accent-soft: #E4EAE1;
  --amber: #B9812C;        /* pendiente / averia */
  --amber-soft: #F5EBD8;
  --success: #3B7A52;
  --success-soft: #E3EFE6;
  --danger: #A2402E;
  --danger-soft: #F5E4E0;
  --radius: 3px;
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.mono { font-family: 'IBM Plex Mono', monospace; }
.hidden { display: none !important; }

/* ---------- Login ---------- */
.view-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 36px 32px;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.brand-mark {
  width: 36px; height: 36px;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 500;
  font-size: 13px;
  flex-shrink: 0;
}
.brand-name { font-weight: 600; font-size: 15px; line-height: 1.3; }
.brand-name.small { font-size: 13px; }
.brand-sub { font-size: 12px; color: var(--ink-soft); }

#login-form { display: flex; flex-direction: column; gap: 16px; }
label { font-size: 13px; color: var(--ink-soft); display: flex; flex-direction: column; gap: 6px; }
.hint { font-size: 11px; font-weight: 400; }
input[type="text"], input[type="password"], input[type="number"], textarea, select {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}
button { font-family: inherit; cursor: pointer; }
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
}
.btn-primary:hover { background: #264429; }
.link-btn {
  background: none; border: none; color: var(--accent);
  font-size: 13px; padding: 0; text-decoration: underline;
}
.error-msg { color: var(--danger); font-size: 13px; min-height: 16px; }

/* ---------- App shell ---------- */
.view-app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  flex-shrink: 0;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; padding: 0 4px; }
#nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  padding: 9px 10px;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
  border-left: 2px solid transparent;
}
.nav-item:hover { background: var(--accent-soft); color: var(--ink); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); border-left-color: var(--accent); font-weight: 500; }
.sidebar-user { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 14px; }
.user-name { font-size: 13px; font-weight: 500; }
.user-role { font-size: 11px; color: var(--ink-soft); text-transform: capitalize; margin-bottom: 8px; }

.main { flex: 1; padding: 28px 36px; max-width: 1200px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.topbar h1 { font-size: 20px; font-weight: 600; margin: 0; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); }
th, td { text-align: left; padding: 10px 12px; font-size: 13.5px; border-bottom: 1px solid var(--border); }
th { color: var(--ink-soft); font-weight: 500; font-size: 12px; text-transform: none; background: #FAFAF7; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--accent-soft); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
}
.badge-pendiente { background: var(--amber-soft); color: var(--amber); }
.badge-aceptado { background: var(--success-soft); color: var(--success); }
.badge-rechazado { background: var(--danger-soft); color: var(--danger); }
.badge-averia { background: var(--danger-soft); color: var(--danger); }
.badge-muestra { background: var(--accent-soft); color: var(--accent); }
.badge-otro { background: #EEE; color: var(--ink-soft); }

.filters { display: flex; gap: 10px; margin-bottom: 14px; }
.filters select { padding: 7px 8px; font-size: 13px; }

/* ---------- Cards / stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); padding: 16px; }
.stat-card .num { font-family: 'IBM Plex Mono', monospace; font-size: 26px; font-weight: 500; }
.stat-card .label { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
.chart-wrap { background: var(--surface); border: 1px solid var(--border); padding: 20px; margin-bottom: 20px; }
.chart-wrap h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(26,29,27,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--surface); width: 420px; max-height: 88vh; overflow-y: auto;
  border: 1px solid var(--border);
}
.modal-wide { width: 560px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 16px; margin: 0; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--ink-soft); }
#mov-form, #user-form { display: flex; flex-direction: column; gap: 14px; padding: 20px; }

.items-block { border: 1px solid var(--border); padding: 10px; }
.items-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-soft); margin-bottom: 8px; }
.item-row { display: grid; grid-template-columns: 80px 1fr 70px 24px; gap: 6px; margin-bottom: 6px; }
.item-row input { padding: 6px 8px; font-size: 13px; }
.item-remove { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 15px; }

.item-row-search { grid-template-columns: 1fr 70px 24px; }
.item-search-wrap { position: relative; }
.item-search-wrap > input[type="text"] { width: 100%; }
.item-search-results {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 10;
  background: var(--surface); border: 1px solid var(--border); border-top: none;
  max-height: 220px; overflow-y: auto;
}
.search-item { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--border); }
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--accent-soft); }
.search-item-name { display: block; font-size: 13px; }
.search-item-meta { display: block; font-size: 11px; color: var(--ink-soft); font-family: 'IBM Plex Mono', monospace; }
.search-empty { padding: 8px 10px; font-size: 12px; color: var(--ink-soft); font-style: italic; }

.checkbox-label { flex-direction: row; align-items: center; gap: 8px; }
.checkbox-label input { width: auto; }

.action-btns { display: flex; gap: 8px; margin-top: 16px; }
.btn-small { padding: 6px 12px; font-size: 12.5px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.btn-small.accept { border-color: var(--success); color: var(--success); }
.btn-small.decline { border-color: var(--danger); color: var(--danger); }
.btn-small:hover { background: #FAFAF7; }

.detail-photos { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.detail-photos img { width: 90px; height: 90px; object-fit: cover; border: 1px solid var(--border); }

.empty-state { padding: 40px 20px; text-align: center; color: var(--ink-soft); font-size: 13.5px; }

@media (max-width: 720px) {
  .view-app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 12px 16px; }
  #nav { flex-direction: row; overflow-x: auto; }
  .sidebar-user { display: none; }
  .main { padding: 18px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
