:root {
  --bg: #f6f1e7;
  --surface: #ffffff;
  --line: #ece3d2;
  --text: #4a3f2e;
  --muted: #9a8f78;
  --accent: #e07b2b;
  --accent-dark: #c26010;
  --green: #2e9e5b;
  --green-bg: #e7f6ec;
  --red: #d64a4a;
  --red-bg: #fdecec;
  --amber-bg: #fdf0dd;
  --radius: 16px;
  --shadow: 0 10px 28px rgba(138, 105, 40, 0.10);
}

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

body {
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--text);
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='6' cy='9' r='2.4' fill='%23edE3cf'/%3E%3Ccircle cx='10' cy='6' r='2.4' fill='%23edE3cf'/%3E%3Ccircle cx='14' cy='6' r='2.4' fill='%23edE3cf'/%3E%3Ccircle cx='18' cy='9' r='2.4' fill='%23edE3cf'/%3E%3Cpath d='M12 11.5c-2.8 0-5 2-5 4.2 0 1.5 1.1 2.4 2.7 2.4.9 0 1.6-.4 2.3-.4s1.4.4 2.3.4c1.6 0 2.7-.9 2.7-2.4 0-2.2-2.2-4.2-5-4.2z' fill='%23edE3cf'/%3E%3C/svg%3E");
  background-size: 110px 110px;
  min-height: 100vh;
}

.page { max-width: 1060px; margin: 0 auto; padding: 0 18px 30px; }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 18px;
  padding: 14px 6px;
  margin: 0 -18px 22px;
  padding-left: 18px; padding-right: 18px;
}

.brand { display: flex; align-items: center; gap: 10px; }

.logo {
  width: 42px; height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, #f3b163, var(--accent));
  display: grid; place-items: center;
  font-size: 21px;
  box-shadow: 0 4px 12px rgba(224, 123, 43, 0.35);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: 17px; font-weight: 900; }
.brand-text small { font-size: 11px; color: var(--muted); }

.tabs { display: flex; gap: 6px; margin-left: auto; }

.tab {
  border: none; background: transparent;
  font-family: inherit; font-size: 14px; font-weight: 800;
  color: var(--muted); padding: 9px 16px; border-radius: 999px;
  cursor: pointer; transition: background 0.15s, color 0.15s;
}
.tab:hover { background: var(--amber-bg); color: var(--text); }
.tab.active { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(224, 123, 43, 0.35); }

.owner { display: flex; align-items: center; gap: 8px; }
.owner-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff; font-weight: 900; font-size: 15px;
  display: grid; place-items: center;
}
.owner-name { font-weight: 800; font-size: 14px; white-space: nowrap; }

/* ---------- Vistas ---------- */
.view { display: none; }
.view.active { display: block; animation: in 0.2s ease; }
@keyframes in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 18px;
}
.page-head h2 { font-size: 26px; font-weight: 900; letter-spacing: -0.4px; }
.page-head p { color: var(--muted); font-weight: 600; }

/* ---------- Hero ---------- */
.hero {
  background: linear-gradient(120deg, #f3ad5c, var(--accent) 55%, var(--accent-dark));
  color: #fff; border-radius: 22px; padding: 28px 30px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px; flex-wrap: wrap;
  box-shadow: 0 14px 34px rgba(224, 123, 43, 0.35);
  margin-bottom: 20px;
}
.hero-text h2 { font-size: 26px; font-weight: 900; margin-bottom: 4px; }
.hero-text p { opacity: 0.92; font-weight: 600; }

/* ---------- Botones ---------- */
.btn {
  border: none; border-radius: 999px;
  font-family: inherit; font-size: 14px; font-weight: 800;
  padding: 11px 20px; cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(224, 123, 43, 0.35); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-white { background: #fff; color: var(--accent-dark); }
.btn-white:hover { background: #fff4e6; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-danger:hover { background: #fbd4d4; }
.btn-lg { padding: 14px 26px; font-size: 15px; }
.btn-sm { padding: 7px 13px; font-size: 12.5px; }

.icon-btn {
  border: none; background: var(--amber-bg);
  border-radius: 9px; padding: 7px 10px; cursor: pointer; font-size: 15px;
  transition: transform 0.1s, background 0.15s;
}
.icon-btn:hover { background: #fbe6c8; }
.icon-btn:active { transform: scale(0.93); }
.icon-btn.danger { background: var(--red-bg); }
.icon-btn.danger:hover { background: #fbd4d4; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 20px; }

.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow);
}
.stat-icon {
  width: 48px; height: 48px; border-radius: 14px;
  background: var(--amber-bg); display: grid; place-items: center; font-size: 22px;
  flex-shrink: 0;
}
.stat.accent { border-color: #f0c48f; }
.stat.accent .stat-icon { background: #fdebd2; }
.stat-label { display: block; font-size: 12px; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: 0.4px; }
.stat-value { font-size: 24px; font-weight: 900; letter-spacing: -0.5px; }
.stat.accent .stat-value { color: var(--accent-dark); }

/* ---------- Paneles ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); margin-bottom: 20px;
}
.panel h3 { font-size: 16px; font-weight: 900; margin-bottom: 14px; }

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.panel-head h3 { margin: 0; }
.link { border: none; background: none; color: var(--accent); font-family: inherit; font-weight: 800; font-size: 13px; cursor: pointer; }
.link:hover { color: var(--accent-dark); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 12px 10px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: #fdf8ee; }
tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
th.num { text-align: right; }

.badge { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 11.5px; font-weight: 800; }
.badge.in { background: var(--green-bg); color: var(--green); }
.badge.out { background: var(--red-bg); color: var(--red); }

.chip { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 800; background: var(--amber-bg); color: #b06a15; }
.chip.done { background: var(--green-bg); color: var(--green); }
.chip.in { background: var(--green-bg); color: var(--green); }
.chip.out { background: var(--red-bg); color: var(--red); }

.low { color: var(--red); font-weight: 800; }
.ok { color: var(--green); font-weight: 800; }

/* ---------- Listas mini ---------- */
.mini-list { display: flex; flex-direction: column; }
.mini-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 11px 4px; border-bottom: 1px dashed var(--line);
  font-size: 13.5px;
}
.mini-row:last-child { border-bottom: none; }
.mini-row b { font-size: 14px; }
.mini-row small { color: var(--muted); font-weight: 700; }

/* ---------- Barras ---------- */
.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr auto; align-items: center; gap: 12px; font-size: 13px; font-weight: 700; }
.bar-track { background: var(--amber-bg); border-radius: 999px; height: 20px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, #f3b163, var(--accent)); min-width: 2px; }
.bar-value { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Inputs / toolbar ---------- */
.input {
  font-family: inherit; font-size: 14px; font-weight: 600;
  background: #fdfaf3; border: 1.5px solid var(--line);
  border-radius: 12px; padding: 10px 14px; color: var(--text);
  outline: none; transition: border 0.15s, background 0.15s;
}
.input:focus { border-color: var(--accent); background: #fff; }
.input::placeholder { color: #b8ac92; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.search { flex: 1; min-width: 200px; }

.chips { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.chips .chip b { color: var(--text); font-size: 13.5px; }

/* ---------- Trabajos ---------- */
.works-list { display: flex; flex-direction: column; gap: 10px; }
.work-item {
  background: #fdfaf3; border: 1.5px solid var(--line); border-radius: 14px;
  padding: 14px; cursor: pointer; transition: border 0.15s, background 0.15s;
}
.work-item:hover { border-color: var(--accent); background: #fff8ec; }
.work-item.selected { border-color: var(--accent); background: var(--amber-bg); }
.work-item-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.work-item-name { font-weight: 900; font-size: 14.5px; }
.work-item-meta { font-size: 12.5px; color: var(--muted); font-weight: 700; display: flex; gap: 12px; flex-wrap: wrap; }

.work-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.detail-info { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.detail-info div { background: #fdfaf3; border-radius: 12px; padding: 10px 14px; }
.detail-info label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; font-weight: 800; letter-spacing: 0.4px; margin-bottom: 2px; }
.detail-info span { font-size: 14px; font-weight: 800; }

/* ---------- Modal ---------- */
.modal-bg {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(90, 70, 30, 0.4); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal-bg[hidden] { display: none; }
.modal {
  background: #fff; border-radius: 20px; padding: 26px;
  width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 24px 60px rgba(90, 60, 20, 0.3);
}
.modal h3 { font-size: 20px; font-weight: 900; margin-bottom: 18px; }

.form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 800; color: var(--muted); }
.form label span { color: var(--text); }
.form-error { color: var(--red); font-size: 13px; font-weight: 700; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 22px; right: 22px; z-index: 200;
  background: #4a3f2e; color: #fff; border-radius: 14px;
  padding: 14px 20px; font-size: 14px; font-weight: 800;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  opacity: 0; transform: translateY(14px); pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--red); }

/* ---------- Footer ---------- */
.footer { text-align: center; color: var(--muted); font-size: 13px; font-weight: 700; padding: 10px 0; }
.footer b { color: var(--accent-dark); }

/* ---------- Varios ---------- */
.empty { color: var(--muted); text-align: center; padding: 22px 8px; font-weight: 700; font-size: 13.5px; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 10px; }
  .tabs { order: 3; margin-left: 0; width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .tab { padding: 8px 14px; font-size: 13px; white-space: nowrap; }
  .owner-name { display: none; }
  .form-row { grid-template-columns: 1fr; }
  .hero { padding: 22px; }
  .hero-text h2 { font-size: 22px; }
  .bar-row { grid-template-columns: 110px 1fr auto; }
}