:root {
  --bg: #f4f6f5;
  --surface: #fff;
  --soft: #eef3f1;
  --line: #d9e1e3;
  --ink: #253036;
  --muted: #66747b;
  --teal: #147d7f;
  --teal-dark: #0b5e63;
  --teal-soft: #d9eeee;
  --coral: #cb5548;
  --coral-soft: #fde8e4;
  --green: #35845c;
  --green-soft: #dff0e7;
  --amber: #b7791f;
  --amber-soft: #fff2d8;
  --shadow: 0 18px 50px rgba(37, 48, 54, 0.12);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button, input, select, textarea { max-width: 100%; font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.28rem; }
h2 { font-size: 1.18rem; line-height: 1.25; }
h3 { font-size: 1rem; }
p { color: var(--muted); line-height: 1.45; }

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

input, select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(20, 125, 127, 0.14);
}

.primary, .secondary, .ghost, .danger, .summary-button {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 900;
}

.primary { background: var(--teal); color: #fff; }
.secondary { background: var(--teal-soft); color: var(--teal-dark); }
.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.danger { background: var(--coral-soft); border-color: var(--coral-soft); color: var(--coral); }
.danger:disabled { opacity: 0.45; cursor: not-allowed; }
.summary-button { background: var(--ink); color: #fff; }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(460px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand, .topbar, .section-title, .project-head, .dialog-head, menu {
  display: flex;
  align-items: center;
}

.brand { gap: 12px; min-width: 0; }
.brand-mark {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-weight: 950;
}
.brand p { margin-top: 2px; font-size: 0.86rem; }

.demo-users {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.demo-users button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  font-size: 0.78rem;
  font-weight: 850;
}
.error { min-height: 20px; color: var(--coral); font-weight: 850; }

.app { min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.user-pill {
  display: grid;
  align-content: center;
  min-height: 42px;
  max-width: 260px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}
.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}
.user-pill strong, .user-pill span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-pill strong { font-size: 0.84rem; }
.user-pill span { color: var(--muted); font-size: 0.74rem; font-weight: 850; }

.app-tabs {
  position: sticky;
  top: 75px;
  z-index: 9;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 246, 245, 0.96);
  backdrop-filter: blur(14px);
}
.app-tabs button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-weight: 900;
}
.app-tabs button.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.view { display: none; }
.view.active { display: grid; gap: 14px; }

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.summary-card {
  min-height: 86px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.summary-card strong {
  display: block;
  color: var(--teal-dark);
  font-size: 1.3rem;
}
.summary-card span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 850;
}
.summary-dialog { width: min(520px, calc(100vw - 24px)); }
.summary-content { padding: 18px; }
.summary-dialog .summary {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 14px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.project-list {
  display: grid;
  gap: 10px;
}

.project-card {
  width: 100%;
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--teal);
  border-radius: 8px;
  background: var(--surface);
  text-align: left;
}
.project-card.active { box-shadow: 0 0 0 3px rgba(20, 125, 127, 0.12); }
.project-card-top, .project-card-bottom {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}
.project-card h3 { overflow-wrap: anywhere; }
.project-card p { font-size: 0.88rem; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-size: 0.72rem;
  font-weight: 900;
  white-space: nowrap;
}
.Alta { color: var(--coral); background: var(--coral-soft); }
.Pendiente-aprobacion, .Pendiente { color: var(--amber); background: var(--amber-soft); }
.Aprobado, .Cerrado { color: var(--green); background: var(--green-soft); }

.empty-state, .project-detail, .admin-panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.empty-state { text-align: center; }

.project-detail {
  display: grid;
  gap: 14px;
}
.project-head {
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.project-head h2 { margin-top: 2px; font-size: 1.45rem; }
.reference {
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 950;
}
.status-field { min-width: 220px; }

.info-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.info-grid div {
  padding: 12px;
  border-right: 1px solid var(--line);
  background: #fbfcfc;
}
.info-grid div:last-child { border-right: 0; }
.info-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}
.info-grid strong {
  display: block;
  margin-top: 5px;
  overflow-wrap: anywhere;
}

.section-block {
  display: grid;
  gap: 10px;
}
.section-title {
  justify-content: space-between;
  gap: 12px;
}
.section-title span {
  min-width: 30px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  text-align: center;
  font-size: 0.78rem;
  font-weight: 900;
}

.notes, .quotes, .users-list {
  display: grid;
  gap: 10px;
}
.note, .quote-item, .user-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.note-meta, .quote-row, .user-card {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}
.note-meta {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
}
.note p {
  margin-top: 6px;
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.note-form, .quote-form, .user-form {
  display: grid;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.quote-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.quote-actions button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-weight: 850;
}
.user-card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}
.user-card .danger { min-height: 34px; padding: 0 10px; }

.admin-panel {
  display: grid;
  gap: 14px;
}
.user-form {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: end;
}

dialog {
  width: min(760px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(37, 48, 54, 0.35); }
dialog form { padding: 18px; }
.dialog-head {
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.dialog-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}
menu {
  justify-content: flex-end;
  gap: 8px;
  margin: 16px 0 0;
  padding: 14px 0 0;
  border-top: 1px solid var(--line);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(380px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(16px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

.empty-list {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 860px) {
  body { background: #fff; }
  .login { padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom)); }
  .login-card { padding: 18px; box-shadow: none; }
  .demo-users { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .topbar {
    padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  }
  .brand-mark { width: 38px; height: 38px; font-size: 0.86rem; }
  .brand h1 { font-size: 1.08rem; }
  .brand p { display: none; }
  .user-pill { max-width: 150px; min-height: 38px; }
  .summary-button { min-height: 38px; padding: 0 10px; font-size: 0.84rem; }

  .app-tabs {
    top: 59px;
    display: flex;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    gap: 6px;
    padding: 8px 10px;
  }
  .app-tabs button {
    flex: 1 0 92px;
    min-height: 38px;
    font-size: 0.84rem;
  }

  .main {
    padding: 10px 10px max(18px, env(safe-area-inset-bottom));
  }
  .view.active { gap: 10px; }

  .summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .summary-card {
    min-height: 70px;
    padding: 10px;
  }
  .summary-card strong { font-size: 1.08rem; }
  .summary-card span { font-size: 0.72rem; }
  .summary-content { padding: 14px; }

  .toolbar {
    grid-template-columns: 1fr;
    padding: 12px;
  }
  .toolbar button { width: 100%; }

  .project-card {
    padding: 12px;
  }
  .project-card-top, .project-card-bottom, .project-head, .note-meta, .quote-row, .user-card {
    display: grid;
    grid-template-columns: 1fr;
  }
  .project-head { padding-bottom: 12px; }
  .project-head h2 { font-size: 1.28rem; }
  .status-field { min-width: 0; }

  .empty-state, .project-detail, .admin-panel { padding: 12px; }
  .info-grid { grid-template-columns: 1fr; }
  .info-grid div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .info-grid div:last-child { border-bottom: 0; }

  .form-row, .quote-actions, .dialog-grid, .user-form {
    grid-template-columns: 1fr;
  }
  .user-card-actions {
    justify-content: flex-start;
  }
  .note-form .primary, .quote-form .secondary, .user-form .primary {
    width: 100%;
  }

  dialog {
    width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
    overflow: auto;
  }
  dialog form { padding: 14px; }
  .dialog-head, menu {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
  }
  menu button { width: 100%; }

  .toast {
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    max-width: none;
  }
}

@media (max-width: 390px) {
  .summary { grid-template-columns: 1fr; }
  .user-pill { display: none; }
  .summary-dialog .summary { grid-template-columns: 1fr; }
}
